MCPcopy Create free account
hub / github.com/buger/jsonparser / runMarshalDeterminismGate

Function runMarshalDeterminismGate

encoding_json_fuzz_test.go:509–532  ·  view source on GitHub ↗

============================================================================= Gate I: Marshal determinism on round-tripped values ============================================================================= encoding/json's Marshal uses sorted map iteration (since Go 1.12), so the same value should

(t *testing.T, data []byte)

Source from the content-addressed store, hash-verified

507// differential surface.
508
509func runMarshalDeterminismGate(t *testing.T, data []byte) {
510 t.Helper()
511 if !json.Valid(data) {
512 return
513 }
514 var v interface{}
515 dec := json.NewDecoder(bytes.NewReader(data))
516 dec.UseNumber()
517 if err := dec.Decode(&v); err != nil {
518 return
519 }
520 encodingJSONNoPanic(t, "MarshalDeterminism/Marshal1", data, func() {
521 b1, e1 := json.Marshal(v)
522 b2, e2 := json.Marshal(v)
523 if e1 != nil || e2 != nil {
524 return
525 }
526 if !bytes.Equal(b1, b2) {
527 t.Errorf("Gate I: Marshal non-deterministic on value from %s: "+
528 "b1=%s b2=%s (DETERMINISM violation)",
529 truncateForMsg(data), truncateForMsg(b1), truncateForMsg(b2))
530 }
531 })
532}
533
534// =============================================================================
535// Gate G: Differential — jsonparser vs encoding/json number parsing

Callers 1

runEncodingJSONGatesFunction · 0.85

Calls 2

encodingJSONNoPanicFunction · 0.85
truncateForMsgFunction · 0.85

Tested by

no test coverage detected