Test that every shipped category loads alone into a fresh New

This commit is contained in:
2026-10-03 17:20:36 +02:00
committed by Lillem4n
parent 5667cd5dc3
commit 81bb979164
+15 -11
View File
@@ -33,17 +33,9 @@ func newShippedWhole(t testing.TB, opts ...Option) *Generator {
// loadedCategories is the dot path of every category f has parsed and linked.
func loadedCategories(f *Generator) []string {
var out []string
var walk func(prefix string, g *folder)
walk = func(prefix string, g *folder) {
for _, name := range sortedNames(g.children) {
if sub, isFolder := g.children[name].(*folder); isFolder {
walk(join(prefix, name), sub)
continue
}
out = append(out, join(prefix, name))
}
for _, s := range categorySites(&f.root) {
out = append(out, s.path)
}
walk("", &f.root)
return out
}
@@ -70,7 +62,7 @@ func TestShippedIndexIsCurrent(t *testing.T) {
func shippedIndexSource(whole *Generator) ([]byte, error) {
var b bytes.Buffer
b.WriteString("// Code generated by TestShippedIndexIsCurrent with REPIN=1. DO NOT EDIT.\n\npackage fejkdata\n\nvar shippedIndex = map[string]shippedCategory{\n")
b.WriteString("// Code generated by TestShippedIndexIsCurrent with REPIN=1. DO NOT EDIT.\n\npackage fejkdata\n\nvar shippedIndex = map[string]shippedEntry{\n")
for _, s := range categorySites(&whole.root) {
fmt.Fprintf(&b, "%q: {", s.path)
if t, isTable := s.n.(*table); isTable && t.parentIndex >= 0 {
@@ -186,6 +178,18 @@ func TestOnDemandRendersAsTheWholeLoad(t *testing.T) {
}
}
func TestEveryShippedCategoryLoadsAlone(t *testing.T) {
for p := range shippedIndex {
f, err := New()
if err != nil {
t.Fatalf("New() = %v", err)
}
if _, err := f.Fake(p); err != nil {
t.Errorf("Fake(%q) on a fresh New() = %v", p, err)
}
}
}
func TestListRunsBesideAnOnDemandLoad(t *testing.T) {
f, err := New()
if err != nil {