diff options
Diffstat (limited to 'assistant/test_place.js')
| -rw-r--r-- | assistant/test_place.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/assistant/test_place.js b/assistant/test_place.js new file mode 100644 index 0000000..9f1376e --- /dev/null +++ b/assistant/test_place.js @@ -0,0 +1,32 @@ +// 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 assistant/test_place.js +// Place.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 + "/Place.js", "utf8") + .replace(/^\.pragma library$/m, ""); +const P = new Function(src + "\nreturn { at };")(); + +assert.deepStrictEqual(P.at("center", 1920, 1080, 360, 24), { x: 780, y: 360 }); +assert.deepStrictEqual(P.at("top", 1920, 1080, 360, 24), { x: 780, y: 24 }); +assert.deepStrictEqual(P.at("bottom", 1920, 1080, 360, 24), { x: 780, y: 696 }); +assert.deepStrictEqual(P.at("top-left", 1920, 1080, 360, 24), { x: 24, y: 24 }); +assert.deepStrictEqual(P.at("top-right", 1920, 1080, 360, 24), { x: 1536, y: 24 }); +assert.deepStrictEqual(P.at("bottom-left", 1920, 1080, 360, 24), { x: 24, y: 696 }); +assert.deepStrictEqual(P.at("bottom-right", 1920, 1080, 360, 24), { x: 1536, y: 696 }); +// An unknown position is the centre, not an error. +assert.deepStrictEqual(P.at("middle", 1920, 1080, 360, 24), { x: 780, y: 360 }); +console.log("ok"); |
