-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use MaybeUninit in DecInt * Fix DecInt::new panicking on integers greater than 64 bits and optimize out any panics in DecInt::new * Add tests so people messing with DecInt can catch UB with miri * Use new itoa --------- Co-authored-by: Alex Saveau <[email protected]>
- Loading branch information
1 parent
41b26db
commit 61f17d6
Showing
3 changed files
with
76 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,45 @@ | ||
use rustix::path::DecInt; | ||
|
||
macro_rules! check { | ||
($i:expr) => { | ||
let i = $i; | ||
assert_eq!(DecInt::new(i).as_ref().to_str().unwrap(), i.to_string()); | ||
}; | ||
} | ||
|
||
#[test] | ||
fn test_dec_int() { | ||
assert_eq!(DecInt::new(0).as_ref().to_str().unwrap(), "0"); | ||
assert_eq!(DecInt::new(-1).as_ref().to_str().unwrap(), "-1"); | ||
assert_eq!(DecInt::new(789).as_ref().to_str().unwrap(), "789"); | ||
assert_eq!( | ||
DecInt::new(i64::MIN).as_ref().to_str().unwrap(), | ||
i64::MIN.to_string() | ||
); | ||
assert_eq!( | ||
DecInt::new(i64::MAX).as_ref().to_str().unwrap(), | ||
i64::MAX.to_string() | ||
); | ||
assert_eq!( | ||
DecInt::new(u64::MAX).as_ref().to_str().unwrap(), | ||
u64::MAX.to_string() | ||
); | ||
check!(0); | ||
check!(-1); | ||
check!(789); | ||
|
||
check!(u8::MAX); | ||
check!(i8::MIN); | ||
check!(u16::MAX); | ||
check!(i16::MIN); | ||
check!(u32::MAX); | ||
check!(i32::MIN); | ||
check!(u64::MAX); | ||
check!(i64::MIN); | ||
#[cfg(any( | ||
target_pointer_width = "16", | ||
target_pointer_width = "32", | ||
target_pointer_width = "64" | ||
))] | ||
{ | ||
check!(usize::MAX); | ||
check!(isize::MIN); | ||
} | ||
} | ||
|
||
#[test] | ||
#[should_panic] | ||
fn test_unsupported_max_u128_dec_int() { | ||
check!(u128::MAX); | ||
} | ||
|
||
#[test] | ||
#[should_panic] | ||
fn test_unsupported_min_u128_dec_int() { | ||
check!(i128::MIN); | ||
} |