Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/platform/chunking/node/test/naiveChunker.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 * as assert from 'assert';
7
import { suite, test } from 'vitest';
8
import { trimCommonLeadingWhitespace } from '../naiveChunker';
9
10
suite('trimCommonLeadingWhitespace', () => {
11
test('should trim common leading spaces', () => {
12
const { trimmedLines, shortestLeadingCommonWhitespace } = trimCommonLeadingWhitespace([
13
' const foo = 1;',
14
' const bar = 2;',
15
' const baz = 3;',
16
]);
17
18
assert.deepStrictEqual(trimmedLines, [
19
'const foo = 1;',
20
' const bar = 2;',
21
' const baz = 3;',
22
]);
23
assert.strictEqual(shortestLeadingCommonWhitespace, ' ');
24
});
25
26
test('should trim common leading tabs', () => {
27
const { trimmedLines, shortestLeadingCommonWhitespace } = trimCommonLeadingWhitespace([
28
'\t\tconst foo = 1;',
29
'\t\t\tconst bar = 2;',
30
'\t\t\t\tconst baz = 3;',
31
]);
32
33
assert.deepStrictEqual(trimmedLines, [
34
'const foo = 1;',
35
'\tconst bar = 2;',
36
'\t\tconst baz = 3;',
37
]);
38
assert.strictEqual(shortestLeadingCommonWhitespace, '\t\t');
39
});
40
41
test('should handle mixed spaces and tabs', () => {
42
const { trimmedLines, shortestLeadingCommonWhitespace } = trimCommonLeadingWhitespace([
43
' const foo = 1;',
44
' \t const bar = 2;',
45
' \t const baz = 3;',
46
]);
47
48
assert.deepStrictEqual(trimmedLines, [
49
' const foo = 1;',
50
' \t const bar = 2;',
51
'\t const baz = 3;',
52
]);
53
assert.strictEqual(shortestLeadingCommonWhitespace, ' ');
54
});
55
});
56
57