Make great documentation goal 1.2, and plan the README's reorganisation and the nested-template gaps #33
+13
-33
@@ -9,51 +9,31 @@ import (
|
|||||||
|
|
||||||
func TestWalkPathStopsAtAMissingSegment(t *testing.T) {
|
func TestWalkPathStopsAtAMissingSegment(t *testing.T) {
|
||||||
n := compiled(t, `{"format":"{a}","a":{"format":"{b}","b":"leaf"}}`)
|
n := compiled(t, `{"format":"{a}","a":{"format":"{b}","b":"leaf"}}`)
|
||||||
var seen []string
|
if leaves := pathLeaves(n, []string{"a", "b"}); len(leaves) != 1 {
|
||||||
walk := pathWalk{
|
t.Fatalf("pathLeaves(a.b) = %v, want the one leaf", leaves)
|
||||||
mode: walkEvery,
|
|
||||||
pins: &pinSet{},
|
|
||||||
level: func(tm *template, rest []string) error { seen = append(seen, "level:"+rest[0]); return nil },
|
|
||||||
leaf: func(n node) error { seen = append(seen, "leaf"); return nil },
|
|
||||||
}
|
}
|
||||||
if _, err := walkPath(n, []string{"a", "b"}, walk); err != nil {
|
w := &proveWalk{tail: []string{"a", "nope", "deeper"}}
|
||||||
t.Fatalf("walkPath(a.b) = %v", err)
|
_, err := w.walk(n, w.tail)
|
||||||
}
|
|
||||||
if want := []string{"level:a", "level:b", "leaf"}; !slices.Equal(seen, want) {
|
|
||||||
t.Errorf("walk visited %v, want %v", seen, want)
|
|
||||||
}
|
|
||||||
seen = nil
|
|
||||||
_, err := walkPath(n, []string{"a", "nope", "deeper"}, walk)
|
|
||||||
if err == nil || !strings.Contains(err.Error(), `no field "nope"`) {
|
if err == nil || !strings.Contains(err.Error(), `no field "nope"`) {
|
||||||
t.Errorf("walkPath(a.nope.deeper) = %v, want the missing segment named", err)
|
t.Errorf("walk(a.nope.deeper) = %v, want the missing segment named", err)
|
||||||
}
|
}
|
||||||
if slices.Contains(seen, "leaf") {
|
if len(w.leaves) > 0 {
|
||||||
t.Errorf("walk reached a leaf past a missing segment: %v", seen)
|
t.Errorf("walk reached a leaf past a missing segment: %v", w.leaves)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWalkPathChoiceConsumesNoSegment(t *testing.T) {
|
func TestWalkPathChoiceConsumesNoSegment(t *testing.T) {
|
||||||
n := compiled(t, `[{"format":"{f}","f":"1"},{"format":"{f}","f":"2"}]`)
|
n := compiled(t, `[{"format":"{f}","f":"1"},{"format":"{f}","f":"2"}]`)
|
||||||
var leaves []node
|
if leaves := pathLeaves(n, []string{"f"}); len(leaves) != 2 {
|
||||||
_, err := walkPath(n, []string{"f"}, pathWalk{
|
t.Fatalf("pathLeaves through a choice = %v, want both variants' f", leaves)
|
||||||
mode: walkEvery,
|
|
||||||
pins: &pinSet{},
|
|
||||||
leaf: func(n node) error { leaves = append(leaves, n); return nil },
|
|
||||||
})
|
|
||||||
if err != nil || len(leaves) != 2 {
|
|
||||||
t.Fatalf("walkPath through a choice = %v, %d leaves, want both variants' f", err, len(leaves))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWalkCoverStopsAtAChoice(t *testing.T) {
|
func TestWalkCoverStopsAtAChoice(t *testing.T) {
|
||||||
n := compiled(t, `[{"format":"{f}","f":"1"},{"format":"{f}","f":"2"}]`)
|
n := compiled(t, `[{"format":"{f}","f":"1"},{"format":"{f}","f":"2"}]`)
|
||||||
var leaves []node
|
leaf, err := (&coverWalk{into: map[node]bool{}}).walk(n, []string{"f"})
|
||||||
_, err := walkPath(n, []string{"f"}, pathWalk{
|
if err != nil || leaf != n {
|
||||||
mode: walkCover,
|
t.Fatalf("cover through a choice = %v, %v, want the choice itself", leaf, err)
|
||||||
leaf: func(n node) error { leaves = append(leaves, n); return nil },
|
|
||||||
})
|
|
||||||
if err != nil || len(leaves) != 1 || leaves[0] != n {
|
|
||||||
t.Fatalf("cover through a choice = %v, leaves %v, want the choice alone", err, leaves)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +43,7 @@ func TestDrawPathPanicsOnAnUnprovedPath(t *testing.T) {
|
|||||||
t.Errorf("drawPath(plain, f) recovered %v, want a panic naming the path and the missing field", r)
|
t.Errorf("drawPath(plain, f) recovered %v, want a panic naming the path and the missing field", r)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
drawPath(compiled(t, `"plain"`), []string{"f"}, "plain", &pinSet{}, &pathDraws{s: engine(1).rand})
|
drawPath(compiled(t, `"plain"`), []string{"f"}, "plain", &renderWalk{s: engine(1).rand, pins: &pinSet{}})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDeepDottedPath(t *testing.T) {
|
func TestDeepDottedPath(t *testing.T) {
|
||||||
|
|||||||
+4
-4
@@ -1061,14 +1061,14 @@ func TestProbeReportsTheTablesADrawPins(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
head := f.categories[segs[0]].(*table)
|
head := f.categories[segs[0]].(*table)
|
||||||
var probed pinSet
|
probe := &probeWalk{}
|
||||||
drawn := map[*table]bool{}
|
if _, err := probe.walk(head, segs[1:]); err != nil {
|
||||||
if _, err := walkPath(head, segs[1:], pathWalk{mode: walkProbe, pins: &probed, drawn: drawn}); err != nil {
|
|
||||||
t.Fatalf("%s: %v", path, err)
|
t.Fatalf("%s: %v", path, err)
|
||||||
}
|
}
|
||||||
|
probed, drawn := probe.pins, probe.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], &pins, &pathDraws{s: f.rand})
|
drawPath(head, segs[1:], segs[0], &renderWalk{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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user