-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathencode_fuzz_test.go
52 lines (48 loc) · 1008 Bytes
/
encode_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
package yaml_test
import (
"testing"
"unicode/utf8"
)
func FuzzEncodeDecodeString(f *testing.F) {
var collectStrings func(f *testing.F, input any)
collectStrings = func(f *testing.F, input any) {
switch input := input.(type) {
case nil:
return
case string:
if utf8.ValidString(input) {
f.Add(input)
}
case map[string]any:
for _, v := range input {
collectStrings(f, v)
}
case map[string]string:
for _, v := range input {
collectStrings(f, v)
}
case []any:
for _, v := range input {
collectStrings(f, v)
}
case []string:
for _, v := range input {
collectStrings(f, v)
}
}
}
collectStrings(f, encodeDecodeStringTests)
for _, tt := range marshalTests {
collectStrings(f, tt.value)
}
for _, tt := range unmarshalTests {
collectStrings(f, tt.value)
}
f.Fuzz(func(t *testing.T, input string) {
if !utf8.ValidString(input) {
t.Skipf("Invalid UTF8 string: %q", input)
return
}
testEncodeDecodeString(t, input)
})
}