import test from "node:test"; import assert from "node:assert/strict"; import { citationParts } from "./citations.mjs"; test("valid citations point to the actual source anchor", () => assert.deepEqual(citationParts("A fact [2]", 2), [ { text: "A fact " }, { text: "[2]", href: "#source-2" }, ])); test("invalid and zero citation IDs remain plain text", () => assert.deepEqual(citationParts("[0] [99]", 2), [ { text: "[0]" }, { text: " " }, { text: "[99]" }, ])); test("brief citations use separate source namespaces", () => assert.equal( citationParts("[1]", 1, "brief-2-source")[0].href, "#brief-2-source-1", )); test("markup and user text are never converted to HTML", () => assert.equal( citationParts(" [1]", 1)[0].text, " ", )); test("citation splitting preserves complete answer text", () => { const s = "One [1].\nTwo [2]."; assert.equal( citationParts(s, 2) .map((p) => p.text) .join(""), s, ); });