testDeletedNameStillUsedIsKept

tcmts.cli.test.e2e.merge.testDeletedNameStillUsedIsKept · #lnh6ykff · term

A name one side removed, that the other side's new code uses, is kept: the merged code would otherwise use what nothing names.

import { okIn, tcmIn, tempDir } from "#codebase/tcmts/cli/test/e2e/harness";
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";

export const testDeletedNameStillUsedIsKept = () => {
  const dir = tempDir("merge kept");
  const tcm = (...args: string[]) => okIn(dir, ...args);
  const add = (code: string) => {
    fs.writeFileSync(path.join(dir, "scratch.ts"), `// tcm: namespace lib\n${code}\n`);
    tcm("add");
  };
  tcm("init");
  add(`export const helper = (x: number) => x + 1;`);
  tcm("branch", "b");
  tcm("rm", "lib.helper");
  tcm("switch", "b");
  add(`import { helper } from "#codebase/lib";\nexport const g = () => helper(1);`);
  tcm("switch", "main");

  const merged = tcmIn(dir, "merge", "b");
  assert.equal(merged.status, 0, merged.out);
  assert.match(
    merged.out,
    /kept lib\.helper \(deleted on one side, but the other's code uses it\)/,
  );
  assert.equal(tcm("run", "lib.g").trim(), "2");
  const todo = tcm("todo");
  assert.doesNotMatch(todo, /unnamed version/);
  assert.match(todo, /nothing to do/);
}

uses