From b99526aeb8884e7f6e23323ac774ebe2e0d0310c Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 4 Sep 2026 09:46:39 +0200 Subject: [PATCH] Tests: a record read whole or as an operand still points back at itself, and Record under concurrent use --- perf_test.go | 6 ++++-- record_test.go | 16 ++++++++++------ shipped_data_test.go | 4 ++++ 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/perf_test.go b/perf_test.go index 8536cac..d3ac0cb 100644 --- a/perf_test.go +++ b/perf_test.go @@ -52,8 +52,7 @@ func TestNoRenderAllocRegression(t *testing.T) { } // A record's fences read the compiled tree, so they belong to New, not to a draw. -// A per-draw walk costs allocations in proportion to the tree; this pins that the -// count does not move with the column count. +// A per-draw walk costs allocations in proportion to the tree. func TestNoRecordAllocRegression(t *testing.T) { for _, s := range []struct{ name, json string }{ {"record 3 columns", `{"format":"","a":"x","b":"y","c":"z"}`}, @@ -63,6 +62,9 @@ func TestNoRecordAllocRegression(t *testing.T) { if err != nil { t.Fatalf("New(%s): %v", s.name, err) } + if _, err := f.Record("x"); err != nil { + t.Fatalf("Record(%s): %v", s.name, err) // else the gate would measure the error path + } const base = 4.0 if allocs := testing.AllocsPerRun(10000, func() { f.Record("x") }); allocs > base*1.10 { t.Errorf("%s: %.1f allocs/op regressed past %.1f (baseline %.1f + 10%%); a record fence running per draw is the usual cause", s.name, allocs, base*1.10, base) diff --git a/record_test.go b/record_test.go index 0de914e..01c5d20 100644 --- a/record_test.go +++ b/record_test.go @@ -184,12 +184,16 @@ func TestInlineRecordRejectsOverlappingColumns(t *testing.T) { } func TestRecordRejectsAColumnReadingItsOwnRecord(t *testing.T) { - dir := writeData(t, map[string]string{ - "person": `{"format":"{first} {last}","first":["Ada","Bo"],"last":["Lovelace","Ek"],"full":"{/person.first} {/person.last}"}`, - }) - f := newGenerator(t, dir, WithSeed(1)) - if _, err := f.Record("person"); err == nil || !strings.Contains(err.Error(), "points back at this record") { - t.Fatalf("a column referencing its own record = %v, want it refused; it would contradict the columns it reads", err) + for _, c := range []struct{ name, column string }{ + {"a path into itself", `"full":"{/person.first} {/person.last}"`}, + {"the record read whole", `"whole":"{/person}"`}, + {"the record as an operand", `"up":"{uppercase(/person)}"`}, + } { + person := `{"format":"{first} {last}","first":["Ada","Bo"],"last":["Lovelace","Ek"],` + c.column + `}` + f := newGenerator(t, writeData(t, map[string]string{"person": person}), WithSeed(1)) + if _, err := f.Record("person"); err == nil || !strings.Contains(err.Error(), "points back at this record") { + t.Errorf("%s: Record = %v, want it refused; the column would contradict the columns beside it", c.name, err) + } } } diff --git a/shipped_data_test.go b/shipped_data_test.go index fe1409d..374b7a8 100644 --- a/shipped_data_test.go +++ b/shipped_data_test.go @@ -108,6 +108,10 @@ func TestFakeIsSafeForConcurrentUse(t *testing.T) { return } f.List() + if _, err := f.Record("sv_SE.person"); err != nil { + t.Error(err) + return + } tmpl, err := f.NewTemplate("{/sv_SE.person.last}") if err != nil { t.Error(err)