Make great documentation goal 1.2, and plan the README's reorganisation and the nested-template gaps #33
+65
-11
@@ -1,6 +1,7 @@
|
|||||||
package fejkdata
|
package fejkdata
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"maps"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
@@ -967,7 +968,8 @@ func TestAmbiguousNameNamesARunnablePath(t *testing.T) {
|
|||||||
|
|
||||||
// TestEnteredRowsAgreeWithPinning holds what a fence walk decides about the rows it entered, and
|
// TestEnteredRowsAgreeWithPinning holds what a fence walk decides about the rows it entered, and
|
||||||
// the rows a render draws, to what pinning refuses: drift between them is data that loads and then
|
// the rows a render draws, to what pinning refuses: drift between them is data that loads and then
|
||||||
// renders a family that disagrees.
|
// renders a family that disagrees. A row rendered whole is drawn over the whole table, apart from
|
||||||
|
// every pin, so it is an alternative only to another row of its own draw.
|
||||||
func TestEnteredRowsAgreeWithPinning(t *testing.T) {
|
func TestEnteredRowsAgreeWithPinning(t *testing.T) {
|
||||||
f := newGenerator(t, writeFiles(t, geo()), WithSeed(1))
|
f := newGenerator(t, writeFiles(t, geo()), WithSeed(1))
|
||||||
var tables []*table
|
var tables []*table
|
||||||
@@ -981,13 +983,8 @@ func TestEnteredRowsAgreeWithPinning(t *testing.T) {
|
|||||||
var none pinSet
|
var none pinSet
|
||||||
for _, entered := range tables {
|
for _, entered := range tables {
|
||||||
for row := 0; row < entered.rows(); row++ {
|
for row := 0; row < entered.rows(); row++ {
|
||||||
var drawn []tablePin
|
whole := drawAt{drawn: entered, whole: tablePin{entered, row}}
|
||||||
alone := none.entered(entered, row, false)
|
s := none.entered(entered, row)
|
||||||
alone.each(func(tbl *table, r int) { drawn = append(drawn, tablePin{tbl, r}) })
|
|
||||||
if len(drawn) != 1 || drawn[0] != (tablePin{entered, row}) {
|
|
||||||
t.Errorf("a drawn %s enters %v, want its own row alone", entered.selectorSpelling(row), drawn)
|
|
||||||
}
|
|
||||||
s := none.entered(entered, row, true)
|
|
||||||
for _, cand := range tables {
|
for _, cand := range tables {
|
||||||
for i := 0; i < 20; i++ {
|
for i := 0; i < 20; i++ {
|
||||||
drawing := s.clone()
|
drawing := s.clone()
|
||||||
@@ -998,18 +995,26 @@ func TestEnteredRowsAgreeWithPinning(t *testing.T) {
|
|||||||
for cr := 0; cr < cand.rows(); cr++ {
|
for cr := 0; cr < cand.rows(); cr++ {
|
||||||
beside := s.clone()
|
beside := s.clone()
|
||||||
refused := beside.pinRow(cand, cr) != nil
|
refused := beside.pinRow(cand, cr) != nil
|
||||||
if got := alternatives(drawAt{alt: s}, drawAt{alt: none.entered(cand, cr, true)}); got != refused {
|
pinned := drawAt{alt: none.entered(cand, cr)}
|
||||||
|
if got := alternatives(drawAt{alt: s}, pinned); got != refused {
|
||||||
t.Errorf("alternatives(%s, %s) = %v, but pinning both refuses = %v", entered.selectorSpelling(row), cand.selectorSpelling(cr), got, refused)
|
t.Errorf("alternatives(%s, %s) = %v, but pinning both refuses = %v", entered.selectorSpelling(row), cand.selectorSpelling(cr), got, refused)
|
||||||
}
|
}
|
||||||
|
if alternatives(whole, pinned) || alternatives(pinned, whole) {
|
||||||
|
t.Errorf("%s rendered whole is an alternative to %s pinned, though the whole draw ignores the pin", entered.selectorSpelling(row), cand.selectorSpelling(cr))
|
||||||
|
}
|
||||||
|
other := drawAt{drawn: cand, whole: tablePin{cand, cr}}
|
||||||
|
if want := cand == entered && cr != row; alternatives(whole, other) != want {
|
||||||
|
t.Errorf("alternatives(%s, %s), both rendered whole, = %v, want %v", entered.selectorSpelling(row), cand.selectorSpelling(cr), !want, want)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var spilled pinSet
|
var spilled pinSet
|
||||||
for i := 0; i <= len(spilled.inline); i++ {
|
for i := 0; i <= len(spilled.inline); i++ {
|
||||||
spilled = spilled.entered(&table{path: strconv.Itoa(i)}, 0, false)
|
spilled = spilled.entered(&table{path: strconv.Itoa(i)}, 0)
|
||||||
}
|
}
|
||||||
_ = spilled.entered(&table{path: "past"}, 0, false)
|
_ = spilled.entered(&table{path: "past"}, 0)
|
||||||
n := 0
|
n := 0
|
||||||
spilled.each(func(*table, int) { n++ })
|
spilled.each(func(*table, int) { n++ })
|
||||||
if n != len(spilled.inline)+1 {
|
if n != len(spilled.inline)+1 {
|
||||||
@@ -1017,6 +1022,55 @@ func TestEnteredRowsAgreeWithPinning(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
func TestProbeReportsTheTablesADrawPins(t *testing.T) {
|
||||||
|
f := newGenerator(t, writeFiles(t, geo()), WithSeed(1))
|
||||||
|
for _, path := range []string{
|
||||||
|
"locality.code",
|
||||||
|
"municipality.locality.name",
|
||||||
|
"municipality[1281].locality.name",
|
||||||
|
"municipality.locality[L4].name",
|
||||||
|
"region",
|
||||||
|
"region.municipality.name",
|
||||||
|
"region[12].municipality.locality.code",
|
||||||
|
"region[12].name",
|
||||||
|
} {
|
||||||
|
segs, err := splitPath(path)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
head := f.categories[segs[0]].(*table)
|
||||||
|
var probed pinSet
|
||||||
|
drawn := map[*table]bool{}
|
||||||
|
if _, err := walkPath(head, segs[1:], pathWalk{mode: walkProbe, pins: &probed, drawn: drawn}); err != nil {
|
||||||
|
t.Fatalf("%s: %v", path, err)
|
||||||
|
}
|
||||||
|
for i := 0; i < 20; i++ {
|
||||||
|
var pins pinSet
|
||||||
|
drawPath(head, segs[1:], segs[0], &pins, &pathDraws{s: f.rand})
|
||||||
|
want := map[*table]bool{}
|
||||||
|
pins.each(func(tbl *table, _ int) {
|
||||||
|
if _, selected := probed.pinned(tbl); !selected {
|
||||||
|
want[tbl] = true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
if !maps.Equal(drawn, want) {
|
||||||
|
t.Fatalf("%s: the probe reports %v drawn, a draw pins %v", path, categoriesOf(drawn), categoriesOf(want))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func categoriesOf(tables map[*table]bool) []string {
|
||||||
|
var out []string
|
||||||
|
for tbl := range tables {
|
||||||
|
out = append(out, tbl.category)
|
||||||
|
}
|
||||||
|
slices.Sort(out)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
// TestCellReadsMeetWhereTheRenderPairsTheRows reads what the TSVs below do not show: region 01's
|
// TestCellReadsMeetWhereTheRenderPairsTheRows reads what the TSVs below do not show: region 01's
|
||||||
// note holds {/addr} and 1280's, under region 12, holds {/addr.city}, so the two meet only where
|
// note holds {/addr} and 1280's, under region 12, holds {/addr.city}, so the two meet only where
|
||||||
// no read pins a region.
|
// no read pins a region.
|
||||||
|
|||||||
Reference in New Issue
Block a user