Add record output to JSON, CSV and SQL #8
+4
-2
@@ -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)
|
||||
|
||||
+10
-6
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user