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

Function runDifferentialGate

encoding_json_fuzz_test.go:555–578  ·  view source on GitHub ↗

============================================================================= Gate G: Differential — jsonparser vs encoding/json number parsing ============================================================================= runDifferentialGate feeds the SAME number token to both jsonparser's ParseInt/

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

Source from the content-addressed store, hash-verified

553// For VALID JSON number tokens, the two implementations MUST agree. Any
554// disagreement here is a real bug in jsonparser OR in encoding/json.
555func runDifferentialGate(t *testing.T, data []byte) {
556 t.Helper()
557 if !json.Valid(data) {
558 return
559 }
560 encodingJSONNoPanic(t, "Differential", data, func() {
561 // Root scalar number.
562 if val, dt, _, err := Get(data); err == nil && dt == Number && len(val) > 0 {
563 compareNumberParsing(t, val, data)
564 }
565 // Object value at a common key.
566 if val, dt, _, err := Get(data, "a"); err == nil && dt == Number && len(val) > 0 {
567 compareNumberParsing(t, val, data)
568 }
569 // Each element of a root array.
570 if containerIs(data, '[') {
571 _, _ = ArrayEach(data, func(value []byte, vt ValueType, off int, err error) {
572 if vt == Number && len(value) > 0 {
573 compareNumberParsing(t, value, data)
574 }
575 })
576 }
577 })
578}
579
580// compareNumberParsing cross-checks jsonparser.ParseInt/ParseFloat against
581// encoding/json's json.Number (the canonical reference).

Callers 1

runEncodingJSONGatesFunction · 0.85

Calls 5

encodingJSONNoPanicFunction · 0.85
GetFunction · 0.85
compareNumberParsingFunction · 0.85
containerIsFunction · 0.85
ArrayEachFunction · 0.85

Tested by

no test coverage detected