- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/worker/project/test/spelling.test.ts?format=json
87 linesFirst import 100%Last change First import in version 0, 1 version changed it
1// One file whatever the case of its spelling (#49):
2// a write under another spelling of an existing file is recorded as that
3// file, with a warning; only a move changes a file's case. A move keeps the
4// lines' ids, so blame follows the file.
6import assert from "node:assert/strict";
7import { test } from "node:test";
8import { blame } from "../blame.ts";
9import { MemoryStore, Project } from "../project.ts";
11function setup() {
12 const project = new Project(new MemoryStore());
13 project.init({ "README.md": "# readme\nline two\n", "src/a.ts": "export const a = 1;\n" }, 0);
14 for (const a of ["ann", "bob"]) project.sync(a);
15 return project;
16}
18test("a record or edit under another spelling goes to the existing file, with a warning", () => {
19 const project = setup();
20 const r = project.record("ann", { "readme.md": "# readme\nline two\nline three\n" }, 1);
21 assert.deepEqual([r.changed, r.spelling], [["README.md"], [{ path: "readme.md", existing: "README.md" }]]);
22 const e = project.edit("ann", { file: "SRC/A.TS", old: "1", new: "2" }, 2);
23 assert.ok(e.ok && e.spelling);
24 assert.deepEqual(e.ok && e.spelling, [{ path: "SRC/A.TS", existing: "src/a.ts" }]);
25 project.publish("ann", "two edits", 3);
26 assert.deepEqual(Object.keys(project.files()).sort(), ["README.md", "src/a.ts"], "still one file each");
27 assert.equal(project.files()["README.md"], "# readme\nline two\nline three\n");
28});
30test("a move changes a file's case, and its lines keep their ids, so blame still names who wrote them", () => {
31 const project = setup();
32 project.edit("bob", { file: "README.md", old: "line two", new: "line 2" }, 1);
33 project.publish("bob", "line 2", 2);
34 project.sync("ann");
35 const m = project.move("ann", "README.md", "readme.md", 3);
36 assert.deepEqual([m.from, m.to], ["README.md", "readme.md"]);
37 project.publish("ann", "lower case readme", 4);
38 assert.deepEqual(Object.keys(project.files()).sort(), ["readme.md", "src/a.ts"]);
39 assert.equal(project.files()["readme.md"], "# readme\nline 2\n");
40 assert.deepEqual(
41 blame(project, "readme.md").lines.map((l) => l.author),
42 ["init", "bob"],
43 );
44});
46test("a move is refused onto another existing file, from a missing one, or to the same name", () => {
47 const project = setup();
48 assert.throws(() => project.move("ann", "src/a.ts", "Readme.MD", 1), /Readme\.MD is README\.md, another file/);
49 assert.throws(() => project.move("ann", "nope.md", "x.md", 1), /there is no nope\.md to move/);
50 assert.throws(() => project.move("ann", "README.md", "README.md", 1), /already called that/);
51 const ok = project.move("ann", "src/a.ts", "lib/a.ts", 2);
52 assert.equal(ok.to, "lib/a.ts");
53});
55test("a record naming both spellings, the old one gone, is a rename and is taken as it is", () => {
56 const project = setup();
57 const r = project.record("ann", { "README.md": null, "readme.md": "# readme\nline two\n" }, 1);
58 assert.equal(r.spelling, undefined);
59 project.publish("ann", "rename by record", 2);
60 assert.deepEqual(Object.keys(project.files()).sort(), ["readme.md", "src/a.ts"]);
61});
63test("Unicode spellings of one name are one file, and a new decomposed name gets a gentle warning", () => {
64 const project = setup();
65 const composed = "notes/r\u00e9sum\u00e9.md";
66 const decomposed = "notes/re\u0301sume\u0301.md";
67 const first = project.record("ann", { [composed]: "one\n" }, 1);
68 assert.equal(first.uncomposed, undefined);
69 const second = project.record("ann", { [decomposed.toUpperCase()]: "two\n" }, 2);
70 assert.deepEqual(second.spelling, [{ path: decomposed.toUpperCase(), existing: composed }]);
71 project.publish("ann", "one name", 3);
72 assert.deepEqual(
73 Object.keys(project.files()).filter((p) => p.startsWith("notes/")),
74 [composed],
75 );
76 const fresh = project.edit("ann", { file: "notes/cafe\u0301.md", content: "x\n" }, 4);
77 assert.ok(fresh.ok);
78 assert.deepEqual(fresh.ok && fresh.uncomposed, ["notes/cafe\u0301.md"]);
79 assert.throws(() => project.move("ann", "src/a.ts", composed.toUpperCase(), 5), /another file/);
80});
82test("pathKey folds case and Unicode form, and ß as case folding does", async () => {
83 const { pathKey } = await import("../pathkey.ts");
84 assert.equal(pathKey("R\u00c9SUM\u00c9.md"), pathKey("re\u0301sume\u0301.md"));
85 assert.equal(pathKey("Stra\u00dfe.txt"), pathKey("STRASSE.txt"));
86 assert.notEqual(pathKey("a.md"), pathKey("b.md"));
87});