diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/ron/tests/numbers.rs | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/ron/tests/numbers.rs')
-rw-r--r-- | third_party/rust/ron/tests/numbers.rs | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/third_party/rust/ron/tests/numbers.rs b/third_party/rust/ron/tests/numbers.rs new file mode 100644 index 0000000000..4717ddb9f2 --- /dev/null +++ b/third_party/rust/ron/tests/numbers.rs @@ -0,0 +1,111 @@ +use ron::de::from_str; +use ron::error::{Error, Position, SpannedError}; + +#[test] +fn test_hex() { + assert_eq!(from_str("0x507"), Ok(0x507)); + assert_eq!(from_str("0x1A5"), Ok(0x1A5)); + assert_eq!(from_str("0x53C537"), Ok(0x53C537)); + + assert_eq!( + from_str::<u8>("0x"), + Err(SpannedError { + code: Error::ExpectedInteger, + position: Position { line: 1, col: 3 }, + }) + ); + assert_eq!( + from_str::<u8>("0x_1"), + Err(SpannedError { + code: Error::UnderscoreAtBeginning, + position: Position { line: 1, col: 3 }, + }) + ); + assert_eq!( + from_str::<u8>("0xFFF"), + Err(SpannedError { + code: Error::IntegerOutOfBounds, + position: Position { line: 1, col: 6 }, + }) + ); +} + +#[test] +fn test_bin() { + assert_eq!(from_str("0b101"), Ok(0b101)); + assert_eq!(from_str("0b001"), Ok(0b001)); + assert_eq!(from_str("0b100100"), Ok(0b100100)); + + assert_eq!( + from_str::<u8>("0b"), + Err(SpannedError { + code: Error::ExpectedInteger, + position: Position { line: 1, col: 3 }, + }) + ); + assert_eq!( + from_str::<u8>("0b_1"), + Err(SpannedError { + code: Error::UnderscoreAtBeginning, + position: Position { line: 1, col: 3 }, + }) + ); + assert_eq!( + from_str::<u8>("0b111111111"), + Err(SpannedError { + code: Error::IntegerOutOfBounds, + position: Position { line: 1, col: 12 }, + }) + ); +} + +#[test] +fn test_oct() { + assert_eq!(from_str("0o1461"), Ok(0o1461)); + assert_eq!(from_str("0o051"), Ok(0o051)); + assert_eq!(from_str("0o150700"), Ok(0o150700)); + + assert_eq!( + from_str::<u8>("0o"), + Err(SpannedError { + code: Error::ExpectedInteger, + position: Position { line: 1, col: 3 }, + }) + ); + assert_eq!( + from_str::<u8>("0o_1"), + Err(SpannedError { + code: Error::UnderscoreAtBeginning, + position: Position { line: 1, col: 3 }, + }) + ); + assert_eq!( + from_str::<u8>("0o77777"), + Err(SpannedError { + code: Error::IntegerOutOfBounds, + position: Position { line: 1, col: 8 }, + }) + ); +} + +#[test] +fn test_dec() { + assert_eq!(from_str("1461"), Ok(1461)); + assert_eq!(from_str("51"), Ok(51)); + assert_eq!(from_str("150700"), Ok(150700)); + + assert_eq!( + from_str::<i8>("-_1"), + Err(SpannedError { + code: Error::UnderscoreAtBeginning, + position: Position { line: 1, col: 2 }, + }) + ); + assert_eq!( + from_str::<u8>("256"), + Err(SpannedError { + code: Error::IntegerOutOfBounds, + position: Position { line: 1, col: 4 }, + }) + ); +} |