-
Notifications
You must be signed in to change notification settings - Fork 576
/
delimiter_stream_test.ts
36 lines (32 loc) · 1.2 KB
/
delimiter_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
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
import { DelimiterStream } from "./delimiter_stream.ts";
import { assert, assertEquals } from "../testing/asserts.ts";
Deno.test("[streams] DelimiterStream", async () => {
const textStream = new ReadableStream({
start(controller) {
controller.enqueue("qwertzu");
controller.enqueue("iopasdfoomnbvc");
controller.enqueue("xylkjhfoogfdsapfoooiuzt");
controller.enqueue("rewq098765432fo");
controller.enqueue("o349012i491290");
controller.close();
},
});
const lines = textStream
.pipeThrough(new TextEncoderStream())
.pipeThrough(new DelimiterStream(new TextEncoder().encode("foo")))
.pipeThrough(new TextDecoderStream());
const reader = lines.getReader();
const a = await reader.read();
assertEquals(a.value, "qwertzuiopasd");
const b = await reader.read();
assertEquals(b.value, "mnbvcxylkjh");
const c = await reader.read();
assertEquals(c.value, "gfdsap");
const d = await reader.read();
assertEquals(d.value, "oiuztrewq098765432");
const e = await reader.read();
assertEquals(e.value, "349012i491290");
const f = await reader.read();
assert(f.done);
});