Pin bare-reference independence and tighten the shared-draw comments
Tests / vet + fmt + tests (pull_request) Successful in 1m3s

This commit is contained in:
2026-09-03 23:29:10 +02:00
parent 93ac610192
commit d237c15d77
3 changed files with 28 additions and 4 deletions
+1 -2
View File
@@ -274,8 +274,7 @@ func readField(s *session, t *template, held, shared *draws, a arm) string {
}
return renderShared(s, t.fields[a.key], shared)
}
// A reference names a shared source, so a record shares its draw across the
// columns; a sibling field is drawn per expansion as always.
// A reference shares its draw across a record's columns; a sibling is per expansion.
d := held
if isRef(a.key) && shared != nil {
d = shared
+26
View File
@@ -200,6 +200,32 @@ func TestRecordSharesAReferenceIntoAColumnRepeat(t *testing.T) {
}
}
func TestRecordBareReferenceStaysIndependent(t *testing.T) {
dir := writeData(t, map[string]string{
"currency": `[{"format":"{code}","code":"AUD"},{"format":"{code}","code":"EUR"}]`,
"order": `{"format":"","whole":"{/currency}","code":"{/currency.code}"}`,
})
f := newGenerator(t, dir, WithSeed(1))
sawMismatch := false
for i := 0; i < 100; i++ {
r, err := f.Record("order")
if err != nil {
t.Fatal(err)
}
m := map[string]string{}
for _, c := range r.Fields() {
m[c.Name] = c.Value
}
if m["whole"] != m["code"] {
sawMismatch = true
break
}
}
if !sawMismatch {
t.Fatal("a bare {/currency} column never disagreed with a tailed {/currency.code} column; a bare reference should draw independently")
}
}
func TestRecordSQLQuotesIdentifiers(t *testing.T) {
dir := writeData(t, map[string]string{
"row": `{"format": "", "postal-code": "1", "street-number": "2"}`,
+1 -2
View File
@@ -56,8 +56,7 @@ func render(s *session, n node) string {
}
// renderShared is render with a shared draw context: the draws a record shares
// across its columns. A nil shared means a standalone render, where a reference
// is drawn per expansion as it always has been.
// across its columns; a nil shared is a standalone render.
func renderShared(s *session, n node, shared *draws) string {
switch n := n.(type) {
case *choice: