testNotFoundSaysWhatWasMeant

tcmts.cli.help.testNotFoundSaysWhatWasMeant · #zuexbon5 · term

import { notFound } from "#codebase/tcmts/cli/help";
import assert from "node:assert/strict";

export const testNotFoundSaysWhatWasMeant = () => {
  const paths = ["lib.math.square", "lib.math.cube", "lib.util.sort", "tcmts.cli.vitest.resultKey"];
  // the same name, in another namespace
  assert.match(
    notFound(paths, "tcmts.cli.testing.resultKey"),
    /not found; did you mean tcmts\.cli\.vitest\.resultKey\?/,
  );
  // a few letters off
  assert.match(notFound(paths, "lib.math.sqare"), /did you mean lib\.math\.square\?/);
  assert.match(notFound(paths, "Lib.Util.Sort"), /did you mean lib\.util\.sort\?/);
  // only the closest
  assert.equal(
    notFound(paths, "lib.math.cueb"),
    "'lib.math.cueb' not found; did you mean lib.math.cube?",
  );
  // a namespace says what it holds
  assert.match(
    notFound(paths, "lib"),
    /'lib' is a namespace, not a definition: it holds math, util;/,
  );
  assert.equal(notFound(paths, "nothing.like.it"), "'nothing.like.it' not found");
}

uses