Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasArvidsson committed Feb 19, 2024
1 parent 5b7371e commit 300511c
Show file tree
Hide file tree
Showing 17 changed files with 118 additions and 6 deletions.
4 changes: 3 additions & 1 deletion cursorless-talon/src/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

from .fallback import perform_fallback

COMMAND_VERSION = 7


@dataclasses.dataclass
class CursorlessCommand:
version = 7
version = COMMAND_VERSION
spokenForm: str
usePrePhraseSnapshot: bool
action: dict
Expand Down
5 changes: 5 additions & 0 deletions cursorless-talon/src/fallback.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

from talon import actions

from .command import COMMAND_VERSION

# This ensures that we remember to update fallback if the response payload changes
assert COMMAND_VERSION == 7

action_callbacks = {
"getText": lambda: [actions.edit.selected_text()],
"setSelection": actions.skip,
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export * from "./types/TestCaseFixture";
export * from "./util/getEnvironmentVariableStrict";
export * from "./util/CompositeKeyDefaultMap";
export * from "./util/toPlainObject";
export * from "./util/clientSupportsFallBack";
export * from "./util/clientSupportsFallback";

Check failure on line 99 in packages/common/src/index.ts

View workflow job for this annotation

GitHub Actions / test-docs-build

Cannot find module './util/clientSupportsFallback' or its corresponding type declarations.

Check failure on line 99 in packages/common/src/index.ts

View workflow job for this annotation

GitHub Actions / Test (macos-latest, stable)

Already included file name '/Users/runner/work/cursorless/cursorless/packages/common/src/util/clientSupportsFallback.ts' differs from file name '/Users/runner/work/cursorless/cursorless/packages/common/src/util/clientSupportsFallBack.ts' only in casing.

Check failure on line 99 in packages/common/src/index.ts

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, stable)

Cannot find module './util/clientSupportsFallback' or its corresponding type declarations.

Check failure on line 99 in packages/common/src/index.ts

View workflow job for this annotation

GitHub Actions / Test (windows-latest, stable)

Already included file name 'D:/a/cursorless/cursorless/packages/common/src/util/clientSupportsFallback.ts' differs from file name 'D:/a/cursorless/cursorless/packages/common/src/util/clientSupportsFallBack.ts' only in casing.

Check failure on line 99 in packages/common/src/index.ts

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest, legacy)

Cannot find module './util/clientSupportsFallback' or its corresponding type declarations.
export * from "./scopeSupportFacets/scopeSupportFacets.types";
export * from "./scopeSupportFacets/scopeSupportFacetInfos";
export * from "./scopeSupportFacets/textualScopeSupportFacetInfos";
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/testUtil/serializeTestFixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function reorderFields(
): EnforceUndefined<TestCaseFixtureLegacy> {
return {
languageId: fixture.languageId,
focusedElementType: fixture.focusedElementType,
postEditorOpenSleepTimeMs: fixture.postEditorOpenSleepTimeMs,
postCommandSleepTimeMs: fixture.postCommandSleepTimeMs,
command: fixture.command,
Expand Down
7 changes: 6 additions & 1 deletion packages/common/src/types/TestCaseFixture.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Command, CommandLatest, Fallback } from "..";
import type { Command, CommandLatest, Fallback, FocusedElementType } from "..";
import type { TestCaseSnapshot } from "../testUtil/TestCaseSnapshot";
import type { PlainSpyIDERecordedValues } from "../testUtil/spyToPlainObject";

Expand All @@ -12,6 +12,11 @@ interface TestCaseFixtureBase {
postCommandSleepTimeMs?: number;
spokenFormError?: string;

/**
* The type of element that is focused before the command is executed. If undefined default to text editor.
*/
focusedElementType?: FocusedElementType | "other";

/**
* A list of marks to check in the case of navigation map test otherwise undefined
*/
Expand Down
6 changes: 6 additions & 0 deletions packages/cursorless-engine/src/testCaseRecorder/TestCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
extractTargetedMarks,
ExtraSnapshotField,
Fallback,
FocusedElementType,
marksToPlainObject,
PartialTargetDescriptor,
PlainSpyIDERecordedValues,
Expand Down Expand Up @@ -43,6 +44,7 @@ export class TestCase {

constructor(
command: CommandLatest,
private focusedElementType: FocusedElementType | undefined,
private hatTokenMap: ReadOnlyHatMap,
private storedTargets: StoredTargetMap,
private spyIde: SpyIDE,
Expand Down Expand Up @@ -138,6 +140,10 @@ export class TestCase {
}
const fixture: EnforceUndefined<TestCaseFixture> = {
languageId: this.languageId,
focusedElementType:
this.focusedElementType !== "textEditor"
? this.focusedElementType ?? "other"
: undefined,
postEditorOpenSleepTimeMs: undefined,
postCommandSleepTimeMs: undefined,
command: this.command,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
CommandComplete,
CommandLatest,
CommandResponse,
CommandServerApi,
DecoratedSymbolMark,
DEFAULT_TEXT_EDITOR_OPTIONS_FOR_TEST,
extractTargetedMarks,
Expand Down Expand Up @@ -64,6 +65,7 @@ export class TestCaseRecorder {
private spokenFormGenerator = new SpokenFormGenerator(defaultSpokenFormMap);

constructor(
private commandServerApi: CommandServerApi | null,
private hatTokenMap: HatTokenMap,
private storedTargets: StoredTargetMap,
) {
Expand Down Expand Up @@ -293,6 +295,7 @@ export class TestCaseRecorder {
? spokenForm.spokenForms[0]
: command.spokenForm,
},
this.commandServerApi?.getFocusedElementType(),
hatTokenMap,
this.storedTargets,
this.spyIde,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
languageId: plaintext
focusedElementType: other
command:
version: 7
spokenForm: bring fine
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
languageId: plaintext
focusedElementType: terminal
command:
version: 7
spokenForm: bring fine
action:
name: replaceWithTarget
source:
type: primitive
mark: {type: decoratedSymbol, symbolColor: default, character: f}
destination: {type: implicit}
usePrePhraseSnapshot: true
initialState:
documentContents: foo
selections:
- anchor: {line: 0, character: 3}
active: {line: 0, character: 3}
marks:
default.f:
start: {line: 0, character: 0}
end: {line: 0, character: 3}
finalState:
documentContents: foo
selections:
- anchor: {line: 0, character: 3}
active: {line: 0, character: 3}
fallback:
action: insert
modifiers: []
text: foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
languageId: plaintext
focusedElementType: terminal
command:
version: 7
spokenForm: chuck fine
action:
name: remove
target:
type: primitive
mark: {type: decoratedSymbol, symbolColor: default, character: f}
usePrePhraseSnapshot: true
initialState:
documentContents: foo
selections:
- anchor: {line: 0, character: 3}
active: {line: 0, character: 3}
marks:
default.f:
start: {line: 0, character: 0}
end: {line: 0, character: 3}
finalState:
documentContents: ""
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
languageId: plaintext
focusedElementType: other
command:
version: 7
spokenForm: chuck fine
action:
name: remove
target:
type: primitive
mark: {type: decoratedSymbol, symbolColor: default, character: f}
usePrePhraseSnapshot: true
initialState:
documentContents: foo
selections:
- anchor: {line: 0, character: 3}
active: {line: 0, character: 3}
marks:
default.f:
start: {line: 0, character: 0}
end: {line: 0, character: 3}
finalState:
documentContents: ""
selections:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
languageId: plaintext
focusedElementType: other
command:
version: 7
spokenForm: move fine
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
languageId: plaintext
focusedElementType: other
command:
version: 7
spokenForm: take this
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
languageId: plaintext
focusedElementType: other
command:
version: 7
spokenForm: take token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ async function runTest(file: string, spyIde: SpyIDE) {
}

commandServerApi.setFocusedElementType(
fixture.fallback == null ? "textEditor" : undefined,
fixture.focusedElementType === "other"
? undefined
: fixture.focusedElementType ?? "textEditor",
);

// Ensure that the expected hats are present
Expand Down
6 changes: 5 additions & 1 deletion packages/cursorless-vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ export async function activate(
new CommandHistory(normalizedIde, commandServerApi, fileSystem),
);

const testCaseRecorder = new TestCaseRecorder(hatTokenMap, storedTargets);
const testCaseRecorder = new TestCaseRecorder(
commandServerApi,
hatTokenMap,
storedTargets,
);
addCommandRunnerDecorator(testCaseRecorder);

const statusBarItem = StatusBarItem.create("cursorless.showQuickPick");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function transformPackageJson(
json.version = `${major}.${minor}.${commitCount}`;
} else {
const gitSha = (await runCommand("git rev-parse --short HEAD")).trim();
json.version = `${json.version}-${gitSha}`;
// json.version = `${json.version}-${gitSha}`;
}

return json;
Expand Down

0 comments on commit 300511c

Please sign in to comment.