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
|
import Keymaps from "../../../src/shared/settings/Keymaps";
describe("Keymaps", () => {
describe("#valueOf", () => {
it("returns empty object by empty settings", () => {
const keymaps = Keymaps.fromJSON({}).toJSON();
expect(keymaps).toEqual({});
});
it("returns keymaps by valid settings", () => {
const keymaps = Keymaps.fromJSON({
k: { type: "scroll.vertically", count: -1 },
j: { type: "scroll.vertically", count: 1 },
}).toJSON();
expect(keymaps["k"]).toEqual({
type: "scroll.vertically",
count: -1,
});
expect(keymaps["j"]).toEqual({
type: "scroll.vertically",
count: 1,
});
});
it("throws a TypeError by invalid settings", () => {
expect(() =>
Keymaps.fromJSON({
k: { type: "invalid.operation" },
})
).toThrow(TypeError);
});
});
describe("#combine", () => {
it("returns combined keymaps", () => {
const keymaps = Keymaps.fromJSON({
k: { type: "scroll.vertically", count: -1 },
j: { type: "scroll.vertically", count: 1 },
}).combine(
Keymaps.fromJSON({
n: { type: "find.next" },
N: { type: "find.prev" },
})
);
const entries = keymaps
.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" }],
]);
});
it("overrides current keymaps", () => {
const keymaps = Keymaps.fromJSON({
k: { type: "scroll.vertically", count: -1 },
j: { type: "scroll.vertically", count: 1 },
}).combine(
Keymaps.fromJSON({
n: { type: "find.next" },
j: { type: "find.prev" },
})
);
const entries = keymaps
.entries()
.sort(([name1], [name2]) => name1.localeCompare(name2));
expect(entries).toEqual([
["j", { type: "find.prev" }],
["k", { type: "scroll.vertically", count: -1 }],
["n", { type: "find.next" }],
]);
});
});
});
|