testCommentChangeMergesWithCodeChange

tcmts.cli.test.e2e.merge.testCommentChangeMergesWithCodeChange · #gagirreq · term

One side changes a definition's doc, the other its code: the merge keeps both, the doc merged into the new code as text, rather than dropping the doc change.

import { okIn, 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 testCommentChangeMergesWithCodeChange = () => {
  const dir = tempDir("merge comment and code");
  const tcm = (...args: string[]) => okIn(dir, ...args);
  const update = (code: string) => {
    fs.writeFileSync(path.join(dir, "scratch.ts"), `// tcm: namespace lib\n${code}\n`);
    tcm("update");
  };
  tcm("init");
  update(`/** Adds one. */\nexport const f = (x: number): number =>\n  // the step\n  x + 1;`);
  tcm("branch", "s");
  tcm("switch", "s");
  update(`/** Adds one to x. */\nexport const f = (x: number): number =>\n  // the step\n  x + 1;`);
  tcm("switch", "main");
  update(`/** Adds one. */\nexport const f = (x: number): number =>\n  // the step\n  x + 2;`);
  tcm("switch", "s");
  const merged = tcm("merge", "main");
  assert.match(merged, /merged as text lib\.f/);
  assert.doesNotMatch(merged, /dropped/);
  assert.match(tcm("view", "lib.f"), /Adds one to x[\s\S]*x \+ 2/);
}

uses