feat: rm (with --cascade) and unalias commands, v0.1.2
ci / release (push) Successful in 1m13s

This commit is contained in:
2026-11-22 19:05:52 +01:00
parent 7c44fedcab
commit 7d1b6aed5f
3 changed files with 129 additions and 1 deletions
+67
View File
@@ -174,6 +174,73 @@ suite "find / path":
check run(d, "path", "a", "a").contains("same entity")
check fails(d, "path", "a", "e", "x").contains("integer")
suite "rm / unalias":
test "unalias removes, errors when absent":
let d = freshDir()
seed(d)
discard run(d, "alias", "a", "Foo")
discard run(d, "alias", "a", "bar")
check run(d, "unalias", "a", "foo") == "aliases of a: bar"
check readFile(d / "entities" / "a.md").contains("aliases: bar\n")
check fails(d, "unalias", "a", "foo").contains("alias not found")
check fails(d, "unalias", "zzz", "x").contains("entity not found")
test "rm without relations":
let d = freshDir()
seed(d)
check run(d, "rm", "a") == "removed entities/a.md"
check not fileExists(d / "entities" / "a.md")
check fails(d, "rm", "a").contains("entity not found")
check not fileExists(d / "entities" / "a.md.tmp")
test "rm refuses and lists relations in both directions":
let d = freshDir()
seed(d)
discard run(d, "link", "a", "part-of", "b", "why")
discard run(d, "link", "c", "part-of", "a")
let m = fails(d, "rm", "a")
check m.contains("refusing to remove a")
check m.contains(" a part-of b # why")
check m.contains(" c part-of a")
check fileExists(d / "entities" / "a.md")
check relsText(d).count("\n") == 2
test "rm --cascade removes relations and file, prints them":
let d = freshDir()
seed(d)
discard run(d, "link", "a", "part-of", "b", "why")
discard run(d, "link", "c", "part-of", "a")
discard run(d, "link", "c", "b")
check run(d, "rm", "a", "--cascade") ==
"removed relation a part-of b # why\nremoved relation c part-of a\nremoved entities/a.md"
check relsText(d) == "b\trelates-to\tc\n"
check not fileExists(d / "entities" / "a.md")
check run(d, "lint").contains("0 errors")
test "tombstone: rm acts on the tombstone, protected while referenced":
let d = freshDir()
seed(d)
discard run(d, "merge", "a", "b")
# tombstone a is unreferenced: rm removes it, not b
check run(d, "rm", "a") == "removed entities/a.md"
check fileExists(d / "entities" / "b.md")
# referenced by a relation
let d2 = freshDir()
seed(d2)
discard run(d2, "merge", "a", "b")
writeFile(d2 / "relations.tsv", "a\tpart-of\tc\n")
var m = fails(d2, "rm", "a", "--cascade")
check m.contains("tombstone a") and m.contains(" a part-of c")
check fileExists(d2 / "entities" / "a.md")
# referenced by another redirect
let d3 = freshDir()
seed(d3)
discard run(d3, "merge", "a", "b")
discard run(d3, "merge", "b", "c")
m = fails(d3, "rm", "b")
check m.contains("tombstone b") and m.contains("a -> b")
check fileExists(d3 / "entities" / "b.md")
suite "merge":
test "rewrites relations, unions aliases, tombstones, resolves redirects":
let d = freshDir()