Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/prompt/node/test/indentationGuesser.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 { describe, expect, it } from 'vitest';
7
import { transformIndentation } from '../indentationGuesser';
8
9
describe('identationGuesser', () => {
10
it('transformIndentation', () => {
11
expect(transformIndentation(' hello()', { insertSpaces: true, tabSize: 2 }, { insertSpaces: false, tabSize: 2 })).toBe('\thello()');
12
13
// 4 spaces to 2-space indent
14
expect(transformIndentation(' hello()', { insertSpaces: true, tabSize: 4 }, { insertSpaces: true, tabSize: 2 })).toBe(' hello()');
15
// tab to 4 spaces
16
expect(transformIndentation('\thello()', { insertSpaces: false, tabSize: 4 }, { insertSpaces: true, tabSize: 4 })).toBe(' hello()');
17
// 8 spaces to tab (tabSize 4)
18
expect(transformIndentation(' hello()', { insertSpaces: true, tabSize: 4 }, { insertSpaces: false, tabSize: 4 })).toBe('\t\thello()');
19
// 2 tabs to 4 spaces (tabSize 2)
20
expect(transformIndentation('\t\thello()', { insertSpaces: false, tabSize: 2 }, { insertSpaces: true, tabSize: 4 })).toBe(' hello()');
21
// No indentation change
22
expect(transformIndentation('hello()', { insertSpaces: true, tabSize: 2 }, { insertSpaces: true, tabSize: 2 })).toBe('hello()');
23
expect(transformIndentation(' \thello()', { insertSpaces: false, tabSize: 4 }, { insertSpaces: true, tabSize: 2 })).toBe(' \thello()');
24
});
25
});
26
27