Initial commit
Test / test (push) Successful in 7m5s
Release / gates (push) Successful in 7m28s
Release / build (amd64, freebsd) (push) Successful in 2m52s
Release / build (amd64, linux) (push) Successful in 2m46s
Release / build (arm64, freebsd) (push) Successful in 2m22s
Release / build (arm64, linux) (push) Successful in 2m38s
Release / build (loong64, linux) (push) Successful in 2m7s
Release / build (riscv64, linux) (push) Successful in 2m17s
Release / release (push) Successful in 1m0s
Test / test (push) Successful in 7m5s
Release / gates (push) Successful in 7m28s
Release / build (amd64, freebsd) (push) Successful in 2m52s
Release / build (amd64, linux) (push) Successful in 2m46s
Release / build (arm64, freebsd) (push) Successful in 2m22s
Release / build (arm64, linux) (push) Successful in 2m38s
Release / build (loong64, linux) (push) Successful in 2m7s
Release / build (riscv64, linux) (push) Successful in 2m17s
Release / release (push) Successful in 1m0s
Assisted-by: GLM 5.3
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
// Copyright (c) 2026 Petr Balvín <opensource@petrbalvin.org> (https://petrbalvin.org)
|
||||
// SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0
|
||||
|
||||
package markdown
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var update = flag.Bool("update", false, "rewrite golden files")
|
||||
|
||||
// TestGoldenCorpus renders every corpus file and compares against the
|
||||
// committed golden output. Run `go test ./internal/markdown -update` to
|
||||
// regenerate after an intentional rendering change.
|
||||
func TestGoldenCorpus(t *testing.T) {
|
||||
corpusDir := filepath.Join("testdata", "corpus")
|
||||
entries, err := os.ReadDir(corpusDir)
|
||||
if err != nil {
|
||||
t.Fatalf("read corpus: %v", err)
|
||||
}
|
||||
for _, entry := range entries {
|
||||
if entry.IsDir() || !strings.HasSuffix(entry.Name(), ".md") {
|
||||
continue
|
||||
}
|
||||
name := strings.TrimSuffix(entry.Name(), ".md")
|
||||
t.Run(name, func(t *testing.T) {
|
||||
src, err := os.ReadFile(filepath.Join(corpusDir, entry.Name()))
|
||||
if err != nil {
|
||||
t.Fatalf("read corpus file: %v", err)
|
||||
}
|
||||
htmlOut, toc, err := RenderWithTOC(string(src))
|
||||
if err != nil {
|
||||
t.Fatalf("RenderWithTOC: %v", err)
|
||||
}
|
||||
got := "=== HTML ===\n" + htmlOut + "=== TOC ===\n" + toc
|
||||
goldenPath := filepath.Join("testdata", name+".html")
|
||||
if *update {
|
||||
if err := os.WriteFile(goldenPath, []byte(got), 0o644); err != nil {
|
||||
t.Fatalf("write golden: %v", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
want, err := os.ReadFile(goldenPath)
|
||||
if err != nil {
|
||||
t.Fatalf("read golden (run with -update): %v", err)
|
||||
}
|
||||
if got != string(want) {
|
||||
t.Fatalf("output differs from golden:\n--- got ---\n%s\n--- want ---\n%s", got, want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user