Skip to content

Commit

Permalink
test const abs, wrapping_abs, and overflowing_abs
Browse files Browse the repository at this point in the history
  • Loading branch information
tspiteri committed Aug 21, 2019
1 parent 39260d9 commit adee559
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/test/ui/consts/const-int-overflowing-rpass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ const SHR_B: (u32, bool) = 0x10u32.overflowing_shr(132);
const NEG_A: (u32, bool) = 0u32.overflowing_neg();
const NEG_B: (u32, bool) = core::u32::MAX.overflowing_neg();

const ABS_POS: (i32, bool) = 10i32.overflowing_abs();
const ABS_NEG: (i32, bool) = (-10i32).overflowing_abs();
const ABS_MIN: (i32, bool) = i32::min_value().overflowing_abs();

fn main() {
assert_eq!(ADD_A, (7, false));
assert_eq!(ADD_B, (0, true));
Expand All @@ -36,4 +40,8 @@ fn main() {

assert_eq!(NEG_A, (0, false));
assert_eq!(NEG_B, (1, true));

assert_eq!(ABS_POS, (10, false));
assert_eq!(ABS_NEG, (10, false));
assert_eq!(ABS_MIN, (i32::min_value(), true));
}
6 changes: 6 additions & 0 deletions src/test/ui/consts/const-int-sign-rpass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const SIGNUM_POS: i32 = 10i32.signum();
const SIGNUM_NIL: i32 = 0i32.signum();
const SIGNUM_NEG: i32 = (-42i32).signum();

const ABS_A: i32 = 10i32.abs();
const ABS_B: i32 = (-10i32).abs();

fn main() {
assert!(NEGATIVE_A);
assert!(!NEGATIVE_B);
Expand All @@ -20,4 +23,7 @@ fn main() {
assert_eq!(SIGNUM_POS, 1);
assert_eq!(SIGNUM_NIL, 0);
assert_eq!(SIGNUM_NEG, -1);

assert_eq!(ABS_A, 10);
assert_eq!(ABS_B, 10);
}
8 changes: 8 additions & 0 deletions src/test/ui/consts/const-int-wrapping-rpass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ const SHR_B: u32 = 128u32.wrapping_shr(128);
const NEG_A: u32 = 5u32.wrapping_neg();
const NEG_B: u32 = 1234567890u32.wrapping_neg();

const ABS_POS: i32 = 10i32.wrapping_abs();
const ABS_NEG: i32 = (-10i32).wrapping_abs();
const ABS_MIN: i32 = i32::min_value().wrapping_abs();

fn main() {
assert_eq!(ADD_A, 255);
assert_eq!(ADD_B, 199);
Expand All @@ -36,4 +40,8 @@ fn main() {

assert_eq!(NEG_A, 4294967291);
assert_eq!(NEG_B, 3060399406);

assert_eq!(ABS_POS, 10);
assert_eq!(ABS_NEG, 10);
assert_eq!(ABS_MIN, i32::min_value());
}

0 comments on commit adee559

Please sign in to comment.