2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2022-11-29 13:55:38 +00:00
|
|
|
|
2024-04-29 02:57:30 +00:00
|
|
|
import { assert, assertEquals } from "@std/assert";
|
2023-03-29 22:21:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Verify that a transform stream produces the expected output data
|
|
|
|
* @param transform The transform stream to test
|
|
|
|
* @param inputs Source input data
|
|
|
|
* @param outputs Expected output data
|
|
|
|
*/
|
|
|
|
export async function testTransformStream<T, U>(
|
|
|
|
transform: TransformStream<T, U>,
|
|
|
|
inputs: Iterable<T> | AsyncIterable<T>,
|
|
|
|
outputs: Iterable<U> | AsyncIterable<U>,
|
|
|
|
) {
|
2023-07-17 06:08:20 +00:00
|
|
|
const reader = ReadableStream.from(inputs)
|
2023-03-29 22:21:00 +00:00
|
|
|
.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}`);
|
|
|
|
}
|