Repository navigation
Expand file tree
/
Copy pathinstanceAcrossSplit.vscode.test.ts
More file actions
163 lines (154 loc) · 3.78 KB
/
Copy pathinstanceAcrossSplit.vscode.test.ts
File metadata and controls
163 lines (154 loc) · 3.78 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import type { Modifier, SpyIDE } from "@cursorless/common";
import {
HatStability,
LATEST_VERSION,
Range,
asyncSafety,
} from "@cursorless/common";
import {
getCursorlessApi,
openNewEditor,
runCursorlessCommand,
} from "@cursorless/vscode-common";
import * as assert from "assert";
import { Selection } from "vscode";
import { endToEndTestSetup } from "../endToEndTestSetup";
import { setupFake } from "./setupFake";
// Ensure that the "from" / "instance" work properly when "from"
// is run in a different editor from "instance"
suite("Instance across split", async function () {
const { getSpy } = endToEndTestSetup(this);
suiteSetup(async () => {
const { ide } = (await getCursorlessApi()).testHelpers!;
setupFake(ide, HatStability.stable);
});
test(
"Every instance",
asyncSafety(() =>
runTest(
getSpy(),
{
type: "everyScope",
scopeType: { type: "instance" },
},
true,
" bbb ",
),
),
);
test(
"Next instance",
asyncSafety(() =>
runTest(
getSpy(),
{
type: "relativeScope",
scopeType: { type: "instance" },
direction: "forward",
length: 1,
offset: 1,
},
false,
" bbb aaa aaa",
),
),
);
test(
"Two instances",
asyncSafety(() =>
runTest(
getSpy(),
{
type: "relativeScope",
scopeType: { type: "instance" },
direction: "forward",
length: 2,
offset: 0,
},
false,
" bbb aaa",
),
),
);
test(
"Second instance",
asyncSafety(() =>
runTest(
getSpy(),
{
type: "ordinalScope",
scopeType: { type: "instance" },
length: 1,
start: 1,
},
true,
" aaa bbb aaa",
),
),
);
});
async function runTest(
spyIde: SpyIDE,
modifier: Modifier,
useWholeFile: boolean,
expectedContents: string,
) {
const { hatTokenMap } = (await getCursorlessApi()).testHelpers!;
const { document: instanceDocument } = await openNewEditor("aaa");
/** The editor containing the "instance" */
const instanceEditor = spyIde.activeTextEditor!;
/** The editor in which "from" is run */
const fromEditor = await openNewEditor(" aaa bbb aaa aaa", "plaintext", true);
const { document: fromDocument } = fromEditor;
fromEditor.selections = [new Selection(0, 0, 0, 0)];
await hatTokenMap.allocateHats([
{
grapheme: "a",
hatStyle: "default",
hatRange: new Range(0, 0, 0, 1),
token: {
editor: instanceEditor,
offsets: { start: 0, end: 3 },
range: new Range(0, 0, 0, 3),
text: "aaa",
},
},
]);
// "from this" / "from file this", depending on the value of `useWholeFile`
await runCursorlessCommand({
version: LATEST_VERSION,
usePrePhraseSnapshot: false,
action: {
name: "experimental.setInstanceReference",
target: {
type: "primitive",
mark: {
type: "cursor",
},
modifiers: useWholeFile
? [{ type: "containingScope", scopeType: { type: "document" } }]
: [],
},
},
});
// "change <modifier> air", where <modifier> is some kind of "instance"
// modifier
await runCursorlessCommand({
version: LATEST_VERSION,
usePrePhraseSnapshot: false,
action: {
name: "clearAndSetSelection",
target: {
type: "primitive",
mark: {
type: "decoratedSymbol",
symbolColor: "default",
character: "a",
},
modifiers: [modifier],
},
},
});
assert.deepStrictEqual(instanceDocument.getText(), "aaa");
assert.deepStrictEqual(fromDocument.getText(), expectedContents);
}