-
Notifications
You must be signed in to change notification settings - Fork 18
/
fuzz_test.go
71 lines (67 loc) · 1.12 KB
/
fuzz_test.go
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package css
import (
"strings"
"testing"
"golang.org/x/net/html"
)
func FuzzParse(f *testing.F) {
corpus := []string{
"*",
"a",
"ns|a",
".red",
"#demo",
"[attr]",
"[attr=value]",
"[herf~=foo]",
"[herf|=foo]",
"[herf^=foo]",
"[herf$=foo]",
"[herf*=foo]",
"[herf=foo i]",
"h1 a",
"h1, a",
"h1 > a",
"h1 ~ a",
"h1 + a",
"h1:empty",
"h1:first-child",
"h1:first-of-type",
"h1:last-child",
"h1:last-of-type",
"h1:only-child",
"h1:only-of-type",
"h1:root",
"h1:nth-child(1n + 3)",
"h1:nth-child(odd)",
"h1:nth-child(even)",
"h1:nth-child(1n)",
"h1:nth-child(3)",
"h1:nth-child(+3)",
"h1:last-child(1n + 3)",
"h1:last-of-type(1n + 3)",
"h1:nth-of-type(1n + 3)",
}
for _, s := range corpus {
f.Add(s)
}
f.Fuzz(func(t *testing.T, s string) {
Parse(s)
})
}
func FuzzSelector(f *testing.F) {
for _, test := range selectorTests {
f.Add(test.sel, test.in)
}
f.Fuzz(func(t *testing.T, sel, in string) {
s, err := Parse(sel)
if err != nil {
t.Skip()
}
root, err := html.Parse(strings.NewReader(in))
if err != nil {
t.Skip()
}
s.Select(root)
})
}