test(11.1-07): planted fixtures and unit tests for fence, execution and name-form holes

- eighteen violation plants pin nested src=, Go aliases, unrun examples, build membership and command forms
- unit tests cover fence collection, captions, goLang, go doc -c, commandWord and Sync
This commit is contained in:
Jakub Zych
2026-10-01 08:45:34 +02:00
parent efc3161c3f
commit 9ba5530ca7
48 changed files with 890 additions and 0 deletions

View File

@@ -469,6 +469,140 @@ func TestCommandTokenForms(t *testing.T) {
})
}
func TestNestedFenceChecks(t *testing.T) {
body := strings.Join([]string{
"> [!NOTE]",
"> ```go",
"> x := 1",
"> ```",
"",
"- item",
"",
" ```go",
" x := 1",
" ```",
"",
"```GO",
"x := 1",
"```",
"",
"```main.go",
"x := 1",
"```",
"",
" ```go",
" x := 1",
" ```",
"",
"> [!NOTE]",
"> ```sh",
"> summer bogus:nested",
"> ```",
"",
"> ```yaml src=config/app.yaml",
"> app:",
"> ```",
"",
}, "\n")
readme := strings.Join([]string{
"# fixture",
"",
"Fixture does one thing.",
"",
"## Usage",
"",
"```go",
"x := 1",
"```",
"",
"```go src=modules/fixture/fixture.go",
"package fixture",
"```",
"",
}, "\n")
assertProblems(t, checkFixture(t, fixtureCommands, map[string]string{
"docs/index.md": page("Acme docs", "index", 0, "Text.\n"),
"docs/setup/start.md": page("Start", "setup", 10, body),
"modules/fixture/README.md": readme,
}), []string{
"docs/setup/start.md:10: snippet: go code block has no src= reference",
"docs/setup/start.md:16: snippet: go code block has no src= reference",
"docs/setup/start.md:20: snippet: GO code block has no src= reference",
"docs/setup/start.md:24: snippet: main.go code block has no src= reference",
`docs/setup/start.md:34: command: "bogus:nested" is not a summer or application command`,
"docs/setup/start.md:37: snippet: config/app.yaml: " + nestedSrcMessage,
"modules/fixture/README.md:11: snippet: modules/fixture/fixture.go: " + readmeSrcMessage,
})
}
func TestIdentifierGoDocCaseSensitive(t *testing.T) {
root := writeTree(t, map[string]string{
"go.mod": "module example.com/forms\n\ngo 1.27\n",
"modules/forms/forms.go": "package forms\n\n" +
"// OpenFromApp is a fixture.\nfunc OpenFromApp() {}\n\n" +
"// Outer holds a method.\ntype Outer struct{}\n\n" +
"// HelloWorld is a method.\nfunc (Outer) HelloWorld() {}\n",
})
idx, problems, err := buildIdentIndex(root)
if err != nil || len(problems) > 0 {
t.Fatalf("buildIdentIndex: %v %q", err, problemLines(problems))
}
for _, q := range []string{"OpenFromApp", "Outer.HelloWorld"} {
if !idx.goDoc("modules/forms", q) {
t.Errorf("goDoc(%q) = false, want true", q)
}
}
for _, q := range []string{"Openfromapp", "Outer.Helloworld"} {
if idx.goDoc("modules/forms", q) {
t.Errorf("goDoc(%q) = true, want false", q)
}
}
if got := idx.checkSpan("forms.Openfromapp"); got != "forms.Openfromapp does not exist in modules/forms" {
t.Fatalf("checkSpan = %q", got)
}
}
func TestCommandWord(t *testing.T) {
tool, app := true, false
cases := []struct {
in string
name string
tool, ok bool
}{
{"summer docs:build", "docs:build", tool, true},
{"$ summer docs:build --out site", "docs:build", tool, true},
{"FOO=1 summer no:such", "no:such", tool, true},
{"FOO=1 BAR=x ./bin/acme serve", "serve", app, true},
{"summer --root . no:such", "no:such", tool, true},
{"summer --root=. docs:build", "docs:build", tool, true},
{"summer -r . docs:build", "docs:build", tool, true},
{"summer --help", "", tool, false},
{"summer --help docs:build", "docs:build", tool, true},
{"summer -h docs:build", "docs:build", tool, true},
{"summer --root", "", tool, false},
{"summer --root .", "", tool, false},
{"summer -- docs:build", "", tool, false},
{"go run ./cmd/summer no:such", "no:such", tool, true},
{"go run ./cmd/summer --root . docs:build", "docs:build", tool, true},
{"bin/acme migrate", "migrate", app, true},
{"./bin/acme migrate", "migrate", app, true},
{"echo summer x", "", false, false},
{"# summer x", "", false, false},
{"go test ./modules/demo", "", false, false},
{"go install ./cmd/summer", "", false, false},
{"summer", "", tool, false},
{"FOO=1", "", false, false},
{"summer --version", "", tool, false},
}
for _, tc := range cases {
name, isTool, ok := commandWord(tc.in)
if name != tc.name || isTool != tc.tool || ok != tc.ok {
t.Errorf("commandWord(%q) = %q, %v, %v; want %q, %v, %v",
tc.in, name, isTool, ok, tc.name, tc.tool, tc.ok)
}
}
}
func TestExampleCommandNames(t *testing.T) {
dir := writeTree(t, map[string]string{
"a/main.go": "package main\n\nimport \"x/bonfire\"\n\nvar a = bonfire.Command{Name: \"a:one\", Description: \"d\"}\n" +