Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/platform/endpoint/test/node/stream.splitChunk.spec.ts
13405 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
import { assert, suite, test } from 'vitest';
7
import { splitChunk } from '../../../networking/node/stream';
8
9
suite('splitChunk', () => {
10
test('splits correctly with one newline in between', function () {
11
const [lines, extra] = splitChunk('foo\nbar');
12
assert.deepStrictEqual(lines, ['foo']);
13
assert.strictEqual(extra, 'bar');
14
});
15
test('splits correctly with one newline in between and trailing', function () {
16
const [lines, extra] = splitChunk('foo\nbar\n');
17
assert.deepStrictEqual(lines, ['foo', 'bar']);
18
assert.strictEqual(extra, '');
19
});
20
test('splits correctly with two newlines in between', function () {
21
const [lines, extra] = splitChunk('foo\n\nbar');
22
assert.deepStrictEqual(lines, ['foo']);
23
assert.strictEqual(extra, 'bar');
24
});
25
test('splits correctly with two newlines in between and trailing', function () {
26
const [lines, extra] = splitChunk('foo\n\nbar\n\n');
27
assert.deepStrictEqual(lines, ['foo', 'bar']);
28
assert.strictEqual(extra, '');
29
});
30
test('splits correctly with three newlines in between', function () {
31
const [lines, extra] = splitChunk('foo\n\n\nbar');
32
assert.deepStrictEqual(lines, ['foo']);
33
assert.strictEqual(extra, 'bar');
34
});
35
test('splits correctly with three newlines in between and trailing', function () {
36
const [lines, extra] = splitChunk('foo\n\n\nbar\n\n\n');
37
assert.deepStrictEqual(lines, ['foo', 'bar']);
38
assert.strictEqual(extra, '');
39
});
40
});
41
42