Skip to content

Commit

Permalink
Fix for #66.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexhuszagh committed Sep 3, 2021
1 parent 40680c8 commit 5140eac
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
16 changes: 16 additions & 0 deletions lexical-parse-float/tests/api_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,22 @@ fn base_prefix_and_suffix_test() {
assert!(f64::from_lexical_with_options::<FORMAT>(b"+0x3.0e+300h ", &options).is_err());
}

#[test]
#[cfg(feature = "format")]
fn issue66_test() {
const RUST: u128 = format::RUST_LITERAL;
const JSON: u128 = format::JSON;
const CXX: u128 = format::CXX17_LITERAL;

let options = Options::new();

assert_eq!(f64::from_lexical_with_options::<JSON>(b"42.0", &options), Ok(42.0));
assert_eq!(f64::from_lexical_with_options::<RUST>(b"42.0", &options), Ok(42.0));
assert_eq!(f64::from_lexical_with_options::<RUST>(b"4_2.0", &options), Ok(42.0));
assert_eq!(f64::from_lexical_with_options::<CXX>(b"42.0", &options), Ok(42.0));
assert_eq!(f64::from_lexical_with_options::<CXX>(b"4'2.0", &options), Ok(42.0));
}

fn float_equal<F: Float>(x: F, y: F) -> bool {
if x.is_nan() {
y.is_nan()
Expand Down
2 changes: 1 addition & 1 deletion lexical-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "MIT/Apache-2.0"
name = "lexical-util"
readme = "README.md"
repository = "https://github.com/Alexhuszagh/rust-lexical"
version = "0.8.0"
version = "0.8.1"
exclude = [
"assets/*",
"docs/*",
Expand Down
5 changes: 5 additions & 0 deletions lexical-util/src/skip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,11 @@ impl<'a, const FORMAT: u128> Bytes<'a, FORMAT> {
);
}
self.index += count;
if !Self::IS_CONTIGUOUS {
// Only increment the count if it's not contiguous, otherwise,
// this is an unnecessary performance penalty.
self.count += count;
}
}

/// Advance the byte by 1 element.
Expand Down
9 changes: 9 additions & 0 deletions lexical-util/tests/iterator_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,16 @@ fn skip_iterator_test() {
assert_eq!(iter.is_done(), false);
assert_eq!(iter.length(), 6);
assert_eq!(iter.cursor(), 0);
assert_eq!(iter.current_count(), 0);
unsafe { iter.step_unchecked() };
assert_eq!(iter.cursor(), 1);
assert_eq!(iter.current_count(), 1);
iter.next();
assert_eq!(iter.cursor(), 2);
assert_eq!(iter.current_count(), 2);

let mut byte = digits.bytes::<{ FORMAT }>();
let mut iter = byte.integer_iter();
assert_eq!(unsafe { iter.peek_unchecked() }, &b'1');
assert_eq!(iter.peek(), Some(&b'1'));
assert_eq!(iter.next(), Some(&b'1'));
Expand Down

0 comments on commit 5140eac

Please sign in to comment.