Skip to content

Commit

Permalink
Improve the documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexhuszagh committed Sep 21, 2024
1 parent ed7a0a7 commit c6aedf7
Show file tree
Hide file tree
Showing 6 changed files with 360 additions and 54 deletions.
51 changes: 38 additions & 13 deletions lexical-parse-integer/tests/issue_96_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ fn issue_96_i_test() {

// TODO: This is oddly failing on floats

let result = i64::from_lexical_partial_with_options::<FMT>(b"_", &opts);
assert_eq!(result, Ok((0, 0)));

let result = i64::from_lexical_partial_with_options::<FMT>(b"+_", &opts);
assert_eq!(result, Ok((0, 1)));

let result = i64::from_lexical_partial_with_options::<FMT>(b"_1_", &opts);
assert_eq!(result, Ok((0, 0)));

let result = i64::from_lexical_partial_with_options::<FMT>(b"_1_23", &opts);
assert_eq!(result, Ok((0, 0)));

Expand Down Expand Up @@ -102,6 +111,12 @@ fn issue_96_l_test() {
.consecutive_digit_separator(false)
.build();

let result = i64::from_lexical_partial_with_options::<FMT>(b"_", &opts);
assert_eq!(result, Ok((0, 1)));

let result = i64::from_lexical_partial_with_options::<FMT>(b"+_", &opts);
assert_eq!(result, Ok((0, 2)));

let result = i64::from_lexical_partial_with_options::<FMT>(b"_1_23", &opts);
assert_eq!(result, Ok((1, 2)));

Expand All @@ -127,6 +142,12 @@ fn issue_96_t_test() {
.consecutive_digit_separator(false)
.build();

let result = i64::from_lexical_partial_with_options::<FMT>(b"_", &opts);
assert_eq!(result, Ok((0, 1)));

let result = i64::from_lexical_partial_with_options::<FMT>(b"+_", &opts);
assert_eq!(result, Ok((0, 2)));

let result = i64::from_lexical_partial_with_options::<FMT>(b"_1_23", &opts);
assert_eq!(result, Ok((0, 0)));

Expand Down Expand Up @@ -159,21 +180,25 @@ fn issue_96_il_test() {
.consecutive_digit_separator(false)
.build();

// TODO: Restore
// let result = i64::from_lexical_partial_with_options::<FMT>(b"_1_23", &opts);
// assert_eq!(result, Ok((123, 5)));
//
// let result = i64::from_lexical_partial_with_options::<FMT>(b"+_1_23", &opts);
// assert_eq!(result, Ok((123, 6)));
//
// let result = i64::from_lexical_partial_with_options::<FMT>(b"1__1_23", &opts);
// assert_eq!(result, Ok((1, 1)));
//
// let result = i64::from_lexical_partial_with_options::<FMT>(b"1_1", &opts);
// assert_eq!(result, Ok((11, 3)));
let result = i64::from_lexical_partial_with_options::<FMT>(b"_", &opts);
assert_eq!(result, Ok((0, 1)));

let result = i64::from_lexical_partial_with_options::<FMT>(b"+_", &opts);
assert_eq!(result, Ok((0, 2)));

let result = i64::from_lexical_partial_with_options::<FMT>(b"_1_23", &opts);
assert_eq!(result, Ok((123, 5)));

let result = i64::from_lexical_partial_with_options::<FMT>(b"+_1_23", &opts);
assert_eq!(result, Ok((123, 6)));

let result = i64::from_lexical_partial_with_options::<FMT>(b"1__1_23", &opts);
assert_eq!(result, Ok((1, 1)));

let result = i64::from_lexical_partial_with_options::<FMT>(b"1_1", &opts);
assert_eq!(result, Ok((11, 3)));

let result = i64::from_lexical_partial_with_options::<FMT>(b"1_1_", &opts);
// TODO: This got it wrong
assert_eq!(result, Ok((11, 3)));

let result = i64::from_lexical_partial_with_options::<FMT>(b"_+1_23", &opts);
Expand Down
80 changes: 80 additions & 0 deletions lexical-util/src/feature_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -947,108 +947,188 @@ impl<const FORMAT: u128> NumberFormat<FORMAT> {
// DIGIT SEPARATOR FLAGS & MASKS

// If digit separators are allowed between integer digits.
///
/// This will not consider an input of only the digit separator
/// to be a valid separator: the digit separator must be surrounded by
/// digits.
pub const INTEGER_INTERNAL_DIGIT_SEPARATOR: bool = from_flag!(FORMAT, INTEGER_INTERNAL_DIGIT_SEPARATOR);

/// Get if digit separators are allowed between integer digits.
///
/// This will not consider an input of only the digit separator
/// to be a valid separator: the digit separator must be surrounded by
/// digits.
#[inline(always)]
pub const fn integer_internal_digit_separator(&self) -> bool {
Self::INTEGER_INTERNAL_DIGIT_SEPARATOR
}

/// If digit separators are allowed between fraction digits.
///
/// This will not consider an input of only the digit separator
/// to be a valid separator: the digit separator must be surrounded by
/// digits.
pub const FRACTION_INTERNAL_DIGIT_SEPARATOR: bool = from_flag!(FORMAT, FRACTION_INTERNAL_DIGIT_SEPARATOR);

/// Get if digit separators are allowed between fraction digits.
///
/// This will not consider an input of only the digit separator
/// to be a valid separator: the digit separator must be surrounded by
/// digits.
#[inline(always)]
pub const fn fraction_internal_digit_separator(&self) -> bool {
Self::FRACTION_INTERNAL_DIGIT_SEPARATOR
}

/// If digit separators are allowed between exponent digits.
///
/// This will not consider an input of only the digit separator
/// to be a valid separator: the digit separator must be surrounded by
/// digits.
pub const EXPONENT_INTERNAL_DIGIT_SEPARATOR: bool = from_flag!(FORMAT, EXPONENT_INTERNAL_DIGIT_SEPARATOR);

/// Get if digit separators are allowed between exponent digits.
///
/// This will not consider an input of only the digit separator
/// to be a valid separator: the digit separator must be surrounded by
/// digits.
#[inline(always)]
pub const fn exponent_internal_digit_separator(&self) -> bool {
Self::EXPONENT_INTERNAL_DIGIT_SEPARATOR
}

/// If digit separators are allowed between digits.
///
/// This will not consider an input of only the digit separator
/// to be a valid separator: the digit separator must be surrounded by
/// digits.
pub const INTERNAL_DIGIT_SEPARATOR: bool = from_flag!(FORMAT, INTERNAL_DIGIT_SEPARATOR);

/// Get if digit separators are allowed between digits.
///
/// This will not consider an input of only the digit separator
/// to be a valid separator: the digit separator must be surrounded by
/// digits.
#[inline(always)]
pub const fn internal_digit_separator(&self) -> bool {
Self::INTERNAL_DIGIT_SEPARATOR
}

/// If a digit separator is allowed before any integer digits.
///
/// This will consider an input of only the digit separator
/// to be a identical to empty input.
pub const INTEGER_LEADING_DIGIT_SEPARATOR: bool = from_flag!(FORMAT, INTEGER_LEADING_DIGIT_SEPARATOR);

/// Get if a digit separator is allowed before any integer digits.
///
/// This will consider an input of only the digit separator
/// to be a identical to empty input.
#[inline(always)]
pub const fn integer_leading_digit_separator(&self) -> bool {
Self::INTEGER_LEADING_DIGIT_SEPARATOR
}

/// If a digit separator is allowed before any integer digits.
///
/// This will consider an input of only the digit separator
/// to be a identical to empty input.
pub const FRACTION_LEADING_DIGIT_SEPARATOR: bool = from_flag!(FORMAT, FRACTION_LEADING_DIGIT_SEPARATOR);

/// Get if a digit separator is allowed before any fraction digits.
///
/// This will consider an input of only the digit separator
/// to be a identical to empty input.
#[inline(always)]
pub const fn fraction_leading_digit_separator(&self) -> bool {
Self::FRACTION_LEADING_DIGIT_SEPARATOR
}

/// If a digit separator is allowed before any exponent digits.
///
/// This will consider an input of only the digit separator
/// to be a identical to empty input.
pub const EXPONENT_LEADING_DIGIT_SEPARATOR: bool = from_flag!(FORMAT, EXPONENT_LEADING_DIGIT_SEPARATOR);

/// Get if a digit separator is allowed before any exponent digits.
///
/// This will consider an input of only the digit separator
/// to be a identical to empty input.
#[inline(always)]
pub const fn exponent_leading_digit_separator(&self) -> bool {
Self::EXPONENT_LEADING_DIGIT_SEPARATOR
}

/// If a digit separator is allowed before any digits.
///
/// This will consider an input of only the digit separator
/// to be a identical to empty input.
pub const LEADING_DIGIT_SEPARATOR: bool = from_flag!(FORMAT, LEADING_DIGIT_SEPARATOR);

/// Get if a digit separator is allowed before any digits.
///
/// This will consider an input of only the digit separator
/// to be a identical to empty input.
#[inline(always)]
pub const fn leading_digit_separator(&self) -> bool {
Self::LEADING_DIGIT_SEPARATOR
}

/// If a digit separator is allowed after any integer digits.
///
/// This will consider an input of only the digit separator
/// to be a identical to empty input.
pub const INTEGER_TRAILING_DIGIT_SEPARATOR: bool = from_flag!(FORMAT, INTEGER_TRAILING_DIGIT_SEPARATOR);

/// Get if a digit separator is allowed after any integer digits.
///
/// This will consider an input of only the digit separator
/// to be a identical to empty input.
#[inline(always)]
pub const fn integer_trailing_digit_separator(&self) -> bool {
Self::INTEGER_TRAILING_DIGIT_SEPARATOR
}

/// If a digit separator is allowed after any fraction digits.
///
/// This will consider an input of only the digit separator
/// to be a identical to empty input.
pub const FRACTION_TRAILING_DIGIT_SEPARATOR: bool = from_flag!(FORMAT, FRACTION_TRAILING_DIGIT_SEPARATOR);

/// Get if a digit separator is allowed after any fraction digits.
///
/// This will consider an input of only the digit separator
/// to be a identical to empty input.
#[inline(always)]
pub const fn fraction_trailing_digit_separator(&self) -> bool {
Self::FRACTION_TRAILING_DIGIT_SEPARATOR
}

/// If a digit separator is allowed after any exponent digits.
///
/// This will consider an input of only the digit separator
/// to be a identical to empty input.
pub const EXPONENT_TRAILING_DIGIT_SEPARATOR: bool = from_flag!(FORMAT, EXPONENT_TRAILING_DIGIT_SEPARATOR);

/// Get if a digit separator is allowed after any exponent digits.
///
/// This will consider an input of only the digit separator
/// to be a identical to empty input.
#[inline(always)]
pub const fn exponent_trailing_digit_separator(&self) -> bool {
Self::EXPONENT_TRAILING_DIGIT_SEPARATOR
}

/// If a digit separator is allowed after any digits.
///
/// This will consider an input of only the digit separator
/// to be a identical to empty input.
pub const TRAILING_DIGIT_SEPARATOR: bool = from_flag!(FORMAT, TRAILING_DIGIT_SEPARATOR);

/// Get if a digit separator is allowed after any digits.
///
/// This will consider an input of only the digit separator
/// to be a identical to empty input.
#[inline(always)]
pub const fn trailing_digit_separator(&self) -> bool {
Self::TRAILING_DIGIT_SEPARATOR
Expand Down
Loading

0 comments on commit c6aedf7

Please sign in to comment.