From 1fefff4fcc1f66c5dc20ff983dfe6eb06c78e26e Mon Sep 17 00:00:00 2001 From: mag123c Date: Tue, 14 Jul 2026 21:58:08 +0900 Subject: [PATCH] Add approx large-integer overflow/boundary test coverage Mirrors the correct-parser long_int_boundaries coverage for the approx-number-parsing feature: exercises the cold parse_large_integer path at its i64::MIN / u64::MAX success boundaries and the Overflow errors just past them. The overflow assertions are gated to the case where neither 128bit (wider target) nor big-int-as-float (float reinterpretation) is enabled. Addresses simd-lite/simd-json#89. --- src/numberparse/approx.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/numberparse/approx.rs b/src/numberparse/approx.rs index f9706e24..457757eb 100644 --- a/src/numberparse/approx.rs +++ b/src/numberparse/approx.rs @@ -749,4 +749,30 @@ mod test { assert!(to_value_from_str("[1e]").is_err()); assert!(to_value_from_str("[9e-]").is_err()); } + + #[test] + fn long_int_boundaries() -> Result<(), crate::Error> { + // 18/19-digit integers take the cold `parse_large_integer` path; check + // its success boundaries and the Overflow errors just past them. + assert_eq!( + to_value_from_str("-999999999999999999")?, + -999_999_999_999_999_999_i64 + ); + assert_eq!( + to_value_from_str("-9223372036854775807")?, + -9_223_372_036_854_775_807_i64 + ); + assert_eq!(to_value_from_str("-9223372036854775808")?, i64::MIN); + assert_eq!(to_value_from_str("18446744073709551615")?, u64::MAX); + // Without a wider integer target, values past i64::MIN / u64::MAX overflow. + // `128bit` widens the target and `big-int-as-float` reinterprets them, so + // the error only holds when neither is enabled. + #[cfg(not(any(feature = "128bit", feature = "big-int-as-float")))] + { + assert!(to_value_from_str("-9223372036854775809").is_err()); + assert!(to_value_from_str("18446744073709551616").is_err()); + assert!(to_value_from_str("99999999999999999999").is_err()); + } + Ok(()) + } }