import { assert, assertEquals } from "../testing/asserts.ts";import { readableStreamFromIterable } from "./readable_stream_from_iterable.ts";
const N = 100;
export function init(): Uint8Array { const testBytes = new Uint8Array(N); for (let i = 0; i < N; i++) { testBytes[i] = "a".charCodeAt(0) + (i % 26); } return testBytes;}
export async function testTransformStream<T, U>( transform: TransformStream<T, U>, inputs: Iterable<T> | AsyncIterable<T>, outputs: Iterable<U> | AsyncIterable<U>,) { const reader = readableStreamFromIterable(inputs) .pipeThrough(transform) .getReader(); for await (const output of outputs) { const { value, done } = await reader.read(); assertEquals(value, output); assertEquals(done, false); } const f = await reader.read(); assert(f.done, `stream not done, value was: ${f.value}`);}