deno.land / std@0.201.0 / streams / byte_slice_stream_test.ts
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { assertEquals, assertThrows } from "../assert/mod.ts";import { ByteSliceStream } from "./byte_slice_stream.ts";
Deno.test("[streams] ByteSliceStream", async function () { function createStream(start = 0, end = Infinity) { return new ReadableStream({ start(controller) { controller.enqueue(new Uint8Array([0, 1])); controller.enqueue(new Uint8Array([2, 3])); controller.close(); }, }).pipeThrough(new ByteSliceStream(start, end)); }
let chunks = [];
for await (const chunk of createStream(0, 3)) { chunks.push(chunk); } assertEquals(chunks, [ new Uint8Array([0, 1]), new Uint8Array([2, 3]), ]);
chunks = []; for await (const chunk of createStream(0, 1)) { chunks.push(chunk); } assertEquals(chunks, [ new Uint8Array([0, 1]), ]);
chunks = []; for await (const chunk of createStream(0, 2)) { chunks.push(chunk); } assertEquals(chunks, [ new Uint8Array([0, 1]), new Uint8Array([2]), ]);
chunks = []; for await (const chunk of createStream(0, 3)) { chunks.push(chunk); } assertEquals(chunks, [ new Uint8Array([0, 1]), new Uint8Array([2, 3]), ]);
chunks = []; for await (const chunk of createStream(1, 3)) { chunks.push(chunk); } assertEquals(chunks, [ new Uint8Array([1]), new Uint8Array([2, 3]), ]);
chunks = []; for await (const chunk of createStream(2, 3)) { chunks.push(chunk); } assertEquals(chunks, [ new Uint8Array([2, 3]), ]);
chunks = []; for await (const chunk of createStream(0, 10)) { chunks.push(chunk); } assertEquals(chunks, [ new Uint8Array([0, 1]), new Uint8Array([2, 3]), ]);
assertThrows(() => createStream(-1, Infinity));});
Version Info