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
|
// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Run: node keybinds/test_binds.js
// Binds.js is a QML library, so its .pragma line is stripped before node
// evaluates it.
const fs = require("fs");
const assert = require("assert");
const src = fs.readFileSync(__dirname + "/Binds.js", "utf8")
.replace(/^\.pragma library$/m, "");
const B = new Function(src + "\nreturn { mods, keys, group };")();
assert.deepStrictEqual(B.mods(0), []);
assert.deepStrictEqual(B.mods(65), ["SUPER", "SHIFT"]);
assert.deepStrictEqual(B.mods(13), ["CTRL", "ALT", "SHIFT"]);
assert.strictEqual(B.keys({ modmask: 69, key: "F1" }), "SUPER + CTRL + SHIFT + F1");
assert.strictEqual(B.keys({ modmask: 0, key: "XF86AudioMute" }), "XF86AudioMute");
assert.deepStrictEqual(B.group([
{ modmask: 64, key: "s", description: "" },
{ modmask: 64, key: "w", description: "Apps: Browser" },
{ modmask: 0, key: "XF86AudioMute", description: "Media: Mute" },
{ modmask: 64, key: "e", description: "Apps: Files" },
{ modmask: 8, key: "x", description: "No colon here" },
]), [
{ name: "Apps", rows: [
{ keys: "SUPER + w", label: "Browser" },
{ keys: "SUPER + e", label: "Files" },
] },
{ name: "Media", rows: [{ keys: "XF86AudioMute", label: "Mute" }] },
{ name: "Other", rows: [{ keys: "ALT + x", label: "No colon here" }] },
{ name: "Undescribed", rows: [{ keys: "SUPER + s", label: "no description" }] },
]);
console.log("ok");
|