mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-09-24 15:49:09 +00:00
56 lines
1.9 KiB
JavaScript
56 lines
1.9 KiB
JavaScript
"use strict";
|
|
|
|
const assert = require("node:assert/strict");
|
|
const test = require("node:test");
|
|
|
|
const {
|
|
PATCHES,
|
|
patchXtermSource,
|
|
sameLengthExpression,
|
|
} = require("./patch-xterm-macos-column-selection.cjs");
|
|
|
|
test("patches both distributed bundles without shifting source-map offsets", () => {
|
|
for (const patch of PATCHES.filter((entry) => entry.preserveLength)) {
|
|
const input = `before:${patch.original}:after`;
|
|
const result = patchXtermSource(input, patch);
|
|
assert.equal(result.changed, true);
|
|
assert.equal(result.source.length, input.length);
|
|
assert.equal(result.source.includes(patch.original), false);
|
|
assert.equal(
|
|
result.source.includes(sameLengthExpression(patch.replacement, patch.original.length)),
|
|
true,
|
|
);
|
|
}
|
|
});
|
|
|
|
test("patches readable xterm sources and source-map content", () => {
|
|
for (const patch of PATCHES.filter((entry) => !entry.preserveLength)) {
|
|
const result = patchXtermSource(`before:${patch.original}:after`, patch);
|
|
assert.equal(result.changed, true);
|
|
assert.equal(result.source, `before:${patch.replacement}:after`);
|
|
}
|
|
});
|
|
|
|
test("is idempotent and fails closed on an unknown package shape", () => {
|
|
for (const patch of PATCHES) {
|
|
const replacement = patch.preserveLength
|
|
? sameLengthExpression(patch.replacement, patch.original.length)
|
|
: patch.replacement;
|
|
assert.deepEqual(patchXtermSource(`before:${replacement}:after`, patch), {
|
|
source: `before:${replacement}:after`,
|
|
changed: false,
|
|
});
|
|
assert.throws(
|
|
() => patchXtermSource("unrecognized source", patch),
|
|
/expected exactly one original or patched selection predicate/,
|
|
);
|
|
}
|
|
});
|
|
|
|
test("fails closed when a generated-bundle replacement would shift offsets", () => {
|
|
assert.throws(
|
|
() => sameLengthExpression("replacement is longer", 4),
|
|
/replacement expression is too long/,
|
|
);
|
|
});
|