Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/contrib/lineSelection/test/browser/lineSelection.test.ts
4780 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 from 'assert';
7
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';
8
import type { ICodeEditor } from '../../../../browser/editorBrowser.js';
9
import { EditorAction } from '../../../../browser/editorExtensions.js';
10
import { Position } from '../../../../common/core/position.js';
11
import { Selection } from '../../../../common/core/selection.js';
12
import { ExpandLineSelectionAction } from '../../browser/lineSelection.js';
13
import { withTestCodeEditor } from '../../../../test/browser/testCodeEditor.js';
14
15
function executeAction(action: EditorAction, editor: ICodeEditor): void {
16
action.run(null!, editor, undefined);
17
}
18
19
suite('LineSelection', () => {
20
21
ensureNoDisposablesAreLeakedInTestSuite();
22
23
test('', () => {
24
const LINE1 = ' \tMy First Line\t ';
25
const LINE2 = '\tMy Second Line';
26
const LINE3 = ' Third Line🐶';
27
const LINE4 = '';
28
const LINE5 = '1';
29
30
const TEXT =
31
LINE1 + '\r\n' +
32
LINE2 + '\n' +
33
LINE3 + '\n' +
34
LINE4 + '\r\n' +
35
LINE5;
36
37
withTestCodeEditor(TEXT, {}, (editor, viewModel) => {
38
const action = new ExpandLineSelectionAction();
39
40
// 0 1 2
41
// 01234 56789012345678 0
42
// let LINE1 = ' \tMy First Line\t ';
43
editor.setPosition(new Position(1, 1));
44
executeAction(action, editor);
45
assert.deepStrictEqual(editor.getSelection(), new Selection(1, 1, 2, 1));
46
47
editor.setPosition(new Position(1, 2));
48
executeAction(action, editor);
49
assert.deepStrictEqual(editor.getSelection(), new Selection(1, 1, 2, 1));
50
51
editor.setPosition(new Position(1, 5));
52
executeAction(action, editor);
53
assert.deepStrictEqual(editor.getSelection(), new Selection(1, 1, 2, 1));
54
55
editor.setPosition(new Position(1, 19));
56
executeAction(action, editor);
57
assert.deepStrictEqual(editor.getSelection(), new Selection(1, 1, 2, 1));
58
59
editor.setPosition(new Position(1, 20));
60
executeAction(action, editor);
61
assert.deepStrictEqual(editor.getSelection(), new Selection(1, 1, 2, 1));
62
63
editor.setPosition(new Position(1, 21));
64
executeAction(action, editor);
65
assert.deepStrictEqual(editor.getSelection(), new Selection(1, 1, 2, 1));
66
executeAction(action, editor);
67
assert.deepStrictEqual(editor.getSelection(), new Selection(1, 1, 3, 1));
68
executeAction(action, editor);
69
assert.deepStrictEqual(editor.getSelection(), new Selection(1, 1, 4, 1));
70
executeAction(action, editor);
71
assert.deepStrictEqual(editor.getSelection(), new Selection(1, 1, 5, 1));
72
executeAction(action, editor);
73
assert.deepStrictEqual(editor.getSelection(), new Selection(1, 1, 5, LINE5.length + 1));
74
executeAction(action, editor);
75
assert.deepStrictEqual(editor.getSelection(), new Selection(1, 1, 5, LINE5.length + 1));
76
});
77
});
78
});
79
80