Pin the reference-draw overlap to naming the disagreement and the read a drawGroup goes on

This commit is contained in:
2026-09-29 14:58:32 +02:00
committed by Lillem4n
parent 5c8e7d66d0
commit 68dc2e594a
5 changed files with 21 additions and 15 deletions
+2 -2
View File
@@ -108,8 +108,8 @@ func TestFakeTemplateErrors(t *testing.T) {
{`name: {/no.such.path}`, "no entry"},
{`name: {..nope}`, "write {/nope}"},
{`{"format":"x"}`, "is a string"},
{`{/misc.territory} {/misc.territory.alpha2}`, "and {/misc.territory.alpha2} share one reference draw, one read whole and one by a path; name the fields you want instead, or draw them apart with a drawGroup"},
{`{"format":"{/misc.territory.alpha2} {x}","x":"{/misc.territory}"}`, "share one reference draw"},
{`{/misc.territory} {/misc.territory.alpha2}`, "{/misc.territory} renders its own draw of what {/misc.territory.alpha2} reads a path through; name the fields you want instead, or move {/misc.territory.alpha2} into a field with a drawGroup"},
{`{"format":"{/misc.territory.alpha2} {x}","x":"{/misc.territory}"}`, "renders its own draw of what"},
{`{"format":"{/misc.territory.alpha2}","drawGroup":"g"}`, "nothing can reference"},
} {
_, err := f.FakeTemplate(c.input)
+2 -2
View File
@@ -220,7 +220,7 @@ func TestRecordRejectsOverlappingReferenceColumns(t *testing.T) {
{"a column reaching back through another category", `{"format":"","whole":"{/mid}","inner":"{/cat.a.b}"}`},
} {
_, err := New(WithoutShippedData(), WithDataPath(writeData(t, map[string]string{"cat": cat, "mid": mid, "row": c.row})))
if err == nil || !strings.Contains(err.Error(), "share one reference draw") {
if err == nil || !strings.Contains(err.Error(), "renders its own draw of what") {
t.Errorf("%s: New = %v, want the overlap refused at load, the way one format is", c.name, err)
continue
}
@@ -236,7 +236,7 @@ func TestInlineRecordRejectsOverlappingColumns(t *testing.T) {
})
f := newGenerator(t, dir, WithSeed(1))
_, err := f.FakeRecordTemplate(`{"format":"","whole":"{/cat.a}","inner":"{/cat.a.b}"}`)
if err == nil || !strings.Contains(err.Error(), "share one reference draw") {
if err == nil || !strings.Contains(err.Error(), "renders its own draw of what") {
t.Fatalf("inline record over an overlapping pair = %v, want the inline entry point to refuse it too", err)
}
}
+13 -7
View File
@@ -271,10 +271,14 @@ func TestReferenceOverlapIsRejected(t *testing.T) {
"a bare reference beside a path into what it never renders": `{"format":"{a} {b}","a":"{/cat}","b":"{/cat.p.first}"}`,
} {
_, err := New(WithoutShippedData(), WithDataPath(writeData(t, map[string]string{"cat": cat, "row": row})))
if err == nil || !strings.Contains(err.Error(), "share one reference draw") {
if err == nil || !strings.Contains(err.Error(), "renders its own draw of what") {
t.Errorf("%s: New = %v, want the overlap rejected", name, err)
}
}
_, err := New(WithoutShippedData(), WithDataPath(writeData(t, map[string]string{"cat": cat, "row": `{"format":"{a} {b}","a":"{/cat}","b":"{/cat.p.first}"}`})))
if err == nil || !strings.HasSuffix(err.Error(), "or give {b} a drawGroup") {
t.Errorf("New = %v, want the drawGroup named on the path's field", err)
}
// A sibling path and a reference into the level it holds are the same overlap,
// and the reference reaches it from a category row renders.
if _, err := New(WithoutShippedData(), WithDataPath(writeData(t, map[string]string{
@@ -283,11 +287,13 @@ func TestReferenceOverlapIsRejected(t *testing.T) {
}))); err == nil || !strings.Contains(err.Error(), "by a second route") {
t.Errorf("New = %v, want a sibling path beside a reference into it rejected", err)
}
if _, err := New(WithoutShippedData(), WithDataPath(writeData(t, map[string]string{
"cat": cat,
"row": `{"format":"{a} {b}","a":{"format":"{/cat.p}","drawGroup":"g"},"b":"{/cat.p.first}"}`,
}))); err != nil {
t.Errorf("New = %v, want a level and a path into it accepted in groups of their own", err)
for _, row := range []string{
`{"format":"{a} {b}","a":{"format":"{/cat.p}","drawGroup":"g"},"b":"{/cat.p.first}"}`,
`{"format":"{a} {b}","a":"{/cat}","b":{"format":"{/cat.p.first}","drawGroup":"g"}}`,
} {
if _, err := New(WithoutShippedData(), WithDataPath(writeData(t, map[string]string{"cat": cat, "row": row}))); err != nil {
t.Errorf("New(%s) = %v, want a level and a path into it accepted in groups of their own", row, err)
}
}
}
@@ -413,7 +419,7 @@ func TestSpellingsOfOneReferenceAreOneLevel(t *testing.T) {
"sv_SE/person": person,
"sv_SE/mail": `"{.person} <{/sv_SE.person.first}>"`,
})))
if err == nil || !strings.Contains(err.Error(), "share one reference draw") || !strings.Contains(err.Error(), "{.person}") {
if err == nil || !strings.Contains(err.Error(), "renders its own draw of what") || !strings.Contains(err.Error(), "{.person}") {
t.Errorf("New = %v, want the bare spelling rejected beside the path spelling", err)
}
dir := writeData(t, map[string]string{
+1 -1
View File
@@ -296,7 +296,7 @@ func TestFakeStructErrors(t *testing.T) {
{&struct {
A string `fake:"trip.leg"`
B string `fake:"trip.leg.to"`
}{}, "share one reference draw"},
}{}, "renders its own draw of what"},
{&struct {
Trip struct {
A int `fake:"{digits(3)}"`
+3 -3
View File
@@ -367,8 +367,8 @@ func TestTableSelectorInAReference(t *testing.T) {
func TestTableSelectionFences(t *testing.T) {
rejected := map[string]struct{ json, want string }{
"bare beside a path": {`"{/region} {/region.name}"`, "share one reference draw"},
"bare beside a linked path": {`"{/region} {/locality.name}"`, "share one reference draw"},
"bare beside a path": {`"{/region} {/region.name}"`, "renders its own draw of what"},
"bare beside a linked path": {`"{/region} {/locality.name}"`, "renders its own draw of what"},
"selected beside unselected": {`"{/region[12].municipality.name} {/municipality.code}"`, "{/region[12].municipality.code}"},
"relative selected beside unselected": {`"{.region[12].municipality.name} {.municipality.code}"`, "{.region[12].municipality.code}"},
"two selections": {`"{/region[12].name} {/region[14].name}"`, "drawGroup"},
@@ -1120,7 +1120,7 @@ func TestCellReadsMeetWhereTheRenderPairsTheRows(t *testing.T) {
"region.json": `{"format":"{name}={note}","rows":"region.tsv","key":"code","name":"name","weight":"population"}`,
"x.json": `"{/region}|{/municipality}"`,
})
if _, err := New(WithoutShippedData(), WithDataPath(writeFiles(t, whole)), WithSeed(1)); err == nil || !strings.Contains(err.Error(), "share one reference draw") {
if _, err := New(WithoutShippedData(), WithDataPath(writeFiles(t, whole)), WithSeed(1)); err == nil || !strings.Contains(err.Error(), "renders its own draw of what") {
t.Fatalf("New = %v, want the two drawn rows held to one draw of addr", err)
}
nested := with(whole, map[string]string{