Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/base/test/node/nodeStreams.test.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
7
import { Writable } from 'stream';
8
import assert from 'assert';
9
import { StreamSplitter } from '../../node/nodeStreams.js';
10
import { ensureNoDisposablesAreLeakedInTestSuite } from '../common/utils.js';
11
12
suite('StreamSplitter', () => {
13
ensureNoDisposablesAreLeakedInTestSuite();
14
15
test('should split a stream on a single character splitter', (done) => {
16
const chunks: string[] = [];
17
const splitter = new StreamSplitter('\n');
18
const writable = new Writable({
19
write(chunk, _encoding, callback) {
20
chunks.push(chunk.toString());
21
callback();
22
},
23
});
24
25
splitter.pipe(writable);
26
splitter.write('hello\nwor');
27
splitter.write('ld\n');
28
splitter.write('foo\nbar\nz');
29
splitter.end(() => {
30
assert.deepStrictEqual(chunks, ['hello\n', 'world\n', 'foo\n', 'bar\n', 'z']);
31
done();
32
});
33
});
34
35
test('should split a stream on a multi-character splitter', (done) => {
36
const chunks: string[] = [];
37
const splitter = new StreamSplitter('---');
38
const writable = new Writable({
39
write(chunk, _encoding, callback) {
40
chunks.push(chunk.toString());
41
callback();
42
},
43
});
44
45
splitter.pipe(writable);
46
splitter.write('hello---wor');
47
splitter.write('ld---');
48
splitter.write('foo---bar---z');
49
splitter.end(() => {
50
assert.deepStrictEqual(chunks, ['hello---', 'world---', 'foo---', 'bar---', 'z']);
51
done();
52
});
53
});
54
});
55
56