diff --git a/lexical-parse-integer/src/shared.rs b/lexical-parse-integer/src/shared.rs index 41e3ca41..fff53f58 100644 --- a/lexical-parse-integer/src/shared.rs +++ b/lexical-parse-integer/src/shared.rs @@ -86,6 +86,8 @@ macro_rules! invalid_digit_partial { } else { into_error!(Overflow, (count - 1).min(min + 1)) } + } else if <$t>::IS_SIGNED && $is_negative { + into_ok_partial!($value.wrapping_neg(), $iter.cursor() - 1) } else { into_ok_partial!($value, $iter.cursor() - 1) } diff --git a/lexical-parse-integer/tests/api_tests.rs b/lexical-parse-integer/tests/api_tests.rs index 58380f92..329b244f 100644 --- a/lexical-parse-integer/tests/api_tests.rs +++ b/lexical-parse-integer/tests/api_tests.rs @@ -28,6 +28,11 @@ fn i8_decimal_test() { assert_eq!(Err(Error::Overflow(2)), i8::from_lexical(b"255")); assert_eq!(Ok(-1), i8::from_lexical(b"-1")); assert_eq!(Err(Error::InvalidDigit(1)), i8::from_lexical(b"1a")); + + assert_eq!(Ok((1, 1)), i8::from_lexical_partial(b"1")); + assert_eq!(Ok((1, 1)), i8::from_lexical_partial(b"1a")); + assert_eq!(Ok((-1, 2)), i8::from_lexical_partial(b"-1")); + assert_eq!(Ok((-1, 2)), i8::from_lexical_partial(b"-1a")); } #[test]