testRenamedSignature

tcmts.store.test.testRenamedSignature · #g3ejamgw · term

A signature names types and values by their new names, but not keys, parameters, members or string literals.

import { renamedSignature } from "#codebase/tcmts/store";
import assert from "node:assert/strict";

export const testRenamedSignature = () => {
  const to = new Map([
    ["Shape", "Figure"],
    ["Store", "Db"],
  ]);
  assert.equal(
    renamedSignature("(q: Shape, d: Shape) => Shape | undefined", to),
    "(q: Figure, d: Figure) => Figure | undefined",
  );
  assert.equal(renamedSignature("typeof Store", to), "typeof Db");
  assert.equal(
    renamedSignature("Promise<Map<string, Shape[]>>", to),
    "Promise<Map<string, Figure[]>>",
  );
  assert.equal(
    renamedSignature("{ Shape: Shape; Store?: Store; Shape(): Shape; }", to),
    "{ Shape: Figure; Store?: Db; Shape(): Figure; }",
  );
  assert.equal(
    renamedSignature("(Shape: number, ...Store: Shape[]) => void", to),
    "(Shape: number, ...Store: Figure[]) => void",
  );
  assert.equal(
    renamedSignature('"Shape" | `a Shape` | lib.Shape', to),
    '"Shape" | `a Shape` | lib.Shape',
  );
  assert.equal(
    renamedSignature("T extends Shape ? Shape : Store", to),
    "T extends Figure ? Figure : Db",
  );
  assert.equal(
    renamedSignature("(x: Shapes) => MyShape", to),
    "(x: Shapes) => MyShape",
    "whole words only",
  );
  assert.equal(renamedSignature("(x: Shape) => void", new Map()), "(x: Shape) => void");
}

uses