// Copyright (C) 2026 Danilo M. // // 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), ["Win", "SHIFT"]); assert.deepStrictEqual(B.mods(13), ["CTRL", "ALT", "SHIFT"]); assert.strictEqual(B.keys({ modmask: 69, key: "F1" }), "Win + CTRL + SHIFT + F1"); assert.strictEqual(B.keys({ modmask: 0, key: "XF86AudioMute" }), "Mute"); assert.strictEqual(B.keys({ modmask: 64, key: "mouse:272" }), "Win + LMB"); assert.strictEqual(B.keys({ modmask: 0, key: "F5" }), "F5"); // A key named like an Object.prototype member is not renamed. assert.strictEqual(B.keys({ modmask: 0, key: "constructor" }), "constructor"); 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: "Win + w", label: "Browser" }, { keys: "Win + e", label: "Files" }, ] }, { name: "Media", rows: [{ keys: "Mute", label: "Mute" }] }, { name: "Other", rows: [{ keys: "ALT + x", label: "No colon here" }] }, { name: "Undescribed", rows: [{ keys: "Win + s", label: "no description" }] }, ]); // A group name matching an Object.prototype property must not resolve to // the inherited value instead of creating a new group. assert.deepStrictEqual(B.group([ { modmask: 64, key: "z", description: "toString: Weird" }, ]), [{ name: "toString", rows: [{ keys: "Win + z", label: "Weird" }] }]); console.log("ok");