Skip to content

Commit

Permalink
Dummy commit to ensure our changes are stored non-locally.
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
Alexhuszagh committed Jan 14, 2025
1 parent 3a5af1d commit dae4139
Show file tree
Hide file tree
Showing 11 changed files with 1,305 additions and 31 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support for `required_integer_digits_with_exponent`, `required_fraction_digits_with_exponent`, and `required_mantissa_digits_with_exponent`, that is,`1.e5` and `.1e5`, as opposed to just requiring`1e5` (#215).
- Added `supports_parsing_integers`, `supports_parsing_floats`, `supports_writing_integers`, and `supports_writing_floats` for our number formats (#215).
- Added `required_base_prefix` and `required_base_suffix` for our number formats, requiring base prefixes and/or suffixes when parsing, and allowing writing base prefixes and/or suffixes (#215).
- Added `NumberFormatBuilder::none()` for create a format with no flags set.
- Added `NumberFormatBuilder::none()` for create a format with no flags set (#215).
- Added many more pre-defined formatting constants (#215).

### Changed

Expand Down
43 changes: 43 additions & 0 deletions lexical-parse-float/tests/api_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1343,3 +1343,46 @@ fn require_base_prefix_test() {
let value = f64::from_lexical_with_options::<SUFFIX>(b"-0d12345", &OPTIONS);
assert_eq!(value, Err(Error::MissingBaseSuffix(8)));
}

#[test]
#[cfg(all(feature = "format", feature = "power-of-two"))]
fn base_prefix_digit_separator_edge_cases_test() {
use core::num;

const OPTIONS: Options = Options::new();
const NO_PREFIX: u128 = NumberFormatBuilder::new()
.digit_separator(num::NonZeroU8::new(b'_'))
.leading_digit_separator(true)
.build_strict();

let value = f64::from_lexical_with_options::<NO_PREFIX>(b"_+12345", &OPTIONS);
assert_eq!(value, Err(Error::InvalidDigit(1)));

let value = f64::from_lexical_with_options::<NO_PREFIX>(b"+_12345", &OPTIONS);
assert_eq!(value, Ok(12345.0));

let value = f64::from_lexical_with_options::<NO_PREFIX>(b"+12345e_+23", &OPTIONS);
assert_eq!(value, Err(Error::EmptyExponent(8)));

let value = f64::from_lexical_with_options::<NO_PREFIX>(b"+12345e+_23", &OPTIONS);
assert_eq!(value, Ok(1.2345e27));

const PREFIX: u128 = NumberFormatBuilder::new()
.digit_separator(num::NonZeroU8::new(b'_'))
.base_prefix(num::NonZeroU8::new(b'd'))
.required_base_prefix(true)
.leading_digit_separator(true)
.build_strict();

let value = f64::from_lexical_with_options::<PREFIX>(b"_+0d12345", &OPTIONS);
assert_eq!(value, Err(Error::MissingBasePrefix(1)));

let value = f64::from_lexical_with_options::<PREFIX>(b"+_0d12345", &OPTIONS);
assert_eq!(value, Ok(12345.0));

// TODO: This fails
let value = f64::from_lexical_with_options::<PREFIX>(b"+0d_12345", &OPTIONS);
assert_eq!(value, Ok(12345.0));

// TODO:> Add suffix
}
3 changes: 1 addition & 2 deletions lexical-parse-integer/src/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,8 +792,7 @@ macro_rules! algorithm {
);
}

#[cfg(all(feature = "format", feature = "power-of-two"))]
if format.required_base_suffix() && !has_suffix {
if cfg!(all(feature = "format", feature = "power-of-two")) && format.required_base_suffix() && !has_suffix {
return Err(Error::MissingBaseSuffix(iter.cursor()));
}

Expand Down
69 changes: 69 additions & 0 deletions lexical-parse-integer/tests/api_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,72 @@ fn require_base_prefix_test() {
let value = u64::from_lexical_with_options::<SUFFIX>(b"0d12345", &OPTIONS);
assert_eq!(value, Err(Error::MissingBaseSuffix(7)));
}

#[test]
#[cfg(all(feature = "format", feature = "power-of-two"))]
fn base_prefix_digit_separator_edge_cases_test() {
use core::num;

const OPTIONS: Options = Options::new();
const NO_PREFIX: u128 = NumberFormatBuilder::new()
.digit_separator(num::NonZeroU8::new(b'_'))
.leading_digit_separator(true)
.build_strict();

let value = i64::from_lexical_with_options::<NO_PREFIX>(b"_+12345", &OPTIONS);
assert_eq!(value, Err(Error::InvalidDigit(1)));

const PREFIX: u128 = NumberFormatBuilder::new()
.digit_separator(num::NonZeroU8::new(b'_'))
.base_prefix(num::NonZeroU8::new(b'd'))
.required_base_prefix(true)
.leading_digit_separator(true)
.build_strict();

let value = i64::from_lexical_with_options::<PREFIX>(b"_+0d12345", &OPTIONS);
assert_eq!(value, Err(Error::MissingBasePrefix(1)));

let value = i64::from_lexical_with_options::<PREFIX>(b"+_0d12345", &OPTIONS);
assert_eq!(value, Ok(12345));

// TODO: This fails: I think this is the correct behavior actually...
// TODO: This is wrong, we should fix this
// TODO: Should migrate `parse_sign` and `parse_base_suffix` to the end...
// TODO: base_prefix_leading_digit_separator
// TODO: base_prefix_internal_digit_separator
// TODO: base_prefix_trailing_digit_separator (identical to
// `integer_leading_digit_separator`)
// TODO: base_prefix_consecutive_digit_separator
// TODO: leading_base_suffix_digit_separator (identical to
// `trailing_digit_separator`, depending on context)
// TODO: internal_base_suffix_digit_separator
// TODO: trailing_base_suffix_digit_separator
// TODO: consecutive_base_suffix_digit_separator
// TODO: integer_sign_digit_separator
// TODO: integer_consecutive_sign_digit_separator
// TODO: exponent_sign_digit_separator
// TODO: exponent_consecutive_sign_digit_separator
// TODO: start_digit_separator (absolute start, can overlap with
// leading_base_prefix_digit_separator or leading_integer_digit_separator
// depending on context)
// TODO: start_consecutive_digit_separator (absolute
// start)
// let value = i64::from_lexical_with_options::<PREFIX>(b"+0d_12345",
// &OPTIONS); assert_eq!(value, Err(Error::InvalidDigit(3)));
//
// // TODO:> Add suffix
//
// // TODO: Need Post-base suffix digit separator
// // This shouldn't be internal I don't think...
//
// const INTERNAL: u128 = NumberFormatBuilder::new()
// .digit_separator(num::NonZeroU8::new(b'_'))
// .base_prefix(num::NonZeroU8::new(b'd'))
// .required_base_prefix(true)
// .internal_digit_separator(true)
// .build_strict();
// let value = i64::from_lexical_with_options::<INTERNAL>(b"+0d_12345",
// &OPTIONS); assert_eq!(value, Err(Error::InvalidDigit(3)));

// TODO: Need
}
Loading

0 comments on commit dae4139

Please sign in to comment.