compareNumberParsing cross-checks jsonparser.ParseInt/ParseFloat against encoding/json's json.Number (the canonical reference).
(t *testing.T, token, fullData []byte)
| 580 | // compareNumberParsing cross-checks jsonparser.ParseInt/ParseFloat against |
| 581 | // encoding/json's json.Number (the canonical reference). |
| 582 | func compareNumberParsing(t *testing.T, token, fullData []byte) { |
| 583 | t.Helper() |
| 584 | ref := json.Number(token) |
| 585 | |
| 586 | // --- ParseFloat cross-check --- |
| 587 | // NOTE: jsonparser.ParseFloat delegates to strconv.ParseFloat, the same |
| 588 | // function json.Number.Float64 uses. This comparison is therefore |
| 589 | // effectively tautological — it is retained to validate that token |
| 590 | // extraction produced a float-parseable string and to guard against any |
| 591 | // future divergence in jsonparser's float path. |
| 592 | jpF, jpFErr := ParseFloat(token) |
| 593 | stdF, stdFErr := ref.Float64() |
| 594 | if (jpFErr == nil) != (stdFErr == nil) { |
| 595 | t.Errorf("Gate G: ParseFloat disagreement on token %q (from data=%s): "+ |
| 596 | "jsonparser=(%v,%v) stdlib=(%v,%v)", |
| 597 | token, truncateForMsg(fullData), jpF, jpFErr, stdF, stdFErr) |
| 598 | } else if jpFErr == nil && jpF != stdF { |
| 599 | t.Errorf("Gate G: ParseFloat value mismatch on token %q (from data=%s): "+ |
| 600 | "jsonparser=%v stdlib=%v", |
| 601 | token, truncateForMsg(fullData), jpF, stdF) |
| 602 | } |
| 603 | |
| 604 | // --- ParseInt cross-check --- |
| 605 | // This is the REAL differential test: jsonparser.parseInt (bytes.go) is |
| 606 | // a hand-rolled implementation independent of strconv.ParseInt. |
| 607 | jpI, jpIErr := ParseInt(token) |
| 608 | stdI, stdIErr := ref.Int64() |
| 609 | if (jpIErr == nil) != (stdIErr == nil) { |
| 610 | t.Errorf("Gate G: ParseInt disagreement on token %q (from data=%s): "+ |
| 611 | "jsonparser=(%d,%v) stdlib=(%d,%v)", |
| 612 | token, truncateForMsg(fullData), jpI, jpIErr, stdI, stdIErr) |
| 613 | } else if jpIErr == nil && jpI != stdI { |
| 614 | t.Errorf("Gate G: ParseInt value mismatch on token %q (from data=%s): "+ |
| 615 | "jsonparser=%d stdlib=%d", |
| 616 | token, truncateForMsg(fullData), jpI, stdI) |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | // ============================================================================= |
| 621 | // Gate runner (runs Gates A–G on a single input) |
no test coverage detected