-
Notifications
You must be signed in to change notification settings - Fork 578
/
delimiter_stream_test.ts
73 lines (69 loc) · 2.59 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
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
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { DelimiterStream } from "./delimiter_stream.ts";
import { testTransformStream } from "./_test_common.ts";
Deno.test("[streams] DelimiterStream, discard", async () => {
const crlf = new TextEncoder().encode("CRLF");
const delimStream = new DelimiterStream(crlf, { disposition: "discard" });
const inputs = [
"qwertzu", // no delimiter
"iopasdCRLFmnbvc", // one delimiter in the middle
"xylkjhCRLFgfdsapCRLFoiuzt", // two separate delimiters
"euoiCRLFCRLFaueiou", // two consecutive delimiters
"rewq098765432CR", // split delimiter (1/2)
"LF349012i491290", // split delimiter (2/2)
].map((s) => new TextEncoder().encode(s));
const outputs = [
"qwertzuiopasd",
"mnbvcxylkjh",
"gfdsap",
"oiuzteuoi",
"",
"aueiourewq098765432",
"349012i491290",
].map((s) => new TextEncoder().encode(s));
await testTransformStream(delimStream, inputs, outputs);
});
Deno.test("[streams] DelimiterStream, suffix", async () => {
const crlf = new TextEncoder().encode("CRLF");
const delimStream = new DelimiterStream(crlf, { disposition: "suffix" });
const inputs = [
"qwertzu", // no delimiter
"iopasdCRLFmnbvc", // one delimiter in the middle
"xylkjhCRLFgfdsapCRLFoiuzt", // two separate delimiters
"euoiCRLFCRLFaueiou", // two consecutive delimiters
"rewq098765432CR", // split delimiter (1/2)
"LF349012i491290", // split delimiter (2/2)
].map((s) => new TextEncoder().encode(s));
const outputs = [
"qwertzuiopasdCRLF",
"mnbvcxylkjhCRLF",
"gfdsapCRLF",
"oiuzteuoiCRLF",
"CRLF",
"aueiourewq098765432CRLF",
"349012i491290",
].map((s) => new TextEncoder().encode(s));
await testTransformStream(delimStream, inputs, outputs);
});
Deno.test("[streams] DelimiterStream, prefix", async () => {
const crlf = new TextEncoder().encode("CRLF");
const delimStream = new DelimiterStream(crlf, { disposition: "prefix" });
const inputs = [
"qwertzu", // no delimiter
"iopasdCRLFmnbvc", // one delimiter in the middle
"xylkjhCRLFgfdsapCRLFoiuzt", // two separate delimiters
"euoiCRLFCRLFaueiou", // two consecutive delimiters
"rewq098765432CR", // split delimiter (1/2)
"LF349012i491290", // split delimiter (2/2)
].map((s) => new TextEncoder().encode(s));
const outputs = [
"qwertzuiopasd",
"CRLFmnbvcxylkjh",
"CRLFgfdsap",
"CRLFoiuzteuoi",
"CRLF",
"CRLFaueiourewq098765432",
"CRLF349012i491290",
].map((s) => new TextEncoder().encode(s));
await testTransformStream(delimStream, inputs, outputs);
});