testPatchLocationsNameTheDefinition
tcmts.cli.main.testPatchLocationsNameTheDefinition · #n2z4l6kp · term
import type { Codebase } from "#codebase/tcmts/cli/codebase";
import { patchLocations } from "#codebase/tcmts/cli/main";
import assert from "node:assert/strict";
export const testPatchLocationsNameTheDefinition = () => {
const text = `// tcm: namespace lib\nimport fs from "node:fs";\n\n/** two */\nexport const two = 2;\n\nexport function f(): number {\n return two + 1;\n}\n`;
// (no codebase: the line counts from the declaration)
const cb = { lookup: () => [], store: {}, lay: {} } as unknown as Codebase;
const rewrite = patchLocations(cb, "/x/patch-123.ts", text, ["lib.two", "lib.f"]);
assert.equal(
rewrite("/x/patch-123.ts:8:10 - error TS2322: nope"),
"lib.f:2:10 - error TS2322: nope",
);
assert.equal(rewrite("warning: patch-123.ts:5:1: hm"), "warning: lib.two:1:1: hm");
assert.equal(rewrite("elsewhere.ts:3:1"), "elsewhere.ts:3:1");
// coloured, and the file on its own
assert.equal(
rewrite("\x1b[96mpatch-123.ts\x1b[0m:\x1b[93m8\x1b[0m:\x1b[93m3\x1b[0m - error"),
"\x1b[96mlib.f:2:3\x1b[0m - error",
);
assert.equal(rewrite("patch-123.ts has problems"), "lib.two, lib.f has problems");
}
uses