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

text_line_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
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
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import { TextLineStream } from "./text_line_stream.ts";import { assertEquals } from "../assert/mod.ts";
Deno.test("TextLineStream parses simple input", async () => { const stream = ReadableStream.from([ "qwertzu", "iopasd\r\nmnbvc", "xylk\rjhgfds\napoiuzt\r", "qwr\r09ei\rqwrjiowqr\r", "\nrewq0987\n\n654321", "\nrewq0987\r\n\r\n654321\r", ]).pipeThrough(new TextLineStream());
assertEquals(await Array.fromAsync(stream), [ "qwertzuiopasd", "mnbvcxylk\rjhgfds", "apoiuzt\rqwr\r09ei\rqwrjiowqr", "rewq0987", "", "654321", "rewq0987", "", "654321\r", ]);
const stream2 = ReadableStream.from("rewq0987\r\n\r\n654321\n") .pipeThrough(new TextLineStream());
assertEquals(await Array.fromAsync(stream2), [ "rewq0987", "", "654321", ]);});
Deno.test("TextLineStream parses with `allowCR` enabled", async () => { const stream = ReadableStream.from([ "qwertzu", "iopasd\r\nmnbvc", "xylk\rjhgfds\napoiuzt\r", "qwr\r09ei\rqwrjiowqr\r", "\nrewq0987\n\n654321", "\nrewq0987\r\n\r\n654321\r", ]).pipeThrough(new TextLineStream({ allowCR: true })); assertEquals(await Array.fromAsync(stream), [ "qwertzuiopasd", "mnbvcxylk", "jhgfds", "apoiuzt", "qwr", "09ei", "qwrjiowqr", "rewq0987", "", "654321", "rewq0987", "", "654321", ]);
const stream2 = ReadableStream.from("rewq0987\r\n\r\n654321\n") .pipeThrough(new TextLineStream());
assertEquals(await Array.fromAsync(stream2), [ "rewq0987", "", "654321", ]);});
Deno.test("TextLineStream parses large chunks", async () => { const totalLines = 20_000; const stream = ReadableStream.from("\n".repeat(totalLines)) .pipeThrough(new TextLineStream()); const lines = await Array.fromAsync(stream);
assertEquals(lines.length, totalLines); assertEquals(lines, Array.from({ length: totalLines }).fill(""));});
Deno.test("TextLineStream parses no final empty chunk with terminal newline", async () => { const stream = ReadableStream.from([ "abc\n", "def\nghi\njk", "l\nmn", "o\np", "qr", "\nstu\nvwx\n", "yz\n", ]).pipeThrough(new TextLineStream());
assertEquals(await Array.fromAsync(stream), [ "abc", "def", "ghi", "jkl", "mno", "pqr", "stu", "vwx", "yz", ]);});
Deno.test("TextLineStream parses no final empty chunk without terminal newline", async () => { const stream = ReadableStream.from([ "abc\n", "def\nghi\njk", "l\nmn", "o\np", "qr", "\nstu\nvwx\n", "yz", ]).pipeThrough(new TextLineStream());
assertEquals(await Array.fromAsync(stream), [ "abc", "def", "ghi", "jkl", "mno", "pqr", "stu", "vwx", "yz", ]);});
std

Version Info

Tagged at
3 weeks ago