Make great documentation goal 1.2, and plan the README's reorganisation and the nested-template gaps #33

Open
lilleman wants to merge 966 commits from worktree-todo-relative-dates-exact-counts into main
Showing only changes of commit 4ee0d61a64 - Show all commits
+26 -29
View File
@@ -3,8 +3,8 @@ package fejkdata
import ( import (
"encoding/json" "encoding/json"
"go/ast" "go/ast"
"reflect"
"slices" "slices"
"sort"
"testing" "testing"
) )
@@ -62,23 +62,6 @@ type unhandledNode struct{}
func (*unhandledNode) isNode() {} func (*unhandledNode) isNode() {}
// nodeSwitches are the switches node's comment lists, each over a scope holding row 0
// of the sample table.
func nodeSwitches(tbl *table) map[string]func(node) {
return map[string]func(node){
"columnItems": func(n node) { columnItems(n) },
"contained": func(n node) { contained(n) },
"paths": func(n node) { paths(n) },
"prove": func(n node) { (&valueProof{}).prove(n) },
"render": func(n node) {
var set holdSet
render(engine(1).rand, n, renderScope{set: &set, row: renderedRow{tbl, 0}})
},
"renderEdges": func(n node) { renderEdges(n) },
"stepInto": func(n node) { _, _ = stepInto(n, "x") },
}
}
// nodeSwitchSkips is the kinds a switch is never handed: its callers step past them first. // nodeSwitchSkips is the kinds a switch is never handed: its callers step past them first.
var nodeSwitchSkips = map[string][]string{ var nodeSwitchSkips = map[string][]string{
"columnItems": {"folder", "table", "tableRow"}, "columnItems": {"folder", "table", "tableRow"},
@@ -93,14 +76,17 @@ func TestNodeSwitchesHandleEveryKind(t *testing.T) {
"r.tsv": "code\tname\n01\t{digits(2)}\n02\tB\n", "r.tsv": "code\tname\n01\t{digits(2)}\n02\tB\n",
})) }))
tbl := f.root.children["r"].(*table) tbl := f.root.children["r"].(*table)
samples := map[string]node{ samples := map[string]node{}
"choice": compiled(t, `["a","b"]`), for _, n := range []node{
"folder": &f.root, compiled(t, `["a","b"]`),
"nullItem": &nullItem{}, compiled(t, `{"format":"{x}","x":"1"}`),
"table": tbl, &f.root,
"tableColumn": tbl.formatTemplate.fields["name"], &nullItem{},
"tableRow": tbl.rowNode, tbl,
"template": compiled(t, `{"format":"{x}","x":"1"}`), tbl.formatTemplate.fields["name"],
tbl.rowNode,
} {
samples[reflect.TypeOf(n).Elem().Name()] = n
} }
var kinds []string var kinds []string
_, files := sourceFiles(t) _, files := sourceFiles(t)
@@ -111,16 +97,27 @@ func TestNodeSwitchesHandleEveryKind(t *testing.T) {
} }
} }
} }
sort.Strings(kinds) slices.Sort(kinds)
sampled := make([]string, 0, len(samples)) sampled := make([]string, 0, len(samples))
for kind := range samples { for kind := range samples {
sampled = append(sampled, kind) sampled = append(sampled, kind)
} }
sort.Strings(sampled) slices.Sort(sampled)
if !slices.Equal(kinds, sampled) { if !slices.Equal(kinds, sampled) {
t.Fatalf("node kinds %v, samples %v; give every kind a sample here", kinds, sampled) t.Fatalf("node kinds %v, samples %v; give every kind a sample here", kinds, sampled)
} }
for name, call := range nodeSwitches(tbl) { for name, call := range map[string]func(node){
"columnItems": func(n node) { columnItems(n) },
"contained": func(n node) { contained(n) },
"paths": func(n node) { paths(n) },
"prove": func(n node) { (&valueProof{}).prove(n) },
"render": func(n node) {
var set holdSet
render(engine(1).rand, n, renderScope{set: &set, row: renderedRow{tbl, 0}})
},
"renderEdges": func(n node) { renderEdges(n) },
"stepInto": func(n node) { _, _ = stepInto(n, "x") },
} {
mustPanic(t, name+" on an unhandled node", func() { call(&unhandledNode{}) }) mustPanic(t, name+" on an unhandled node", func() { call(&unhandledNode{}) })
for _, kind := range kinds { for _, kind := range kinds {
if slices.Contains(nodeSwitchSkips[name], kind) { if slices.Contains(nodeSwitchSkips[name], kind) {