{"file":"src/engine/test/view.test.ts","version":7,"total":94,"from":1,"to":94,"lines":[{"n":1,"text":"// Projection: the line tree, tombstones, sibling priority, and long files.","atom":"a0","author":"init","version":0},{"n":2,"text":"","atom":"a0","author":"init","version":0},{"n":3,"text":"import assert from \"node:assert/strict\";","atom":"a0","author":"init","version":0},{"n":4,"text":"import { describe, it } from \"node:test\";","atom":"a0","author":"init","version":0},{"n":5,"text":"import { buildBase, conflicts, Graph, project, View } from \"../index.ts\";","atom":"a0","author":"init","version":0},{"n":6,"text":"import { lines, Repo } from \"./helpers.ts\";","atom":"a0","author":"init","version":0},{"n":7,"text":"","atom":"a0","author":"init","version":0},{"n":8,"text":"describe(\"View\", () => {","atom":"a0","author":"init","version":0},{"n":9,"text":"\tit(\"keeps deleted lines as tombstones in the full sequence\", () => {","atom":"a0","author":"init","version":0},{"n":10,"text":"\t\tconst repo = Repo.init({ \"f.txt\": lines(\"one\", \"two\", \"three\") });","atom":"a0","author":"init","version":0},{"n":11,"text":"\t\tconst del = repo.edit({ edits: [{ file: \"f.txt\", old: \"two\\n\", new: \"\" }] });","atom":"a0","author":"init","version":0},{"n":12,"text":"\t\tconst view = repo.view();","atom":"a0","author":"init","version":0},{"n":13,"text":"\t\tassert.deepEqual(","atom":"a0","author":"init","version":0},{"n":14,"text":"\t\t\tview.sequence(\"f.txt\").map((l) => [l.id, l.text, l.visible, l.deletedBy]),","atom":"a0","author":"init","version":0},{"n":15,"text":"\t\t\t[","atom":"a0","author":"init","version":0},{"n":16,"text":"\t\t\t\t[\"a0.0\", \"one\", true, []],","atom":"a0","author":"init","version":0},{"n":17,"text":"\t\t\t\t[\"a0.1\", \"two\", false, [del.id]],","atom":"a0","author":"init","version":0},{"n":18,"text":"\t\t\t\t[\"a0.2\", \"three\", true, []],","atom":"a0","author":"init","version":0},{"n":19,"text":"\t\t\t],","atom":"a0","author":"init","version":0},{"n":20,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":21,"text":"\t\tassert.deepEqual(","atom":"a0","author":"init","version":0},{"n":22,"text":"\t\t\tview.lines(\"f.txt\").map((l) => l.id),","atom":"a0","author":"init","version":0},{"n":23,"text":"\t\t\t[\"a0.0\", \"a0.2\"],","atom":"a0","author":"init","version":0},{"n":24,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":25,"text":"\t\tassert.equal(view.lineNumber(\"f.txt\", \"a0.2\"), 1);","atom":"a0","author":"init","version":0},{"n":26,"text":"\t\tassert.equal(view.lineNumber(\"f.txt\", \"a0.1\"), -1);","atom":"a0","author":"init","version":0},{"n":27,"text":"\t\tassert.equal(view.sequenceIndex(\"f.txt\", \"a0.1\"), 1);","atom":"a0","author":"init","version":0},{"n":28,"text":"\t\tassert.equal(view.text(\"f.txt\"), \"one\\nthree\\n\");","atom":"a0","author":"init","version":0},{"n":29,"text":"\t\tassert.equal(view.text(\"missing.txt\"), \"\");","atom":"a0","author":"init","version":0},{"n":30,"text":"\t\tassert.deepEqual(view.lines(\"missing.txt\"), []);","atom":"a0","author":"init","version":0},{"n":31,"text":"\t});","atom":"a0","author":"init","version":0},{"n":32,"text":"","atom":"a0","author":"init","version":0},{"n":33,"text":"\tit(\"orders siblings by descending priority: higher lamport first, then higher seq\", () => {","atom":"a0","author":"init","version":0},{"n":34,"text":"\t\tconst repo = Repo.init({ \"f.txt\": lines(\"top\", \"bottom\") });","atom":"a0","author":"init","version":0},{"n":35,"text":"\t\t// Three inserts after \"top\", all written against the base: same lamport, seq decides.","atom":"a0","author":"init","version":0},{"n":36,"text":"\t\tconst p = repo.edit({ edits: [{ file: \"f.txt\", start: 1, end: 1, lines: [\"p\"] }] }, [\"a0\"]);","atom":"a0","author":"init","version":0},{"n":37,"text":"\t\tconst q = repo.edit({ edits: [{ file: \"f.txt\", start: 1, end: 1, lines: [\"q\"] }] }, [\"a0\"]);","atom":"a0","author":"init","version":0},{"n":38,"text":"\t\tassert.equal(repo.text(\"f.txt\"), lines(\"top\", \"q\", \"p\", \"bottom\"));","atom":"a0","author":"init","version":0},{"n":39,"text":"\t\t// One written later, against a view with both: higher lamport, lands right after \"top\".","atom":"a0","author":"init","version":0},{"n":40,"text":"\t\tconst r = repo.edit({ edits: [{ file: \"f.txt\", start: 1, end: 1, lines: [\"r\"] }] });","atom":"a0","author":"init","version":0},{"n":41,"text":"\t\tassert.ok(repo.graph.lamport(r.id) > repo.graph.lamport(q.id));","atom":"a0","author":"init","version":0},{"n":42,"text":"\t\tassert.equal(repo.text(\"f.txt\"), lines(\"top\", \"r\", \"q\", \"p\", \"bottom\"));","atom":"a0","author":"init","version":0},{"n":43,"text":"\t\tassert.deepEqual(","atom":"a0","author":"init","version":0},{"n":44,"text":"\t\t\tr.deps,","atom":"a0","author":"init","version":0},{"n":45,"text":"\t\t\t[\"a0\", p.id, q.id].sort((a, b) => Number(a.slice(1)) - Number(b.slice(1))),","atom":"a0","author":"init","version":0},{"n":46,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":47,"text":"\t});","atom":"a0","author":"init","version":0},{"n":48,"text":"","atom":"a0","author":"init","version":0},{"n":49,"text":"\tit(\"puts a line's replacements ahead of the lines inserted after it, whatever their priority\", () => {","atom":"a0","author":"init","version":0},{"n":50,"text":"\t\tconst repo = Repo.init({ \"f.txt\": lines(\"x\", \"y\") });","atom":"a0","author":"init","version":0},{"n":51,"text":"\t\tconst y1 = repo.edit({ edits: [{ file: \"f.txt\", old: \"y\", new: \"y1\" }] });","atom":"a0","author":"init","version":0},{"n":52,"text":"\t\tconst y2 = repo.edit({ edits: [{ file: \"f.txt\", old: \"y1\", new: \"y2\" }] });","atom":"a0","author":"init","version":0},{"n":53,"text":"\t\t// A before-mode insert above y2: it hangs off x and depends on y2's writer (lamport 3).","atom":"a0","author":"init","version":0},{"n":54,"text":"\t\tconst before = repo.edit({ edits: [{ file: \"f.txt\", start: 1, end: 1, lines: [\"n\"], mode: \"before\" }] });","atom":"a0","author":"init","version":0},{"n":55,"text":"\t\tassert.equal(repo.graph.lamport(before.id), 3);","atom":"a0","author":"init","version":0},{"n":56,"text":"\t\t// A replacement of x written against the base (lamport 1); the two don't conflict.","atom":"a0","author":"init","version":0},{"n":57,"text":"\t\tconst replace = repo.edit({ edits: [{ file: \"f.txt\", old: \"x\", new: \"X\" }] }, [\"a0\"]);","atom":"a0","author":"init","version":0},{"n":58,"text":"\t\tassert.equal(repo.graph.lamport(replace.id), 1);","atom":"a0","author":"init","version":0},{"n":59,"text":"\t\tassert.deepEqual(conflicts(repo.graph, repo.shared), []);","atom":"a0","author":"init","version":0},{"n":60,"text":"\t\tassert.equal(repo.text(\"f.txt\"), lines(\"X\", \"n\", \"y2\"));","atom":"a0","author":"init","version":0},{"n":61,"text":"\t\tassert.deepEqual(","atom":"a0","author":"init","version":0},{"n":62,"text":"\t\t\trepo","atom":"a0","author":"init","version":0},{"n":63,"text":"\t\t\t\t.view()","atom":"a0","author":"init","version":0},{"n":64,"text":"\t\t\t\t.sequence(\"f.txt\")","atom":"a0","author":"init","version":0},{"n":65,"text":"\t\t\t\t.map((l) => l.id),","atom":"a0","author":"init","version":0},{"n":66,"text":"\t\t\t[\"a0.0\", `${replace.id}.0`, `${before.id}.0`, \"a0.1\", `${y1.id}.0`, `${y2.id}.0`],","atom":"a0","author":"init","version":0},{"n":67,"text":"\t\t);","atom":"a0","author":"init","version":0},{"n":68,"text":"\t});","atom":"a0","author":"init","version":0},{"n":69,"text":"","atom":"a0","author":"init","version":0},{"n":70,"text":"\tit(\"refuses sets that are not closed or name unknown atoms\", () => {","atom":"a0","author":"init","version":0},{"n":71,"text":"\t\tconst repo = Repo.init({ \"f.txt\": lines(\"one\") });","atom":"a0","author":"init","version":0},{"n":72,"text":"\t\tconst x = repo.edit({ edits: [{ file: \"f.txt\", old: \"one\", new: \"ONE\" }] });","atom":"a0","author":"init","version":0},{"n":73,"text":"\t\tassert.throws(() => new View(repo.graph, [x.id]), { code: \"not-closed\" });","atom":"a0","author":"init","version":0},{"n":74,"text":"\t\tassert.throws(() => new View(repo.graph, [\"a0\", \"a9\"]), { code: \"unknown-atom\" });","atom":"a0","author":"init","version":0},{"n":75,"text":"\t\tassert.deepEqual(new View(repo.graph, []).files(), {});","atom":"a0","author":"init","version":0},{"n":76,"text":"\t});","atom":"a0","author":"init","version":0},{"n":77,"text":"","atom":"a0","author":"init","version":0},{"n":78,"text":"\tit(\"projects a long file (a deep chain) without recursion limits\", () => {","atom":"a0","author":"init","version":0},{"n":79,"text":"\t\tconst big = Array.from({ length: 30_000 }, (_, i) => `line ${i}`);","atom":"a0","author":"init","version":0},{"n":80,"text":"\t\tconst graph = new Graph();","atom":"a0","author":"init","version":0},{"n":81,"text":"\t\tgraph.add(buildBase({ \"big.txt\": big.join(\"\\n\") + \"\\n\" }, { author: \"import\", message: \"big\" }));","atom":"a0","author":"init","version":0},{"n":82,"text":"\t\tconst files = project(graph, [\"a0\"]);","atom":"a0","author":"init","version":0},{"n":83,"text":"\t\tassert.equal(files[\"big.txt\"]!.split(\"\\n\").length, 30_001);","atom":"a0","author":"init","version":0},{"n":84,"text":"\t});","atom":"a0","author":"init","version":0},{"n":85,"text":"","atom":"a0","author":"init","version":0},{"n":86,"text":"\tit(\"lists known paths separately from existing files\", () => {","atom":"a0","author":"init","version":0},{"n":87,"text":"\t\tconst repo = Repo.init({ \"a.txt\": lines(\"a\"), \"b.txt\": lines(\"b\") });","atom":"a0","author":"init","version":0},{"n":88,"text":"\t\trepo.edit({ edits: [{ file: \"b.txt\", old: \"b\\n\", new: \"\" }] });","atom":"a0","author":"init","version":0},{"n":89,"text":"\t\tconst view = repo.view();","atom":"a0","author":"init","version":0},{"n":90,"text":"\t\tassert.deepEqual(view.paths(), [\"a.txt\"]);","atom":"a0","author":"init","version":0},{"n":91,"text":"\t\tassert.deepEqual(view.knownPaths(), [\"a.txt\", \"b.txt\"]);","atom":"a0","author":"init","version":0},{"n":92,"text":"\t\tassert.deepEqual(view.files(), { \"a.txt\": \"a\\n\" });","atom":"a0","author":"init","version":0},{"n":93,"text":"\t});","atom":"a0","author":"init","version":0},{"n":94,"text":"});","atom":"a0","author":"init","version":0}],"atoms":[{"atom":"a0","author":"init","message":"Start the project","time":1791506895507,"timeIso":"2026-10-09T00:48:15.507Z","publish":{"draft":null,"version":0,"agent":"init","message":"Start the project","time":1791506895507,"timeIso":"2026-10-09T00:48:15.507Z"}}]}