Skip to content

Commit ede8d6f

Browse files
committed
Initial working tests
1 parent 2e5757f commit ede8d6f

File tree

6 files changed

+101
-2
lines changed

6 files changed

+101
-2
lines changed

packages/common/src/ide/normalized/NormalizedIDE.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export class NormalizedIDE extends PassthroughIDEBase {
5252
),
5353
snippetsDir: getFixturePath("cursorless-snippets"),
5454
});
55+
this.configuration.mockConfiguration("decorationDebounceDelayMs", 0);
5556
}
5657

5758
flashRanges(flashDescriptors: FlashDescriptor[]): Promise<void> {

packages/cursorless-engine/src/scopeProviders/ScopeRangeWatcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { ScopeRangeProvider } from "./ScopeRangeProvider";
2020
*/
2121
export class ScopeRangeWatcher {
2222
private disposables: Disposable[] = [];
23-
private debouncer = new Debouncer(() => this.onChange);
23+
private debouncer = new Debouncer(() => this.onChange());
2424
private listeners: (() => void)[] = [];
2525

2626
constructor(

packages/cursorless-engine/src/scopeProviders/ScopeSupportWatcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { ScopeSupportChecker } from "./ScopeSupportChecker";
1919
*/
2020
export class ScopeSupportWatcher {
2121
private disposables: Disposable[] = [];
22-
private debouncer = new Debouncer(() => this.onChange);
22+
private debouncer = new Debouncer(() => this.onChange());
2323
private listeners: ScopeSupportEventCallback[] = [];
2424

2525
constructor(
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {
2+
ScopeSupportInfo,
3+
ScopeSupportLevels
4+
} from "@cursorless/common";
5+
import Sinon = require("sinon");
6+
import { assert } from "chai";
7+
8+
export function assertCalledWithScopeInfo(
9+
fake: Sinon.SinonSpy<[scopeInfos: ScopeSupportLevels], void>,
10+
expectedScopeInfo: ScopeSupportInfo
11+
) {
12+
Sinon.assert.called(fake);
13+
const actualScopeInfo = fake.lastCall.args[0].find(
14+
(scopeInfo) => scopeInfo.scopeType.type === expectedScopeInfo.scopeType.type
15+
);
16+
assert.isDefined(actualScopeInfo);
17+
assert.deepEqual(actualScopeInfo, expectedScopeInfo);
18+
fake.resetHistory();
19+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { getCursorlessApi, openNewEditor } from "@cursorless/vscode-common";
2+
import {
3+
ScopeSupport,
4+
ScopeSupportInfo,
5+
ScopeSupportLevels,
6+
} from "@cursorless/common";
7+
import Sinon = require("sinon");
8+
import { sleepWithBackoff } from "../../endToEndTestSetup";
9+
import { commands } from "vscode";
10+
import { assertCalledWithScopeInfo } from "./assertCalledWithScopeInfo";
11+
12+
/**
13+
* Tests that the scope provider correctly reports the scope support for a
14+
* simple named function.
15+
*/
16+
export async function runBasicScopeInfoTest() {
17+
const { scopeProvider } = (await getCursorlessApi()).testHelpers!;
18+
const fake = Sinon.fake<[scopeInfos: ScopeSupportLevels], void>();
19+
20+
await commands.executeCommand("workbench.action.closeAllEditors");
21+
22+
const disposable = scopeProvider.onDidChangeScopeSupport(fake);
23+
24+
try {
25+
assertCalledWithScopeInfo(fake, unsupported);
26+
27+
await openNewEditor(contents, {
28+
languageId: "typescript",
29+
});
30+
await sleepWithBackoff(25);
31+
32+
assertCalledWithScopeInfo(fake, present);
33+
34+
await commands.executeCommand("workbench.action.closeAllEditors");
35+
await sleepWithBackoff(25);
36+
37+
assertCalledWithScopeInfo(fake, unsupported);
38+
} finally {
39+
disposable.dispose();
40+
}
41+
}
42+
43+
const contents = `
44+
function helloWorld() {
45+
46+
}
47+
`;
48+
49+
function getExpectedScope(scopeSupport: ScopeSupport): ScopeSupportInfo {
50+
return {
51+
humanReadableName: "named function",
52+
isLanguageSpecific: true,
53+
iterationScopeSupport: scopeSupport,
54+
scopeType: {
55+
type: "namedFunction",
56+
},
57+
spokenForm: {
58+
alternatives: [],
59+
preferred: "funk",
60+
type: "success",
61+
},
62+
support: scopeSupport,
63+
};
64+
}
65+
66+
const unsupported = getExpectedScope(ScopeSupport.unsupported);
67+
const present = getExpectedScope(ScopeSupport.supportedAndPresentInEditor);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { endToEndTestSetup } from "../../endToEndTestSetup";
2+
import { asyncSafety } from "@cursorless/common";
3+
import { runBasicScopeInfoTest } from "./runBasicScopeInfoTest";
4+
5+
suite("scope provider", async function () {
6+
endToEndTestSetup(this);
7+
8+
test(
9+
"basic",
10+
asyncSafety(() => runBasicScopeInfoTest()),
11+
);
12+
});

0 commit comments

Comments
 (0)