mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
b1b048d759
* initial commit * Update buffer_test.ts Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com> * remove brackets for classes --------- Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
|
|
import { assertEquals, assertThrows } from "../assert/mod.ts";
|
|
import { ByteSliceStream } from "./byte_slice_stream.ts";
|
|
|
|
Deno.test("ByteSliceStream", async function () {
|
|
function createStream(start = 0, end = Infinity) {
|
|
return ReadableStream.from([
|
|
new Uint8Array([0, 1]),
|
|
new Uint8Array([2, 3]),
|
|
]).pipeThrough(new ByteSliceStream(start, end));
|
|
}
|
|
|
|
let chunks = await Array.fromAsync(createStream(0, 3));
|
|
assertEquals(chunks, [
|
|
new Uint8Array([0, 1]),
|
|
new Uint8Array([2, 3]),
|
|
]);
|
|
|
|
chunks = await Array.fromAsync(createStream(0, 1));
|
|
assertEquals(chunks, [
|
|
new Uint8Array([0, 1]),
|
|
]);
|
|
|
|
chunks = await Array.fromAsync(createStream(0, 2));
|
|
assertEquals(chunks, [
|
|
new Uint8Array([0, 1]),
|
|
new Uint8Array([2]),
|
|
]);
|
|
|
|
chunks = await Array.fromAsync(createStream(0, 3));
|
|
assertEquals(chunks, [
|
|
new Uint8Array([0, 1]),
|
|
new Uint8Array([2, 3]),
|
|
]);
|
|
|
|
chunks = await Array.fromAsync(createStream(1, 3));
|
|
assertEquals(chunks, [
|
|
new Uint8Array([1]),
|
|
new Uint8Array([2, 3]),
|
|
]);
|
|
|
|
chunks = await Array.fromAsync(createStream(2, 3));
|
|
assertEquals(chunks, [
|
|
new Uint8Array([2, 3]),
|
|
]);
|
|
|
|
chunks = await Array.fromAsync(createStream(0, 10));
|
|
assertEquals(chunks, [
|
|
new Uint8Array([0, 1]),
|
|
new Uint8Array([2, 3]),
|
|
]);
|
|
|
|
assertThrows(() => createStream(-1, Infinity));
|
|
});
|