Skip to content

Commit

Permalink
fix: validate keymap props
Browse files Browse the repository at this point in the history
  • Loading branch information
ueokande committed Feb 20, 2024
1 parent a4ea0a2 commit 41ef719
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/background/settings/Validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class Validator {
});

const keymapEntries = settings.keymaps?.entries() || [];
keymapEntries.forEach(([key, { type, ...props }]) => {
keymapEntries.forEach(([key, { type, props }]) => {
const op = this.operatorRegistory.getOperator(type);
if (typeof op === "undefined") {
throw new Error("Unknown keymap: " + type);
Expand Down
10 changes: 5 additions & 5 deletions test/background/settings/Validator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ describe("Validator", () => {
sut.validate({});
sut.validate({
keymaps: new Keymaps({
d: { type: "tabs.close" },
D: { type: "tabs.close", select: "left" },
zd: { type: "tabs.duplicate" },
d: { type: "tabs.close", props: {} },
D: { type: "tabs.close", props: { select: "left" } },
zd: { type: "tabs.duplicate", props: {} },
}),
search: new Search("google", {
google: "https://google.com/search?q={}",
Expand Down Expand Up @@ -65,15 +65,15 @@ describe("Validator", () => {
expect(() => {
sut.validate({
keymaps: new Keymaps({
d: { type: "harakiri" },
d: { type: "harakiri", props: {} },
}),
});
}).toThrowError("Unknown keymap: harakiri");

expect(() => {
sut.validate({
keymaps: new Keymaps({
D: { type: "tabs.close", force: "1" },
D: { type: "tabs.close", props: { force: "1" }} ,

Check failure on line 76 in test/background/settings/Validator.test.ts

View workflow job for this annotation

GitHub Actions / Build

Replace `}·` with `·}`
}),
});
}).toThrowError(
Expand Down
30 changes: 15 additions & 15 deletions test/shared/Keymaps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,44 @@ describe("Keymaps", () => {
describe("#combine", () => {
it("returns combined keymaps", () => {
const keymaps1 = new Keymaps({
k: { type: "scroll.vertically", count: -1 },
j: { type: "scroll.vertically", count: 1 },
k: { type: "scroll.vertically", props: { count: -1 } },
j: { type: "scroll.vertically", props: { count: 1 } },
});
const keymap2 = new Keymaps({
n: { type: "find.next" },
N: { type: "find.prev" },
n: { type: "find.next", props: {} },
N: { type: "find.prev", props: {} },
});
const combined = keymaps1.combine(keymap2);

const entries = combined
.entries()
.sort(([name1], [name2]) => name1.localeCompare(name2));
expect(entries).toEqual([
["j", { type: "scroll.vertically", count: 1 }],
["k", { type: "scroll.vertically", count: -1 }],
["n", { type: "find.next" }],
["N", { type: "find.prev" }],
["j", { type: "scroll.vertically", props: { count: 1 } }],
["k", { type: "scroll.vertically", props: { count: -1 } }],
["n", { type: "find.next", props: {} }],
["N", { type: "find.prev", props: {} }],
]);
});

it("overrides current keymaps", () => {
const keymaps1 = new Keymaps({
k: { type: "scroll.vertically", count: -1 },
j: { type: "scroll.vertically", count: 1 },
k: { type: "scroll.vertically", props: { count: -1 } },
j: { type: "scroll.vertically", props: { count: 1 } },
});
const keymap2 = new Keymaps({
n: { type: "find.next" },
j: { type: "find.prev" },
n: { type: "find.next", props: {} },
j: { type: "find.prev", props: {} },
});
const combined = keymaps1.combine(keymap2);

const entries = combined
.entries()
.sort(([name1], [name2]) => name1.localeCompare(name2));
expect(entries).toEqual([
["j", { type: "find.prev" }],
["k", { type: "scroll.vertically", count: -1 }],
["n", { type: "find.next" }],
["j", { type: "find.prev", props: {} }],
["k", { type: "scroll.vertically", props: { count: -1 } }],
["n", { type: "find.next", props: {} }],
]);
});
});
Expand Down

0 comments on commit 41ef719

Please # to comment.