Spaces:
Running
Running
Download citations.test.mjs from iankamar/fieldnotes-rag: direct link, hf CLI and curl.
- Browser
- Download file 1.04 kB
-
https://huggingface.co/spaces/iankamar/fieldnotes-rag/resolve/main/citations.test.mjs
- Command line
-
hf download hf://spaces/iankamar/fieldnotes-rag/citations.test.mjs
-
curl -L -o citations.test.mjs https://huggingface.co/spaces/iankamar/fieldnotes-rag/resolve/main/citations.test.mjs
1.04 kB
| 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, | |
| ); | |
| }); | |