diff options
Diffstat (limited to 'desktop/assistant/test_ops.js')
| -rw-r--r-- | desktop/assistant/test_ops.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/desktop/assistant/test_ops.js b/desktop/assistant/test_ops.js new file mode 100644 index 0000000..6d53376 --- /dev/null +++ b/desktop/assistant/test_ops.js @@ -0,0 +1,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 desktop/assistant/test_ops.js +// Ops.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 + "/Ops.js", "utf8") + .replace(/^\.pragma library$/m, ""); +const O = new Function(src + "\nreturn { offered, COMPRESS };")(); + +const f = (name, kind) => ({ path: "/x/" + name, name, kind }); +const labels = files => O.offered(files).map(o => o.label); + +assert.deepStrictEqual(labels([f("a.pdf", "pdf")]), ["To .md", "To images", "Compress…"]); +assert.deepStrictEqual(labels([f("a.pdf", "pdf"), f("b.pdf", "pdf")]), + ["To .md", "To images", "Merge", "Compress…"]); +assert.deepStrictEqual(labels([f("a.pdf", "pdf"), f("p.png", "image")]), ["Compress…"]); +// An image's own format is not offered. +assert.deepStrictEqual(labels([f("p.png", "image")]), ["To JPEG", "To WebP", "Resize 50%", "Compress…"]); +assert.deepStrictEqual(labels([f("p.JPG", "image")]), ["To PNG", "To WebP", "Resize 50%", "Compress…"]); +// Mixed formats: offered while any file would change. +assert.deepStrictEqual(labels([f("p.png", "image"), f("q.jpg", "image")]), + ["To PNG", "To JPEG", "To WebP", "Resize 50%", "Compress…"]); +assert.deepStrictEqual(labels([f("c.mp4", "video")]), + ["Extract audio", "To WebM", "To GIF", "Trackcrop", "Compress…"]); +assert.deepStrictEqual(labels([f("c.mkv", "video")]), + ["Extract audio", "To MP4", "To WebM", "To GIF", "Trackcrop", "Compress…"]); +assert.deepStrictEqual(labels([f("b.tar.gz", "archive")]), ["Extract", "Compress…"]); +assert.deepStrictEqual(labels([f("n.txt", "text")]), ["Compress…"]); +assert.deepStrictEqual(labels([]), []); +assert.deepStrictEqual(O.COMPRESS.map(c => c.op), ["zip", "tgz", "txz", "tbz2"]); + +console.log("ok"); |
