Skip to content

Commit

Permalink
fix(parser): fix tests for number parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Jul 14, 2024
1 parent 9a094e8 commit 486e383
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions crates/oxc_parser/src/lexer/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ mod test {
}
}

// binary
static_assertions::const_assert_eq!(binary_byte_to_value(b'0'), 0);
static_assertions::const_assert_eq!(binary_byte_to_value(b'1'), 1);

// octal
static_assertions::const_assert_eq!(octal_byte_to_value(b'0'), 0);
static_assertions::const_assert_eq!(octal_byte_to_value(b'7'), 7);
Expand All @@ -282,29 +286,32 @@ mod test {
static_assertions::const_assert_eq!(hex_byte_to_value(b'a'), 10);
static_assertions::const_assert_eq!(hex_byte_to_value(b'f'), 15);

// binary
static_assertions::const_assert_eq!(binary_byte_to_value(b'0'), 0);
static_assertions::const_assert_eq!(binary_byte_to_value(b'1'), 1);

#[test]
#[allow(clippy::excessive_precision, clippy::cast_precision_loss)]
fn test_int_precision() {
assert_eq!(parse_int("9007199254740991", Kind::Decimal, false), Ok(9007199254740991.0));
assert_eq!(
// 18446744073709551616 = 1 << 64
parse_int("18446744073709551616", Kind::Decimal, false),
Ok(18446744073709551616_i128 as f64)
);
assert_eq!(
// 0x10000000000000000 = 1 << 64
parse_int("0x10000000000000000", Kind::Hex, false),
Ok(0x10000000000000000_i128 as f64)
);
assert_eq!(
parse_int("0o40000000000000000", Kind::Octal, false),
Ok(0o40000000000000000_i128 as f64)
// 0o2000000000000000000000 = 1 << 64
parse_int("0o2000000000000000000000", Kind::Octal, false),
Ok(0o4000000000000000000000_i128 as f64)
);
assert_eq!(
// 0b10000000000000000000000000000000000000000000000000000000000000000 = 1 << 64
parse_int(
"0b00010000000000000000000000000000000000000000000000000000000000000000",
"0b10000000000000000000000000000000000000000000000000000000000000000",
Kind::Binary,
false
),
Ok(0b00010000000000000000000000000000000000000000000000000000000000000000_i128 as f64)
Ok(0b10000000000000000000000000000000000000000000000000000000000000000_i128 as f64)
);
}

Expand Down

0 comments on commit 486e383

Please sign in to comment.