File size: 1,035 Bytes
9dd41f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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("<script>alert(1)</script> [1]", 1)[0].text,
    "<script>alert(1)</script> ",
  ));
test("citation splitting preserves complete answer text", () => {
  const s = "One [1].\nTwo [2].";
  assert.equal(
    citationParts(s, 2)
      .map((p) => p.text)
      .join(""),
    s,
  );
});