-
Notifications
You must be signed in to change notification settings - Fork 27.9k
/
find.test.ts
81 lines (63 loc) · 2.64 KB
/
find.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { Position } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
import { getSelectionSearchString } from 'vs/editor/contrib/find/findController';
import { withTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
suite('Find', () => {
test('search string at position', () => {
withTestCodeEditor([
'ABC DEF',
'0123 456'
], {}, (editor, cursor) => {
// The cursor is at the very top, of the file, at the first ABC
let searchStringAtTop = getSelectionSearchString(editor);
assert.equal(searchStringAtTop, null);
// Move cursor to the end of ABC
editor.setPosition(new Position(1, 3));
let searchStringAfterABC = getSelectionSearchString(editor);
assert.equal(searchStringAfterABC, null);
});
});
test('search string with selection', () => {
withTestCodeEditor([
'ABC DEF',
'0123 456'
], {}, (editor, cursor) => {
// Select A of ABC
editor.setSelection(new Range(1, 1, 1, 2));
let searchStringSelectionA = getSelectionSearchString(editor);
assert.equal(searchStringSelectionA, 'A');
// Select BC of ABC
editor.setSelection(new Range(1, 2, 1, 4));
let searchStringSelectionBC = getSelectionSearchString(editor);
assert.equal(searchStringSelectionBC, 'BC');
// Select BC DE
editor.setSelection(new Range(1, 2, 1, 7));
let searchStringSelectionBCDE = getSelectionSearchString(editor);
assert.equal(searchStringSelectionBCDE, 'BC DE');
});
});
test('search string with multiline selection', () => {
withTestCodeEditor([
'ABC DEF',
'0123 456'
], {}, (editor, cursor) => {
// Select first line and newline
editor.setSelection(new Range(1, 1, 2, 1));
let searchStringSelectionWholeLine = getSelectionSearchString(editor);
assert.equal(searchStringSelectionWholeLine, null);
// Select first line and chunk of second
editor.setSelection(new Range(1, 1, 2, 4));
let searchStringSelectionTwoLines = getSelectionSearchString(editor);
assert.equal(searchStringSelectionTwoLines, null);
// Select end of first line newline and and chunk of second
editor.setSelection(new Range(1, 7, 2, 4));
let searchStringSelectionSpanLines = getSelectionSearchString(editor);
assert.equal(searchStringSelectionSpanLines, null);
});
});
});