gitstack

grindlemire/go-tui code browser

919 B Go 52 lines 2026-03-21 · 197a626 raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package tuigen

import (
	"testing"
)

func FuzzLexer(f *testing.F) {
	// Seed with valid .gsx snippets
	f.Add([]byte(`package test
templ Hello() {
	<div>Hello</div>
}
`))
	f.Add([]byte(`package test
templ X(a int, b string) {
	<span class="font-bold">{a}</span>
}
`))
	f.Add([]byte(`package test
templ Loop(items []string) {
	for _, item := range items {
		<span>{item}</span>
	}
}
`))

	f.Fuzz(func(t *testing.T, data []byte) {
		lexer := NewLexer("fuzz.gsx", string(data))
		// Should not panic
		for {
			tok := lexer.Next()
			if tok.Type == TokenEOF || tok.Type == TokenError {
				break
			}
		}
	})
}

func FuzzParser(f *testing.F) {
	f.Add([]byte(`package test
templ Hello() {
	<div>Hello</div>
}
`))

	f.Fuzz(func(t *testing.T, data []byte) {
		lexer := NewLexer("fuzz.gsx", string(data))
		parser := NewParser(lexer)
		// Should not panic — may return errors, that's fine
		_, _ = parser.ParseFile()
	})
}