forked from irinazheltisheva/vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestCommand.ts
More file actions
76 lines (64 loc) · 2.54 KB
/
Copy pathtestCommand.ts
File metadata and controls
76 lines (64 loc) · 2.54 KB
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
/*---------------------------------------------------------------------------------------------
* 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 { IRange } from 'vs/editor/common/core/range';
import { Selection, ISelection } from 'vs/editor/common/core/selection';
import { ICommand, IEditOperationBuilder } from 'vs/editor/common/editorCommon';
import { IIdentifiedSingleEditOperation, ITextModel } from 'vs/editor/common/model';
import { createTextModel } from 'vs/editor/test/common/editorTestUtils';
import { LanguageIdentifier } from 'vs/editor/common/modes';
import { withTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor';
export function testCommand(
lines: string[],
languageIdentifier: LanguageIdentifier | null,
selection: Selection,
commandFactory: (selection: Selection) => ICommand,
expectedLines: string[],
expectedSelection: Selection,
forceTokenization?: boolean
): void {
let model = createTextModel(lines.join('\n'), undefined, languageIdentifier);
withTestCodeEditor('', { model: model }, (_editor, cursor) => {
if (!cursor) {
return;
}
if (forceTokenization) {
model.forceTokenization(model.getLineCount());
}
cursor.setSelections('tests', [selection]);
cursor.executeCommand(commandFactory(cursor.getSelection()), 'tests');
assert.deepEqual(model.getLinesContent(), expectedLines);
let actualSelection = cursor.getSelection();
assert.deepEqual(actualSelection.toString(), expectedSelection.toString());
});
model.dispose();
}
/**
* Extract edit operations if command `command` were to execute on model `model`
*/
export function getEditOperation(model: ITextModel, command: ICommand): IIdentifiedSingleEditOperation[] {
let operations: IIdentifiedSingleEditOperation[] = [];
let editOperationBuilder: IEditOperationBuilder = {
addEditOperation: (range: IRange, text: string, forceMoveMarkers: boolean = false) => {
operations.push({
range: range,
text: text,
forceMoveMarkers: forceMoveMarkers
});
},
addTrackedEditOperation: (range: IRange, text: string, forceMoveMarkers: boolean = false) => {
operations.push({
range: range,
text: text,
forceMoveMarkers: forceMoveMarkers
});
},
trackSelection: (selection: ISelection) => {
return '';
}
};
command.getEditOperations(model, editOperationBuilder);
return operations;
}