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 98edb1ba01 - Show all commits
+31
View File
@@ -5,8 +5,10 @@ import (
"go/build" "go/build"
"go/parser" "go/parser"
"go/token" "go/token"
"os"
"regexp" "regexp"
"slices" "slices"
"strconv"
"strings" "strings"
"testing" "testing"
) )
@@ -246,3 +248,32 @@ func headerAbove(headers []*ast.CommentGroup, pos token.Pos) string {
} }
return text return text
} }
var printedFake = regexp.MustCompile(`f\.Fake\("([^"]+)"\)\s*// ("(?:[^"\\]|\\.)*")`)
// TestGoExamplesPrintWhatTheyRender replays each Go example's printed Fake calls on seed 42.
func TestGoExamplesPrintWhatTheyRender(t *testing.T) {
for _, name := range []string{"doc.go", "README.md"} {
src, err := os.ReadFile(name)
if err != nil {
t.Fatal(err)
}
calls := printedFake.FindAllStringSubmatch(string(src), -1)
if calls == nil {
t.Errorf("%s prints no seeded Fake, so nothing holds its example to a render", name)
}
f, err := New(WithSeed(42))
if err != nil {
t.Fatal(err)
}
for _, c := range calls {
want, err := strconv.Unquote(c[2])
if err != nil {
t.Fatalf("%s prints %s: %v", name, c[2], err)
}
if got := fake(t, f, c[1]); got != want {
t.Errorf("%s prints Fake(%q) = %q for seed 42, it renders %q", name, c[1], want, got)
}
}
}
}