Skip to content

Commit dae4139

Browse files
committed
Dummy commit to ensure our changes are stored non-locally.
[skip ci]
1 parent 3a5af1d commit dae4139

File tree

11 files changed

+1305
-31
lines changed

11 files changed

+1305
-31
lines changed

CHANGELOG

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
- 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).
2020
- Added `supports_parsing_integers`, `supports_parsing_floats`, `supports_writing_integers`, and `supports_writing_floats` for our number formats (#215).
2121
- 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).
22-
- Added `NumberFormatBuilder::none()` for create a format with no flags set.
22+
- Added `NumberFormatBuilder::none()` for create a format with no flags set (#215).
23+
- Added many more pre-defined formatting constants (#215).
2324

2425
### Changed
2526

lexical-parse-float/tests/api_tests.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,3 +1343,46 @@ fn require_base_prefix_test() {
13431343
let value = f64::from_lexical_with_options::<SUFFIX>(b"-0d12345", &OPTIONS);
13441344
assert_eq!(value, Err(Error::MissingBaseSuffix(8)));
13451345
}
1346+
1347+
#[test]
1348+
#[cfg(all(feature = "format", feature = "power-of-two"))]
1349+
fn base_prefix_digit_separator_edge_cases_test() {
1350+
use core::num;
1351+
1352+
const OPTIONS: Options = Options::new();
1353+
const NO_PREFIX: u128 = NumberFormatBuilder::new()
1354+
.digit_separator(num::NonZeroU8::new(b'_'))
1355+
.leading_digit_separator(true)
1356+
.build_strict();
1357+
1358+
let value = f64::from_lexical_with_options::<NO_PREFIX>(b"_+12345", &OPTIONS);
1359+
assert_eq!(value, Err(Error::InvalidDigit(1)));
1360+
1361+
let value = f64::from_lexical_with_options::<NO_PREFIX>(b"+_12345", &OPTIONS);
1362+
assert_eq!(value, Ok(12345.0));
1363+
1364+
let value = f64::from_lexical_with_options::<NO_PREFIX>(b"+12345e_+23", &OPTIONS);
1365+
assert_eq!(value, Err(Error::EmptyExponent(8)));
1366+
1367+
let value = f64::from_lexical_with_options::<NO_PREFIX>(b"+12345e+_23", &OPTIONS);
1368+
assert_eq!(value, Ok(1.2345e27));
1369+
1370+
const PREFIX: u128 = NumberFormatBuilder::new()
1371+
.digit_separator(num::NonZeroU8::new(b'_'))
1372+
.base_prefix(num::NonZeroU8::new(b'd'))
1373+
.required_base_prefix(true)
1374+
.leading_digit_separator(true)
1375+
.build_strict();
1376+
1377+
let value = f64::from_lexical_with_options::<PREFIX>(b"_+0d12345", &OPTIONS);
1378+
assert_eq!(value, Err(Error::MissingBasePrefix(1)));
1379+
1380+
let value = f64::from_lexical_with_options::<PREFIX>(b"+_0d12345", &OPTIONS);
1381+
assert_eq!(value, Ok(12345.0));
1382+
1383+
// TODO: This fails
1384+
let value = f64::from_lexical_with_options::<PREFIX>(b"+0d_12345", &OPTIONS);
1385+
assert_eq!(value, Ok(12345.0));
1386+
1387+
// TODO:> Add suffix
1388+
}

lexical-parse-integer/src/algorithm.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,8 +792,7 @@ macro_rules! algorithm {
792792
);
793793
}
794794

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

lexical-parse-integer/tests/api_tests.rs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,3 +447,72 @@ fn require_base_prefix_test() {
447447
let value = u64::from_lexical_with_options::<SUFFIX>(b"0d12345", &OPTIONS);
448448
assert_eq!(value, Err(Error::MissingBaseSuffix(7)));
449449
}
450+
451+
#[test]
452+
#[cfg(all(feature = "format", feature = "power-of-two"))]
453+
fn base_prefix_digit_separator_edge_cases_test() {
454+
use core::num;
455+
456+
const OPTIONS: Options = Options::new();
457+
const NO_PREFIX: u128 = NumberFormatBuilder::new()
458+
.digit_separator(num::NonZeroU8::new(b'_'))
459+
.leading_digit_separator(true)
460+
.build_strict();
461+
462+
let value = i64::from_lexical_with_options::<NO_PREFIX>(b"_+12345", &OPTIONS);
463+
assert_eq!(value, Err(Error::InvalidDigit(1)));
464+
465+
const PREFIX: u128 = NumberFormatBuilder::new()
466+
.digit_separator(num::NonZeroU8::new(b'_'))
467+
.base_prefix(num::NonZeroU8::new(b'd'))
468+
.required_base_prefix(true)
469+
.leading_digit_separator(true)
470+
.build_strict();
471+
472+
let value = i64::from_lexical_with_options::<PREFIX>(b"_+0d12345", &OPTIONS);
473+
assert_eq!(value, Err(Error::MissingBasePrefix(1)));
474+
475+
let value = i64::from_lexical_with_options::<PREFIX>(b"+_0d12345", &OPTIONS);
476+
assert_eq!(value, Ok(12345));
477+
478+
// TODO: This fails: I think this is the correct behavior actually...
479+
// TODO: This is wrong, we should fix this
480+
// TODO: Should migrate `parse_sign` and `parse_base_suffix` to the end...
481+
// TODO: base_prefix_leading_digit_separator
482+
// TODO: base_prefix_internal_digit_separator
483+
// TODO: base_prefix_trailing_digit_separator (identical to
484+
// `integer_leading_digit_separator`)
485+
// TODO: base_prefix_consecutive_digit_separator
486+
// TODO: leading_base_suffix_digit_separator (identical to
487+
// `trailing_digit_separator`, depending on context)
488+
// TODO: internal_base_suffix_digit_separator
489+
// TODO: trailing_base_suffix_digit_separator
490+
// TODO: consecutive_base_suffix_digit_separator
491+
// TODO: integer_sign_digit_separator
492+
// TODO: integer_consecutive_sign_digit_separator
493+
// TODO: exponent_sign_digit_separator
494+
// TODO: exponent_consecutive_sign_digit_separator
495+
// TODO: start_digit_separator (absolute start, can overlap with
496+
// leading_base_prefix_digit_separator or leading_integer_digit_separator
497+
// depending on context)
498+
// TODO: start_consecutive_digit_separator (absolute
499+
// start)
500+
// let value = i64::from_lexical_with_options::<PREFIX>(b"+0d_12345",
501+
// &OPTIONS); assert_eq!(value, Err(Error::InvalidDigit(3)));
502+
//
503+
// // TODO:> Add suffix
504+
//
505+
// // TODO: Need Post-base suffix digit separator
506+
// // This shouldn't be internal I don't think...
507+
//
508+
// const INTERNAL: u128 = NumberFormatBuilder::new()
509+
// .digit_separator(num::NonZeroU8::new(b'_'))
510+
// .base_prefix(num::NonZeroU8::new(b'd'))
511+
// .required_base_prefix(true)
512+
// .internal_digit_separator(true)
513+
// .build_strict();
514+
// let value = i64::from_lexical_with_options::<INTERNAL>(b"+0d_12345",
515+
// &OPTIONS); assert_eq!(value, Err(Error::InvalidDigit(3)));
516+
517+
// TODO: Need
518+
}

0 commit comments

Comments
 (0)