testEntriesByHashOrDistance

tcmts.cli.test.e2e.history.testEntriesByHashOrDistance · #md3abx36 · term

Entries by hash or by distance; reset adds an entry rather than rewriting.

import { tempDir } from "#codebase/tcmts/cli/test/e2e/harness";
import { codebase } from "#codebase/tcmts/cli/test/e2e/history";
import assert from "node:assert/strict";

export const testEntriesByHashOrDistance = () => {
  const root = tempDir("history");
  const a = codebase(root, "e");
  a.tcm("init");
  a.write(`export const v = 1;\n`);
  a.tcm("add");
  a.write(`export const v = 2;\n`);
  a.tcm("update");
  assert.match(
    a.tcm("history"),
    /^#\w{8} +0 .* update v\n {4}v +#\w{8} → #\w{8}\n#\w{8} +1 .* add v\n {4}v +\+ #\w{8}/,
  );
  assert.match(a.tcm("diff", "1"), /changes since #\w{8}[\s\S]*edited\s+~ v/);
  const first = a.entries()[1]!;
  // by hash, # or not
  assert.match(a.tcm("diff", first), /changes since #\w{8}/);
  assert.match(a.tcm("reset", `#${first}`), /names as of #\w{8} \(1 added, 1 removed\)/);
  assert.equal(a.tcm("run", "v").trim(), "1");
  assert.equal(a.entries().length, 3, "the reset is an entry of its own");
  assert.match(a.tcm("history", "1"), /reset #\w{8}/);
  assert.throws(() => a.tcm("reset", "9"), /isn't 9 entries long/);
}

uses