Add record output to JSON, CSV and SQL #8

Open
lilleman wants to merge 21 commits from record-output into main
3 changed files with 18 additions and 8 deletions
Showing only changes of commit b99526aeb8 - Show all commits
+4 -2
View File
@@ -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 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 // A per-draw walk costs allocations in proportion to the tree.
// count does not move with the column count.
func TestNoRecordAllocRegression(t *testing.T) { func TestNoRecordAllocRegression(t *testing.T) {
for _, s := range []struct{ name, json string }{ for _, s := range []struct{ name, json string }{
{"record 3 columns", `{"format":"","a":"x","b":"y","c":"z"}`}, {"record 3 columns", `{"format":"","a":"x","b":"y","c":"z"}`},
@@ -63,6 +62,9 @@ func TestNoRecordAllocRegression(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("New(%s): %v", s.name, err) 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 const base = 4.0
if allocs := testing.AllocsPerRun(10000, func() { f.Record("x") }); allocs > base*1.10 { 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) 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)
+9 -5
View File
@@ -184,12 +184,16 @@ func TestInlineRecordRejectsOverlappingColumns(t *testing.T) {
} }
func TestRecordRejectsAColumnReadingItsOwnRecord(t *testing.T) { func TestRecordRejectsAColumnReadingItsOwnRecord(t *testing.T) {
dir := writeData(t, map[string]string{ for _, c := range []struct{ name, column string }{
"person": `{"format":"{first} {last}","first":["Ada","Bo"],"last":["Lovelace","Ek"],"full":"{/person.first} {/person.last}"}`, {"a path into itself", `"full":"{/person.first} {/person.last}"`},
}) {"the record read whole", `"whole":"{/person}"`},
f := newGenerator(t, dir, WithSeed(1)) {"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") { 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) t.Errorf("%s: Record = %v, want it refused; the column would contradict the columns beside it", c.name, err)
}
} }
} }
+4
View File
@@ -108,6 +108,10 @@ func TestFakeIsSafeForConcurrentUse(t *testing.T) {
return return
} }
f.List() f.List()
if _, err := f.Record("sv_SE.person"); err != nil {
t.Error(err)
return
}
tmpl, err := f.NewTemplate("{/sv_SE.person.last}") tmpl, err := f.NewTemplate("{/sv_SE.person.last}")
if err != nil { if err != nil {
t.Error(err) t.Error(err)