Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/test/common/controller/cursorAtomicMoveOperations.test.ts
3296 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 { AtomicTabMoveOperations, Direction } from '../../../common/cursor/cursorAtomicMoveOperations.js';
9
10
suite('Cursor move command test', () => {
11
12
ensureNoDisposablesAreLeakedInTestSuite();
13
14
test('Test whitespaceVisibleColumn', () => {
15
const testCases = [
16
{
17
lineContent: ' ',
18
tabSize: 4,
19
expectedPrevTabStopPosition: [-1, 0, 0, 0, 0, 4, 4, 4, 4, -1],
20
expectedPrevTabStopVisibleColumn: [-1, 0, 0, 0, 0, 4, 4, 4, 4, -1],
21
expectedVisibleColumn: [0, 1, 2, 3, 4, 5, 6, 7, 8, -1],
22
},
23
{
24
lineContent: ' ',
25
tabSize: 4,
26
expectedPrevTabStopPosition: [-1, 0, 0, -1],
27
expectedPrevTabStopVisibleColumn: [-1, 0, 0, -1],
28
expectedVisibleColumn: [0, 1, 2, -1],
29
},
30
{
31
lineContent: '\t',
32
tabSize: 4,
33
expectedPrevTabStopPosition: [-1, 0, -1],
34
expectedPrevTabStopVisibleColumn: [-1, 0, -1],
35
expectedVisibleColumn: [0, 4, -1],
36
},
37
{
38
lineContent: '\t ',
39
tabSize: 4,
40
expectedPrevTabStopPosition: [-1, 0, 1, -1],
41
expectedPrevTabStopVisibleColumn: [-1, 0, 4, -1],
42
expectedVisibleColumn: [0, 4, 5, -1],
43
},
44
{
45
lineContent: ' \t\t ',
46
tabSize: 4,
47
expectedPrevTabStopPosition: [-1, 0, 0, 2, 3, -1],
48
expectedPrevTabStopVisibleColumn: [-1, 0, 0, 4, 8, -1],
49
expectedVisibleColumn: [0, 1, 4, 8, 9, -1],
50
},
51
{
52
lineContent: ' \tA',
53
tabSize: 4,
54
expectedPrevTabStopPosition: [-1, 0, 0, -1, -1],
55
expectedPrevTabStopVisibleColumn: [-1, 0, 0, -1, -1],
56
expectedVisibleColumn: [0, 1, 4, -1, -1],
57
},
58
{
59
lineContent: 'A',
60
tabSize: 4,
61
expectedPrevTabStopPosition: [-1, -1, -1],
62
expectedPrevTabStopVisibleColumn: [-1, -1, -1],
63
expectedVisibleColumn: [0, -1, -1],
64
},
65
{
66
lineContent: '',
67
tabSize: 4,
68
expectedPrevTabStopPosition: [-1, -1],
69
expectedPrevTabStopVisibleColumn: [-1, -1],
70
expectedVisibleColumn: [0, -1],
71
},
72
];
73
74
for (const testCase of testCases) {
75
const maxPosition = testCase.expectedVisibleColumn.length;
76
for (let position = 0; position < maxPosition; position++) {
77
const actual = AtomicTabMoveOperations.whitespaceVisibleColumn(testCase.lineContent, position, testCase.tabSize);
78
const expected = [
79
testCase.expectedPrevTabStopPosition[position],
80
testCase.expectedPrevTabStopVisibleColumn[position],
81
testCase.expectedVisibleColumn[position]
82
];
83
assert.deepStrictEqual(actual, expected);
84
}
85
}
86
});
87
88
test('Test atomicPosition', () => {
89
const testCases = [
90
{
91
lineContent: ' ',
92
tabSize: 4,
93
expectedLeft: [-1, 0, 0, 0, 0, 4, 4, 4, 4, -1],
94
expectedRight: [4, 4, 4, 4, 8, 8, 8, 8, -1, -1],
95
expectedNearest: [0, 0, 0, 4, 4, 4, 4, 8, 8, -1],
96
},
97
{
98
lineContent: ' \t',
99
tabSize: 4,
100
expectedLeft: [-1, 0, 0, -1],
101
expectedRight: [2, 2, -1, -1],
102
expectedNearest: [0, 0, 2, -1],
103
},
104
{
105
lineContent: '\t ',
106
tabSize: 4,
107
expectedLeft: [-1, 0, -1, -1],
108
expectedRight: [1, -1, -1, -1],
109
expectedNearest: [0, 1, -1, -1],
110
},
111
{
112
lineContent: ' \t ',
113
tabSize: 4,
114
expectedLeft: [-1, 0, 0, -1, -1],
115
expectedRight: [2, 2, -1, -1, -1],
116
expectedNearest: [0, 0, 2, -1, -1],
117
},
118
{
119
lineContent: ' A',
120
tabSize: 4,
121
expectedLeft: [-1, 0, 0, 0, 0, 4, 4, 4, 4, -1, -1],
122
expectedRight: [4, 4, 4, 4, 8, 8, 8, 8, -1, -1, -1],
123
expectedNearest: [0, 0, 0, 4, 4, 4, 4, 8, 8, -1, -1],
124
},
125
{
126
lineContent: ' foo',
127
tabSize: 4,
128
expectedLeft: [-1, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1],
129
expectedRight: [4, 4, 4, 4, -1, -1, -1, -1, -1, -1, -1],
130
expectedNearest: [0, 0, 0, 4, 4, -1, -1, -1, -1, -1, -1],
131
},
132
];
133
134
for (const testCase of testCases) {
135
for (const { direction, expected } of [
136
{
137
direction: Direction.Left,
138
expected: testCase.expectedLeft,
139
},
140
{
141
direction: Direction.Right,
142
expected: testCase.expectedRight,
143
},
144
{
145
direction: Direction.Nearest,
146
expected: testCase.expectedNearest,
147
},
148
]) {
149
150
const actual = expected.map((_, i) => AtomicTabMoveOperations.atomicPosition(testCase.lineContent, i, testCase.tabSize, direction));
151
assert.deepStrictEqual(actual, expected);
152
}
153
}
154
});
155
});
156
157