deno.land / std@0.173.0 / streams / byte_slice_stream_test.ts

byte_slice_stream_test.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { assertEquals, assertThrows } from "../testing/asserts.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));});
std

Version Info

Tagged at
a year ago