MCPcopy
hub / github.com/pquerna/ffjson / testTypeFuzzN

Function testTypeFuzzN

tests/fuzz_test.go:406–433  ·  view source on GitHub ↗

Fuzz test for N iterations

(t *testing.T, base interface{}, ff interface{}, n int)

Source from the content-addressed store, hash-verified

404
405// Fuzz test for N iterations
406func testTypeFuzzN(t *testing.T, base interface{}, ff interface{}, n int) {
407 require.Implements(t, (*json.Marshaler)(nil), ff)
408 require.Implements(t, (*json.Unmarshaler)(nil), ff)
409 require.Implements(t, (*marshalerFaster)(nil), ff)
410 require.Implements(t, (*unmarshalFaster)(nil), ff)
411
412 if _, ok := base.(unmarshalFaster); ok {
413 require.FailNow(t, "base should not have a UnmarshalJSONFFLexer")
414 }
415
416 if _, ok := base.(marshalerFaster); ok {
417 require.FailNow(t, "base should not have a MarshalJSONBuf")
418 }
419
420 f := fuzz.New()
421 f.NumElements(0, 1+n/40)
422 f.NilChance(0.2)
423 f.Funcs(fuzzTime, fuzzTimeSlice)
424 for i := 0; i < n; i++ {
425 f.RandSource(rand.New(rand.NewSource(int64(i * 5275))))
426 f.Fuzz(base)
427 f.RandSource(rand.New(rand.NewSource(int64(i * 5275))))
428 f.Fuzz(ff)
429
430 testSameMarshal(t, base, ff)
431 testCycle(t, base, ff)
432 }
433}
434
435func TestFuzzArray(t *testing.T) {
436 testTypeFuzz(t, &Tarray{X: [3]int{}}, &Xarray{X: [3]int{}})

Callers 3

testTypeFuzzFunction · 0.85
TestFuzzInlineStructsFunction · 0.85
TestFuzzReTypeFunction · 0.85

Calls 2

testSameMarshalFunction · 0.85
testCycleFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…