deno.land / std@0.224.0 / streams / delimiter_stream_test.ts

delimiter_stream_test.ts
View Documentation
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { DelimiterStream } from "./delimiter_stream.ts";import { testTransformStream } from "./_test_common.ts";
const DELIMITER_STREAM_INPUTS = [ "a", // more than one subsequent chunks with no delimiters "b", // more than one subsequent chunks with no delimiters "cCRLF", // more than one subsequent chunks with no delimiters "CRLF", // chunk with only delimiter "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) "asdfghjkliopCR", // split delimiter with followup (1/2) "LFytrewqCRLFmnbvcxz", // split delimiter with followup (2/2) "CRLFasd", // chunk starts with delimiter].map((s) => new TextEncoder().encode(s));
Deno.test("DelimiterStream discard", async () => { const crlf = new TextEncoder().encode("CRLF"); const delimStream = new DelimiterStream(crlf, { disposition: "discard" }); const outputs = [ "abc", "", "qwertzuiopasd", "mnbvcxylkjh", "gfdsap", "oiuzteuoi", "", "aueiourewq098765432", "349012i491290asdfghjkliop", "ytrewq", "mnbvcxz", "asd", ].map((s) => new TextEncoder().encode(s)); await testTransformStream(delimStream, DELIMITER_STREAM_INPUTS, outputs);});
Deno.test("DelimiterStream suffix", async () => { const crlf = new TextEncoder().encode("CRLF"); const delimStream = new DelimiterStream(crlf, { disposition: "suffix" }); const outputs = [ "abcCRLF", "CRLF", "qwertzuiopasdCRLF", "mnbvcxylkjhCRLF", "gfdsapCRLF", "oiuzteuoiCRLF", "CRLF", "aueiourewq098765432CRLF", "349012i491290asdfghjkliopCRLF", "ytrewqCRLF", "mnbvcxzCRLF", "asd", ].map((s) => new TextEncoder().encode(s)); await testTransformStream(delimStream, DELIMITER_STREAM_INPUTS, outputs);});
Deno.test("DelimiterStream prefix", async () => { const crlf = new TextEncoder().encode("CRLF"); const delimStream = new DelimiterStream(crlf, { disposition: "prefix" }); const outputs = [ "abc", "CRLF", "CRLFqwertzuiopasd", "CRLFmnbvcxylkjh", "CRLFgfdsap", "CRLFoiuzteuoi", "CRLF", "CRLFaueiourewq098765432", "CRLF349012i491290asdfghjkliop", "CRLFytrewq", "CRLFmnbvcxz", "CRLFasd", ].map((s) => new TextEncoder().encode(s)); await testTransformStream(delimStream, DELIMITER_STREAM_INPUTS, outputs);});
const CHAR_DELIMITER_STREAM_INPUTS = [ "a", // more than one subsequent chunks with no delimiters "b", // more than one subsequent chunks with no delimiters "c_", // more than one subsequent chunks with no delimiters "_", // chunk with only delimiter "qwertzu", // no delimiter "iopasd_mnbvc", // one delimiter in the middle "xylkjh_gfdsap_oiuzt", // two separate delimiters "euoi__aueiou", // two consecutive delimiters "rewq098765432", // more than one intermediate chunks with no delimiters "349012i491290", // more than one intermediate chunks with no delimiters "asdfghjkliop", // more than one intermediate chunks with no delimiters "ytrewq_mnbvcxz", // one delimiter in the middle after multiple chunks with no delimiters "_asd", // chunk starts with delimiter].map((s) => new TextEncoder().encode(s));
Deno.test("DelimiterStream char delimiter, discard", async () => { const delim = new TextEncoder().encode("_"); const delimStream = new DelimiterStream(delim, { disposition: "discard" }); const outputs = [ "abc", "", "qwertzuiopasd", "mnbvcxylkjh", "gfdsap", "oiuzteuoi", "", "aueiourewq098765432349012i491290asdfghjkliopytrewq", "mnbvcxz", "asd", ].map((s) => new TextEncoder().encode(s)); await testTransformStream(delimStream, CHAR_DELIMITER_STREAM_INPUTS, outputs);});
Deno.test("DelimiterStream char delimiter, suffix", async () => { const delim = new TextEncoder().encode("_"); const delimStream = new DelimiterStream(delim, { disposition: "suffix" }); const outputs = [ "abc_", "_", "qwertzuiopasd_", "mnbvcxylkjh_", "gfdsap_", "oiuzteuoi_", "_", "aueiourewq098765432349012i491290asdfghjkliopytrewq_", "mnbvcxz_", "asd", ].map((s) => new TextEncoder().encode(s)); await testTransformStream(delimStream, CHAR_DELIMITER_STREAM_INPUTS, outputs);});
Deno.test("DelimiterStream char delimiter, prefix", async () => { const delim = new TextEncoder().encode("_"); const delimStream = new DelimiterStream(delim, { disposition: "prefix" }); const outputs = [ "abc", "_", "_qwertzuiopasd", "_mnbvcxylkjh", "_gfdsap", "_oiuzteuoi", "_", "_aueiourewq098765432349012i491290asdfghjkliopytrewq", "_mnbvcxz", "_asd", ].map((s) => new TextEncoder().encode(s)); await testTransformStream(delimStream, CHAR_DELIMITER_STREAM_INPUTS, outputs);});
Deno.test("DelimiterStream regression 3609", async () => { const delimStream = new DelimiterStream(new TextEncoder().encode(";")); const inputs = [ ";ab;fg;hn;j", "k;lr;op;rt;;", ].map((s) => new TextEncoder().encode(s)); const outputs = [ "", "ab", "fg", "hn", "jk", "lr", "op", "rt", "", "", ].map((s) => new TextEncoder().encode(s)); await testTransformStream(delimStream, inputs, outputs);});
std

Version Info

Tagged at
6 months ago