-
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.
Add tests so people messing with DecInt can catch UB with miri
- Loading branch information
Alex Saveau
committed
Nov 14, 2024
1 parent
7fdfb82
commit a46a59b
Showing
1 changed file
with
35 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,40 @@ | ||
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_dec_int() { | ||
check!(u128::MAX); | ||
check!(i128::MIN); | ||
} |