Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/contrib/caretOperations/test/browser/moveCarretCommand.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 { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';
7
import { Selection } from '../../../../common/core/selection.js';
8
import { MoveCaretCommand } from '../../browser/moveCaretCommand.js';
9
import { testCommand } from '../../../../test/browser/testCommand.js';
10
11
12
function testMoveCaretLeftCommand(lines: string[], selection: Selection, expectedLines: string[], expectedSelection: Selection): void {
13
testCommand(lines, null, selection, (accessor, sel) => new MoveCaretCommand(sel, true), expectedLines, expectedSelection);
14
}
15
16
function testMoveCaretRightCommand(lines: string[], selection: Selection, expectedLines: string[], expectedSelection: Selection): void {
17
testCommand(lines, null, selection, (accessor, sel) => new MoveCaretCommand(sel, false), expectedLines, expectedSelection);
18
}
19
20
suite('Editor Contrib - Move Caret Command', () => {
21
22
ensureNoDisposablesAreLeakedInTestSuite();
23
24
test('move selection to left', function () {
25
testMoveCaretLeftCommand(
26
[
27
'012345'
28
],
29
new Selection(1, 3, 1, 5),
30
[
31
'023145'
32
],
33
new Selection(1, 2, 1, 4)
34
);
35
});
36
test('move selection to right', function () {
37
testMoveCaretRightCommand(
38
[
39
'012345'
40
],
41
new Selection(1, 3, 1, 5),
42
[
43
'014235'
44
],
45
new Selection(1, 4, 1, 6)
46
);
47
});
48
test('move selection to left - from first column - no change', function () {
49
testMoveCaretLeftCommand(
50
[
51
'012345'
52
],
53
new Selection(1, 1, 1, 1),
54
[
55
'012345'
56
],
57
new Selection(1, 1, 1, 1)
58
);
59
});
60
test('move selection to right - from last column - no change', function () {
61
testMoveCaretRightCommand(
62
[
63
'012345'
64
],
65
new Selection(1, 5, 1, 7),
66
[
67
'012345'
68
],
69
new Selection(1, 5, 1, 7)
70
);
71
});
72
});
73
74