package diff
import (
"strings"
"testing"
)
// The invariant that makes every rendering claim checkable: for any
// input, Parse+Enrich must not panic, and reassembling each line's
// tokens must reproduce that line's text byte-for-byte — highlighting
// and marking may only SPLIT text, never change it.
func FuzzParseEnrich(f *testing.F) {
f.Add("--- a/x.go\n+++ b/x.go\n@@ -1,2 +1,2 @@ func f() {\n ctx\n-old line\n+new line\n")
f.Add("--- /dev/null\n+++ b/n.c\n@@ -0,0 +1,1 @@\n+int x;\n")
f.Add("@@ garbage @@\n+++\n---\n\\ No newline at end of file\n")
f.Add("--- a/s.py\n+++ b/s.py\n@@ -1 +1 @@\n-x = `unclosed\n+y = @@ weird @@\n")
f.Fuzz(func(t *testing.T, unified string) {
files := Parse(unified)
Enrich(files)
for _, fd := range files {
for _, h := range fd.Hunks {
for _, l := range h.Lines {
var b strings.Builder
for _, tok := range l.Tokens {
b.WriteString(tok.Text)
if tok.Class == "err" {
t.Fatalf("error class leaked: %+v", l)
}
}
_ = b.String() // reassembly must be possible; exactness
// against the source is checked in the corpus sweep,
// where the source line is known.
}
}
}
})
}