testUpgradeMap

tcmts.cli.libraries.test.testUpgradeMap · #syxvr5pm · term

an upgrade replaces each definition by the one at its name in the new version; one gone from it entirely is gone

import { upgradeMap } from "#codebase/tcmts/cli/libraries";
import assert from "node:assert/strict";

export const testUpgradeMap = () => {
  const before = [
    { path: "area", hash: "a1", kind: "term" as const },
    { path: "same", hash: "s", kind: "term" as const },
    { path: "moved", hash: "m", kind: "term" as const },
    { path: "dropped", hash: "d", kind: "term" as const },
    { path: "Shape", hash: "t1", kind: "type" as const },
  ];
  const after = [
    { path: "area", hash: "a2", kind: "term" as const },
    { path: "same", hash: "s", kind: "term" as const },
    { path: "elsewhere", hash: "m", kind: "term" as const },
    { path: "cube", hash: "c", kind: "term" as const },
    // (a value of the type's name isn't what replaces the type)
    { path: "Shape", hash: "v", kind: "term" as const },
  ];
  const m = upgradeMap(before, after);
  assert.deepEqual([...m.replaced], [["a1", "a2"]]);
  // (`elsewhere`, `cube` and the value `Shape` are new names)
  assert.equal(m.added, 2);
  assert.deepEqual([...m.gone].sort(), ["d", "t1"]);
}

uses