testCodebasePagesStartPastALoneNamespace

tcmts.registry.test.testCodebasePagesStartPastALoneNamespace · #caoaxjw5 · term

import { codebaseRoot } from "#codebase/tcmts/registry";
import type { NameRow } from "#codebase/tcmts/store";

export const testCodebasePagesStartPastALoneNamespace = () => {
  const rows = (...paths: string[]): NameRow[] =>
    paths.map((path) => ({ path, hash: "h", kind: "term" }));
  const at = "plc_a._codebases.tcm";
  const cases: [NameRow[], string][] = [
    // tcm's: everything under tcmts, its README there
    [rows(`${at}.tcmts.README`, `${at}.tcmts.cli.run`, `${at}.tcmts.core.hash`), `${at}.tcmts`],
    // deeper still, while each level holds one namespace alone
    [rows(`${at}.a.b.x`, `${at}.a.b.y`), `${at}.a.b`],
    // a README (or any definition) at the top: the top
    [rows(`${at}.README`, `${at}.app.main`), at],
    // two namespaces: the top
    [rows(`${at}.app.main`, `${at}.lib.x`), at],
    // nothing yet
    [[], at],
  ];
  for (const [r, want] of cases) {
    const got = codebaseRoot(r, at);
    if (got !== want) throw new Error(`${r.map((x) => x.path).join(", ")}: ${got}, not ${want}`);
  }
}

uses