============================================================================= 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)
| 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. |
| 555 | func 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). |
no test coverage detected