Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { ghosttyKeyForCode, ghosttyUnshiftedCodepoint } from "./keyCodes";
4
5describe("ghosttyKeyForCode", () => {
6 it("keeps the tail of the pinned Ghostty key enum in order", () => {
7 expect(ghosttyKeyForCode("F25")).toBe(ghosttyKeyForCode("F24") + 1);
8 expect(ghosttyKeyForCode("PrintScreen")).toBe(ghosttyKeyForCode("FnLock") + 1);
9 expect(ghosttyKeyForCode("Pause")).toBe(ghosttyKeyForCode("ScrollLock") + 1);
10 expect(ghosttyKeyForCode("Paste")).toBe(ghosttyKeyForCode("Cut") + 1);
11 });
12});
13
14describe("ghosttyUnshiftedCodepoint", () => {
15 it("provides the logical base character for Kitty keyboard encoding", () => {
16 expect(ghosttyUnshiftedCodepoint({ code: "KeyC", key: "c", shiftKey: false })).toBe(
17 "c".codePointAt(0),
18 );
19 expect(ghosttyUnshiftedCodepoint({ code: "KeyC", key: "C", shiftKey: true })).toBe(
20 "c".codePointAt(0),
21 );
22 expect(ghosttyUnshiftedCodepoint({ code: "Digit1", key: "!", shiftKey: true })).toBe(
23 "1".codePointAt(0),
24 );
25 expect(ghosttyUnshiftedCodepoint({ code: "Slash", key: "?", shiftKey: true })).toBe(
26 "/".codePointAt(0),
27 );
28 expect(ghosttyUnshiftedCodepoint({ code: "Digit1", key: "&", shiftKey: false })).toBe(
29 "&".codePointAt(0),
30 );
31 expect(ghosttyUnshiftedCodepoint({ code: "Enter", key: "Enter", shiftKey: false })).toBe(0);
32 });
33
34 it("reports unknown instead of the shifted character without layout data", () => {
35 expect(ghosttyUnshiftedCodepoint({ code: "Digit7", key: "/", shiftKey: true })).toBe(0);
36 expect(ghosttyUnshiftedCodepoint({ code: "KeyD", key: "Д", shiftKey: true })).toBe(
37 "д".codePointAt(0),
38 );
39 });
40
41 it("prefers the active browser layout over US physical key positions", () => {
42 const layoutMap = new Map([
43 ["Digit1", "&"],
44 ["KeyC", "j"],
45 ]);
46 expect(ghosttyUnshiftedCodepoint({ code: "Digit1", key: "1", shiftKey: true }, layoutMap)).toBe(
47 "&".codePointAt(0),
48 );
49 expect(ghosttyUnshiftedCodepoint({ code: "KeyC", key: "J", shiftKey: true }, layoutMap)).toBe(
50 "j".codePointAt(0),
51 );
52 });
53});