checkNumericOracle cross-checks jsonparser's ParseInt/ParseFloat against the strconv reference (the NUMERIC-ORACLE gate). strconv is the reference implementation per the Go specification; disagreements indicate either a parser bug or a token where jsonparser and strconv legitimately disagree on acce
(t *testing.T, val []byte)
| 1434 | // parser bug or a token where jsonparser and strconv legitimately disagree |
| 1435 | // on accepted syntax (both are worth surfacing). |
| 1436 | func checkNumericOracle(t *testing.T, val []byte) { |
| 1437 | t.Helper() |
| 1438 | |
| 1439 | // ParseInt cross-check (only for integer-looking tokens). |
| 1440 | isInt := len(val) > 0 |
| 1441 | for _, b := range val { |
| 1442 | if (b < '0' || b > '9') && b != '-' && b != '+' { |
| 1443 | isInt = false |
| 1444 | break |
| 1445 | } |
| 1446 | } |
| 1447 | if isInt { |
| 1448 | jVal, jErr := ParseInt(val) |
| 1449 | sVal, sErr := strconv.ParseInt(string(val), 10, 64) |
| 1450 | if (jErr == nil) != (sErr == nil) { |
| 1451 | t.Errorf("ParseInt disagreement on %q: jsonparser=(%d,%v) strconv=(%d,%v)", |
| 1452 | val, jVal, jErr, sVal, sErr) |
| 1453 | } else if jErr == nil && jVal != sVal { |
| 1454 | t.Errorf("ParseInt value mismatch on %q: jsonparser=%d strconv=%d", |
| 1455 | val, jVal, sVal) |
| 1456 | } |
| 1457 | } |
| 1458 | |
| 1459 | // ParseFloat cross-check (all numeric tokens). |
| 1460 | jfVal, jfErr := ParseFloat(val) |
| 1461 | sfVal, sfErr := strconv.ParseFloat(string(val), 64) |
| 1462 | if (jfErr == nil) != (sfErr == nil) { |
| 1463 | t.Errorf("ParseFloat disagreement on %q: jsonparser=(%f,%v) strconv=(%f,%v)", |
| 1464 | val, jfVal, jfErr, sfVal, sfErr) |
| 1465 | } else if jfErr == nil && jfVal != sfVal { |
| 1466 | t.Errorf("ParseFloat value mismatch on %q: jsonparser=%f strconv=%f", |
| 1467 | val, jfVal, sfVal) |
| 1468 | } |
| 1469 | } |
| 1470 | |
| 1471 | // ============================================================================= |
| 1472 | // The fuzzer (testing.F, native go-fuzz) |
no test coverage detected