Test a name read before its binder links, and that every record carries its shape once loaded

This commit is contained in:
2026-10-05 22:15:05 +02:00
committed by Lillem4n
parent 34a0fb3a18
commit cdc82a99c6
2 changed files with 34 additions and 0 deletions
+13
View File
@@ -423,3 +423,16 @@ func TestAFieldBindingReadOutsideWhatItBindsLoads(t *testing.T) {
t.Errorf("NewTemplate = %v, want a read of n from x.z, outside x.y, accepted", err)
}
}
func TestANameReadBeforeItsBinderLinks(t *testing.T) {
dir := writeData(t, map[string]string{
"person": `{"format":"{first} {last}","first":["Ada","Bo","Cy"],"last":["Byron","Ek","Lind"]}`,
"row": `{"format":"{a}|{b}","a":"{p}","b":"{/person as p}{p.first} {p.last}"}`,
})
f := newGenerator(t, dir, WithSeed(2))
for i := 0; i < 100; i++ {
if a, b, _ := strings.Cut(fake(t, f, "row"), "|"); a != b {
t.Fatalf("a = %q, b = %q, want one pick of p", a, b)
}
}
}
+21
View File
@@ -537,3 +537,24 @@ func TestRecordOfAFieldlessCategoryNamesTheWrapper(t *testing.T) {
t.Fatalf("the named wrapper does not render: %v", err)
}
}
func TestEveryRecordCarriesItsShapeOnceLoaded(t *testing.T) {
f := newShippedWhole(t, WithSeed(1))
records := 0
if err := eachNode(&f.root, "", func(label string, n node) error {
tm, isTemplate := n.(*template)
if !isTemplate || !tm.isRecord || len(tm.fields) == 0 {
return nil
}
records++
if len(tm.columns) != len(tm.fields) {
t.Errorf("%s: %d record columns, want one per field, %d", label, len(tm.columns), len(tm.fields))
}
return nil
}); err != nil {
t.Fatal(err)
}
if records == 0 {
t.Fatal("no shipped record walked")
}
}