Assert the table each probed selector is credited to

This commit is contained in:
2026-09-29 09:17:31 +02:00
committed by Lillem4n
parent c78f9618cf
commit 2499e71809
+28 -24
View File
@@ -1042,36 +1042,40 @@ func TestEnteredRowsAgreeWithPinning(t *testing.T) {
} }
// TestProbeReportsTheTablesADrawPins holds the check mode to the render: the tables a probe says a // TestProbeReportsTheTablesADrawPins holds the check mode to the render: the tables a probe says a
// path draws are those a draw of it pins beyond what its selectors pin. // path draws are those a draw of it pins beyond what its selectors pin, and each selector is credited
// to the table it selects a row of.
func TestProbeReportsTheTablesADrawPins(t *testing.T) { func TestProbeReportsTheTablesADrawPins(t *testing.T) {
f := newGenerator(t, writeFiles(t, geo()), WithSeed(1)) f := newGenerator(t, writeFiles(t, geo()), WithSeed(1))
for _, path := range []string{ for _, c := range []struct{ path, sels string }{
"locality.code", {"locality.code", ""},
"municipality.locality.name", {"municipality.locality.name", ""},
"municipality[1281].locality.name", {"municipality[1281].locality.name", "municipality=municipality[1281]"},
"municipality.locality[L4].name", {"municipality.locality[L4].name", "locality=municipality.locality[L4]"},
"region", {"region", ""},
"region.municipality", {"region.municipality", ""},
"region.municipality.name", {"region.municipality.name", ""},
"region.locality.name", {"region.locality.name", ""},
"region[12].locality", {"region[12].locality", "region=region[12]"},
"region[12].locality.code", {"region[12].locality.code", "region=region[12]"},
"region[12].municipality.locality.code", {"region[12].locality[L4].name", "region=region[12] locality=region[12].locality[L4]"},
"region[12].name", {"region[12].municipality.locality.code", "region=region[12]"},
{"region[12].municipality[1281].locality.code", "region=region[12] municipality=region[12].municipality[1281]"},
{"region[12].name", "region=region[12]"},
} { } {
segs, err := splitPath(path) a := splitArm(c.path, nil)
if err != nil { head := f.root.children[a.key].(*table)
t.Fatal(err) tr := tableReadOf(head, a, nil)
var sels []string
for _, s := range tr.sels {
sels = append(sels, s.t.segment+"="+s.spelling)
} }
head := f.root.children[segs[0]].(*table) if got := strings.Join(sels, " "); got != c.sels {
probe := &pathProbe{drawn: map[*table]bool{}} t.Errorf("%s: the probe credits the selectors %q, want %q", c.path, got, c.sels)
if _, err := probe.walk(head, segs[1:]); err != nil {
t.Fatalf("%s: %v", path, err)
} }
probed, drawn := probe.pins, probe.drawn probed, drawn := tr.pins, tr.drawn
for i := 0; i < 20; i++ { for i := 0; i < 20; i++ {
var pins pinSet var pins pinSet
drawPath(head, segs[1:], segs[0], &pathDraw{s: f.rand, pins: &pins}) drawPath(head, a.tail, a.key, &pathDraw{s: f.rand, pins: &pins})
want := map[*table]bool{} want := map[*table]bool{}
pins.each(func(tbl *table, _ int) { pins.each(func(tbl *table, _ int) {
if _, selected := probed.pinned(tbl); !selected { if _, selected := probed.pinned(tbl); !selected {
@@ -1079,7 +1083,7 @@ func TestProbeReportsTheTablesADrawPins(t *testing.T) {
} }
}) })
if !maps.Equal(drawn, want) { if !maps.Equal(drawn, want) {
t.Fatalf("%s: the probe reports %v drawn, a draw pins %v", path, segmentsOf(drawn), segmentsOf(want)) t.Fatalf("%s: the probe reports %v drawn, a draw pins %v", c.path, segmentsOf(drawn), segmentsOf(want))
} }
} }
} }