Test that New without WithSeed fails naming it, that the CLI without --seed draws afresh each run, and seed every test's New

This commit is contained in:
2026-10-12 18:10:57 +02:00
committed by Lillem4n
parent 1a5b632b90
commit 3ae8b9f1b1
19 changed files with 91 additions and 87 deletions
+9 -9
View File
@@ -107,7 +107,7 @@ func TestReferenceErrors(t *testing.T) {
"field key using the reference prefix": {"cat": `{"format":"hi","..x":"{/nope}"}`},
}
for name, files := range cases {
if _, err := New(WithDataPath(writeData(t, files))); err == nil {
if _, err := New(WithSeed(1), WithDataPath(writeData(t, files))); err == nil {
t.Errorf("%s: New = nil error, want a reference error", name)
}
}
@@ -142,13 +142,13 @@ func TestAReferenceIntoItsOwnCategoryIsAFreshDraw(t *testing.T) {
"the category in its format": `{"format":"{/cat}"}`,
"a field reading itself": `{"format":"{x}","x":"{/cat.x}"}`,
} {
_, err := New(WithDataPath(writeData(t, map[string]string{"cat": file})))
_, err := New(WithSeed(1), WithDataPath(writeData(t, map[string]string{"cat": file})))
if err == nil || !strings.Contains(err.Error(), "cycle") {
t.Errorf("%s: New = %v, want the cycle refused", name, err)
}
}
// Reading a sibling as a path is the spelling that stays.
if _, err := New(WithDataPath(writeData(t, map[string]string{
if _, err := New(WithSeed(1), WithDataPath(writeData(t, map[string]string{
"cat": `{"format":"{y.v}","y":{"format":"{v}","v":["1","2"]}}`,
}))); err != nil {
t.Errorf("New = %v, want the sibling path accepted", err)
@@ -173,7 +173,7 @@ func TestNewErrorIsDeterministic(t *testing.T) {
dir := writeData(t, files)
var first string
for i := 0; i < 50; i++ {
_, err := New(WithDataPath(dir))
_, err := New(WithSeed(1), WithDataPath(dir))
if err == nil {
t.Fatalf("%s: New = nil error, want a load error", name)
}
@@ -210,7 +210,7 @@ func TestNewErrorPathIsCanonical(t *testing.T) {
},
}
for _, c := range cases {
_, err := New(WithDataPath(writeData(t, c.files)))
_, err := New(WithSeed(1), WithDataPath(writeData(t, c.files)))
if err == nil {
t.Errorf("%s: New = nil error", c.name)
continue
@@ -222,7 +222,7 @@ func TestNewErrorPathIsCanonical(t *testing.T) {
}
func TestReferenceThroughChoiceNeedsEveryVariant(t *testing.T) {
_, err := New(WithDataPath(writeData(t, map[string]string{
_, err := New(WithSeed(1), WithDataPath(writeData(t, map[string]string{
"who": `[{"format":"{f}{h}","f":"1","h":"x"},{"format":"{g}{h}","g":"2","h":"y"}]`,
"card": `"{/who.f}"`,
})))
@@ -325,7 +325,7 @@ func TestReferenceSigilErrors(t *testing.T) {
"missing sibling": {"sv_SE/a": `"{.nope}"`},
"slash in a field name": {"a": `{"format":"{x}","x":"1","a/b":"2"}`},
} {
if _, err := New(WithDataPath(writeData(t, files))); err == nil {
if _, err := New(WithSeed(1), WithDataPath(writeData(t, files))); err == nil {
t.Errorf("%s: New = nil error, want a reference error", name)
}
}
@@ -336,7 +336,7 @@ func TestSlashAfterAReferenceSigilIsRejected(t *testing.T) {
"after ..": {"sv_SE/person": `"Ada"`, "sv_SE/deep/a": `"{../person}"`},
"after .": {"sv_SE/person": `"Ada"`, "sv_SE/a": `"{./person}"`},
} {
_, err := New(WithDataPath(writeData(t, files)))
_, err := New(WithSeed(1), WithDataPath(writeData(t, files)))
if err == nil || !strings.Contains(err.Error(), "person}") || !strings.Contains(err.Error(), "write {") {
t.Errorf("%s: New = %v, want the slash rejected naming the spelling", name, err)
}
@@ -344,7 +344,7 @@ func TestSlashAfterAReferenceSigilIsRejected(t *testing.T) {
}
func TestACycleThroughASelectedRowIsRefused(t *testing.T) {
_, err := New(WithDataPath(writeFiles(t, map[string]string{
_, err := New(WithSeed(1), WithDataPath(writeFiles(t, map[string]string{
"x.json": `{"format":"{v} {/y}","rows":"x.tsv","key":"code"}`,
"x.tsv": "code\tv\n1\ta\n2\tb\n",
"y.json": `"{/x[1]}"`,