import { describe, expect, it } from "vitest"; import { diffLines } from "../src/diff.ts"; import { html, raw } from "../src/html.ts"; import { renderMarkdown } from "../src/markdown.ts"; const md = (s: string) => renderMarkdown(s, { noteHref: (n) => `/go?name=${encodeURIComponent(n)}`, imageSrc: (f) => `/attachments/${f}` }); describe("diff", () => { it("marks added and removed lines and folds the rest", () => { const before = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"].join("\n"); const after = ["a", "b", "c", "d", "e", "F", "g", "h", "i", "j"].join("\n"); const d = diffLines(before, after, 1); expect(d).toEqual([ { kind: "skip", count: 4 }, { kind: "same", text: "e" }, { kind: "remove", text: "f" }, { kind: "add", text: "F" }, { kind: "same", text: "g" }, { kind: "skip", count: 3 }, ]); }); it("shows a new note as all added", () => { expect(diffLines("", "x\ny")).toEqual([ { kind: "add", text: "x" }, { kind: "add", text: "y" }, ]); }); }); describe("html", () => { it("escapes values but not nested html", () => { expect(html`
${""}${html`${"&"}`}${raw("
")}
<b>&