fix: file sizes from PowerShell, quoted mentions, dedupe and BOM
Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
1 parent
761a80004a
commit
1ed04fe9be
5 files changed
+339
-94
No files matched your search
@@ -26,8 +26,11 @@ test("validateMany enforces count limit", () => {
|
||||
assert.equal(validateMany(files.slice(0, 100)).ok, true);
|
||||
});
|
||||
|
||||
test("mention", () => {
|
||||
test("mention: bare path, or quoted when it has whitespace", () => {
|
||||
assert.equal(mention(" /a/b "), "@/a/b");
|
||||
assert.equal(mention("/a b/c"), '@"/a b/c"');
|
||||
assert.equal(mention("C:\\Moje pliki\\x.png"), '@"C:\\Moje pliki\\x.png"');
|
||||
assert.equal(mention("/a\tb"), '@"/a\tb"');
|
||||
assert.equal(mention(""), "");
|
||||
assert.equal(mention(5), "");
|
||||
});
|
||||
@@ -39,12 +42,19 @@ test("removeMention removes only the standalone token", () => {
|
||||
|
||||
test("mention and removeMention with a space and Polish letters in the path", () => {
|
||||
const path = "/home/zażółć/gęsia jaźń/ęą.png";
|
||||
assert.equal(mention(path), `@${path}`);
|
||||
assert.equal(removeMention(`zobacz @${path} proszę`, path), "zobacz proszę");
|
||||
assert.equal(removeMention(`@${path}`, path), "");
|
||||
assert.equal(mention(path), `@"${path}"`);
|
||||
assert.equal(removeMention(`zobacz @"${path}" proszę`, path), "zobacz proszę");
|
||||
assert.equal(removeMention(`@"${path}"`, path), "");
|
||||
});
|
||||
|
||||
test("removeMention leaves a mention glued to a Polish letter alone", () => {
|
||||
assert.equal(removeMention("@src/aę a", "src/a"), "@src/aę a");
|
||||
assert.equal(removeMention("ę@src/a", "src/a"), "ę@src/a");
|
||||
});
|
||||
|
||||
test("removeMention takes the quoted form and the bare form out", () => {
|
||||
assert.equal(removeMention('see @"/a b/ęą.png" now', "/a b/ęą.png"), "see now");
|
||||
assert.equal(removeMention('@"/a b/ęą.png"', "/a b/ęą.png"), "");
|
||||
assert.equal(removeMention("see @/a/ęą.png now", "/a/ęą.png"), "see now");
|
||||
assert.equal(removeMention('see @"/a b/c.png"x now', "/a b/c.png"), 'see @"/a b/c.png"x now');
|
||||
});
|
||||
+69
-14
@@ -1,45 +1,69 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import {
|
||||
clipboardScript, parseClipboardResult, pickerScript, parsePickerResult, staleFiles, supportsImages,
|
||||
clipboardScript, parseClipboardResult, pickerScript, parsePickerResult,
|
||||
sizeScript, parseSizeResult, staleFiles, supportsImages,
|
||||
} from "../mod/ovis-composer/clipboard.js";
|
||||
|
||||
const ok = (stdout) => ({ code: 0, stdout, stderr: "" });
|
||||
|
||||
test("clipboardScript: files first, then image, then NONE", () => {
|
||||
const s = clipboardScript("C:\out dir", "123");
|
||||
test("clipboardScript: files first (with sizes, directories apart), then image, then NONE", () => {
|
||||
const s = clipboardScript("C:\\out dir", "123");
|
||||
assert.ok(s.indexOf("GetFileDropList") >= 0);
|
||||
assert.ok(s.indexOf("GetFileDropList") < s.indexOf("GetImage"));
|
||||
assert.ok(s.includes("paste-123.png"));
|
||||
assert.ok(s.includes("FILES"));
|
||||
assert.ok(s.includes("DIR"));
|
||||
assert.ok(s.includes("Container"));
|
||||
assert.ok(s.includes(".Length"));
|
||||
assert.ok(s.includes("IMAGE"));
|
||||
assert.ok(s.includes("NONE"));
|
||||
assert.ok(s.includes("C:\out dir"));
|
||||
assert.ok(s.includes("C:\\out dir"));
|
||||
});
|
||||
|
||||
test("clipboardScript quotes a path with an apostrophe", () => {
|
||||
assert.ok(clipboardScript("C:\o'brien", "1").includes("C:\o''brien"));
|
||||
assert.ok(clipboardScript("C:\\o'brien", "1").includes("C:\\o''brien"));
|
||||
});
|
||||
|
||||
test("parseClipboardResult: image", () => {
|
||||
assert.deepEqual(parseClipboardResult(ok("IMAGE\tC:\data\paste-1.png\r\n")), {
|
||||
kind: "image", paths: ["C:\data\paste-1.png"],
|
||||
test("parseClipboardResult: image with its size", () => {
|
||||
assert.deepEqual(parseClipboardResult(ok("IMAGE\tC:\\data\\paste-1.png\t2048\r\n")), {
|
||||
kind: "image", files: [{ path: "C:\\data\\paste-1.png", bytes: 2048 }], dirs: [],
|
||||
});
|
||||
});
|
||||
|
||||
test("parseClipboardResult: files with spaces and Polish letters", () => {
|
||||
const out = "FILES\tC:\Moje pliki\zażółć gęślą.txt\r\nFILES\tD:\a b\c.png\r\n";
|
||||
test("parseClipboardResult: files with spaces and Polish letters, sizes", () => {
|
||||
const out = "FILES\tC:\\Moje pliki\\zażółć gęślą.txt\t10\r\nFILES\tD:\\a b\\c.png\t0\r\n";
|
||||
assert.deepEqual(parseClipboardResult(ok(out)), {
|
||||
kind: "files", paths: ["C:\Moje pliki\zażółć gęślą.txt", "D:\a b\c.png"],
|
||||
kind: "files",
|
||||
files: [{ path: "C:\\Moje pliki\\zażółć gęślą.txt", bytes: 10 }, { path: "D:\\a b\\c.png", bytes: 0 }],
|
||||
dirs: [],
|
||||
});
|
||||
});
|
||||
|
||||
test("parseClipboardResult: a file without a readable size has bytes null", () => {
|
||||
assert.deepEqual(parseClipboardResult(ok("FILES\tC:\\a.txt\t\r\nFILES\tC:\\b.txt\r\n")).files, [
|
||||
{ path: "C:\\a.txt", bytes: null }, { path: "C:\\b.txt", bytes: null },
|
||||
]);
|
||||
});
|
||||
|
||||
test("parseClipboardResult: directories are reported apart", () => {
|
||||
const r = parseClipboardResult(ok("DIR\tC:\\folder\r\nFILES\tC:\\a.txt\t5\r\n"));
|
||||
assert.equal(r.kind, "files");
|
||||
assert.deepEqual(r.dirs, ["C:\\folder"]);
|
||||
assert.deepEqual(parseClipboardResult(ok("DIR\tC:\\folder\r\n")), { kind: "dirs", dirs: ["C:\\folder"] });
|
||||
});
|
||||
|
||||
test("parseClipboardResult: NONE, empty, rubbish", () => {
|
||||
assert.deepEqual(parseClipboardResult(ok("NONE\r\n")), { kind: "none" });
|
||||
assert.deepEqual(parseClipboardResult(ok("")), { kind: "none" });
|
||||
assert.deepEqual(parseClipboardResult(ok("what\r\n")), { kind: "none" });
|
||||
});
|
||||
|
||||
test("parseClipboardResult: a BOM in front of the output is ignored", () => {
|
||||
assert.deepEqual(parseClipboardResult(ok("\uFEFFNONE\r\n")), { kind: "none" });
|
||||
assert.equal(parseClipboardResult(ok("\uFEFFIMAGE\tC:\\p.png\t1\r\n")).kind, "image");
|
||||
});
|
||||
|
||||
test("parseClipboardResult: a failed run is an error with stderr", () => {
|
||||
assert.deepEqual(parseClipboardResult({ code: 1, stdout: "", stderr: "boom\n" }), { kind: "error", message: "boom" });
|
||||
const r = parseClipboardResult({ code: 3, stdout: "", stderr: "" });
|
||||
@@ -48,21 +72,52 @@ test("parseClipboardResult: a failed run is an error with stderr", () => {
|
||||
assert.equal(parseClipboardResult(null).kind, "error");
|
||||
});
|
||||
|
||||
test("pickerScript: multiselect dialog, one path per line", () => {
|
||||
test("pickerScript: multiselect dialog, path and size per line", () => {
|
||||
const s = pickerScript();
|
||||
assert.ok(s.includes("OpenFileDialog"));
|
||||
assert.ok(s.includes("Multiselect"));
|
||||
assert.ok(s.includes("$true"));
|
||||
assert.ok(s.includes(".Length"));
|
||||
});
|
||||
|
||||
test("parsePickerResult: paths, cancelled -> []", () => {
|
||||
assert.deepEqual(parsePickerResult(ok("C:\a b\c.txt\r\nD:\d.png\r\n")), ["C:\a b\c.txt", "D:\d.png"]);
|
||||
test("parsePickerResult: path and bytes, cancelled -> []", () => {
|
||||
assert.deepEqual(parsePickerResult(ok("C:\\a b\\c.txt\t7\r\nD:\\d.png\t9\r\n")), [
|
||||
{ path: "C:\\a b\\c.txt", bytes: 7 }, { path: "D:\\d.png", bytes: 9 },
|
||||
]);
|
||||
assert.deepEqual(parsePickerResult(ok("\uFEFFC:\\a.txt\t\r\n")), [{ path: "C:\\a.txt", bytes: null }]);
|
||||
assert.deepEqual(parsePickerResult(ok("C:\\a.txt\r\n")), [{ path: "C:\\a.txt", bytes: null }]);
|
||||
assert.deepEqual(parsePickerResult(ok("")), []);
|
||||
assert.deepEqual(parsePickerResult(ok("\r\n")), []);
|
||||
assert.deepEqual(parsePickerResult({ code: 1, stdout: "x", stderr: "e" }), []);
|
||||
assert.deepEqual(parsePickerResult(null), []);
|
||||
});
|
||||
|
||||
test("sizeScript: one call for the whole batch, paths quoted", () => {
|
||||
const s = sizeScript(["C:\\a b\\it's.txt", "D:\\x.png"]);
|
||||
assert.ok(s.includes("'C:\\a b\\it''s.txt'"));
|
||||
assert.ok(s.includes("'D:\\x.png'"));
|
||||
assert.ok(s.includes("-LiteralPath"));
|
||||
assert.ok(s.includes("DIR"));
|
||||
assert.ok(s.includes("SIZE"));
|
||||
});
|
||||
|
||||
test("parseSizeResult: sizes, directories, missing, unknown sizes", () => {
|
||||
const out = "SIZE\tC:\\a b\\ż.txt\t12\r\nDIR\tC:\\folder\r\nMISSING\tC:\\gone\r\nSIZE\tC:\\c\t\r\n";
|
||||
assert.deepEqual(parseSizeResult(ok(out)), {
|
||||
files: [{ path: "C:\\a b\\ż.txt", bytes: 12 }, { path: "C:\\c", bytes: null }],
|
||||
dirs: ["C:\\folder"],
|
||||
missing: ["C:\\gone"],
|
||||
error: null,
|
||||
});
|
||||
});
|
||||
|
||||
test("parseSizeResult: a failed run fails closed", () => {
|
||||
const r = parseSizeResult({ code: 1, stdout: "", stderr: "nope\n" });
|
||||
assert.deepEqual([r.files, r.dirs, r.error], [[], [], "nope"]);
|
||||
assert.ok(parseSizeResult(null).error.length > 0);
|
||||
assert.equal(parseSizeResult(ok("\uFEFFSIZE\tC:\\a\t3\r\n")).files[0].bytes, 3);
|
||||
});
|
||||
|
||||
test("staleFiles: 6 days stay, 8 days go", () => {
|
||||
const now = 100 * 864e5;
|
||||
const entries = [
|
||||
|
||||
Reference in new issue
Block a user