MCPcopy
hub / github.com/tidwall/gjson / TestRandomData

Function TestRandomData

gjson_test.go:20–40  ·  view source on GitHub ↗

TestRandomData is a fuzzing test that throws random data at the Parse function looking for panics.

(t *testing.T)

Source from the content-addressed store, hash-verified

18// TestRandomData is a fuzzing test that throws random data at the Parse
19// function looking for panics.
20func TestRandomData(t *testing.T) {
21 var lstr string
22 defer func() {
23 if v := recover(); v != nil {
24 println("'" + hex.EncodeToString([]byte(lstr)) + "'")
25 println("'" + lstr + "'")
26 panic(v)
27 }
28 }()
29 rand.Seed(time.Now().UnixNano())
30 b := make([]byte, 200)
31 for i := 0; i < 2000000; i++ {
32 n, err := rand.Read(b[:rand.Int()%len(b)])
33 if err != nil {
34 t.Fatal(err)
35 }
36 lstr = string(b[:n])
37 GetBytes([]byte(lstr), "zzzz")
38 Parse(lstr)
39 }
40}
41
42func TestRandomValidStrings(t *testing.T) {
43 rand.Seed(time.Now().UnixNano())

Callers

nothing calls this directly

Calls 3

GetBytesFunction · 0.85
ParseFunction · 0.85
IntMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…