Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
whitphx committed Jan 10, 2024
1 parent 40e915a commit a8d0ace
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/test/suite/commands/paredit.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import assert from "assert";
import * as vscode from "vscode";
import * as sinon from "sinon";
import { Selection, TextEditor } from "vscode";
import { EmacsEmulator } from "../../../emulator";
import { KillRing } from "../../../kill-yank/kill-ring";
Expand All @@ -11,6 +13,7 @@ import {
clearTextEditor,
assertSelectionsEqual,
} from "../utils";
import { Configuration } from "../../../configuration/configuration";

suite("paredit commands", () => {
let activeTextEditor: TextEditor;
Expand Down Expand Up @@ -64,6 +67,51 @@ suite("paredit commands", () => {
});
});

suite("Parentheses config", () => {
let activeTextEditor: TextEditor;
let emulator: EmacsEmulator;
let getConfigurationStub: sinon.SinonStub;

setup(async () => {
const initialText = "<<>>";

activeTextEditor = await setupWorkspace(initialText);
emulator = new EmacsEmulator(activeTextEditor);

getConfigurationStub = sinon.stub(vscode.workspace, "getConfiguration");
});
teardown(async () => {
getConfigurationStub.restore();
Configuration.reload();
await cleanUpWorkspace();
});

function mockPareditConfig(parentheses: Record<string, string>) {
getConfigurationStub.returns({
paredit: {
parentheses,
},
});
Configuration.reload();
}

test("forwardSexp", async () => {
mockPareditConfig({ "(": ")" });
setEmptyCursors(activeTextEditor, [0, 1]);
await emulator.runCommand("paredit.forwardSexp");
assertCursorsEqual(activeTextEditor, [0, 4]);
await emulator.runCommand("paredit.forwardSexp");
assertCursorsEqual(activeTextEditor, [0, 4]);

mockPareditConfig({ "<": ">" });
setEmptyCursors(activeTextEditor, [0, 1]);
await emulator.runCommand("paredit.forwardSexp");
assertCursorsEqual(activeTextEditor, [0, 3]);
await emulator.runCommand("paredit.forwardSexp");
assertCursorsEqual(activeTextEditor, [0, 3]);
});
});

suite("paredit.kill-sexp", () => {
const initialText = `(
(
Expand Down

0 comments on commit a8d0ace

Please sign in to comment.