-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathfuzz_test.go
More file actions
49 lines (46 loc) · 800 Bytes
/
fuzz_test.go
File metadata and controls
49 lines (46 loc) · 800 Bytes
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
package jscan_test
import (
"encoding/json"
"testing"
"github.com/romshark/jscan/v2"
)
func FuzzValid(f *testing.F) {
for _, s := range []string{
``,
`0`,
`42`,
`3.14159`,
`null`,
`false`,
`true`,
`{"\"escaped_key\"":"\"escaped_value\""}`,
`[]`,
`[1]`,
`[null, 1, 3 , 3.14159]`,
"{}",
`{"foo": "bar"}`,
`"foo"`,
`"{"`,
`"{}"`,
} {
f.Add(s)
}
f.Fuzz(func(t *testing.T, data string) {
var (
std = json.Valid([]byte(data))
jscanBytes = jscan.Valid([]byte(data))
jscanStr = jscan.Valid(data)
)
if std != jscanStr {
t.Fatalf(
`Valid(%q): %t (std) != %t (jscanStr)`,
data, std, jscanStr,
)
} else if std != jscanBytes {
t.Fatalf(
`Valid(%q): %t (std) != %t (jscanBytes)`,
data, std, jscanBytes,
)
}
})
}