testApplyPatch
A patch's edits apply where their text is, once each unless every one is asked for; else nothing changes.
import { applyPatch } from "#codebase/tcmts/cli/main"; import assert from "node:assert/strict"; export const testApplyPatch = () => { assert.deepEqual(applyPatch("a + b", [{ old: "b", new: "c" }]), { text: "a + c" }); assert.deepEqual(applyPatch("x = 1; y = 1", [{ old: "1", new: "2" }], true), { text: "x = 2; y = 2", }); assert.match( (applyPatch("x = 1; y = 1", [{ old: "1", new: "2" }]) as { problem: string }).problem, /found 2 times/, ); assert.match( (applyPatch("x", [{ old: "z", new: "y" }]) as { problem: string }).problem, /not found/, ); // `$&` in the new text is text, not a pattern assert.deepEqual(applyPatch("a", [{ old: "a", new: "$&$&" }]), { text: "$&$&" }); }