Skip to content

Commit adee559

Browse files
committed
test const abs, wrapping_abs, and overflowing_abs
1 parent 39260d9 commit adee559

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/test/ui/consts/const-int-overflowing-rpass.rs

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ const SHR_B: (u32, bool) = 0x10u32.overflowing_shr(132);
1818
const NEG_A: (u32, bool) = 0u32.overflowing_neg();
1919
const NEG_B: (u32, bool) = core::u32::MAX.overflowing_neg();
2020

21+
const ABS_POS: (i32, bool) = 10i32.overflowing_abs();
22+
const ABS_NEG: (i32, bool) = (-10i32).overflowing_abs();
23+
const ABS_MIN: (i32, bool) = i32::min_value().overflowing_abs();
24+
2125
fn main() {
2226
assert_eq!(ADD_A, (7, false));
2327
assert_eq!(ADD_B, (0, true));
@@ -36,4 +40,8 @@ fn main() {
3640

3741
assert_eq!(NEG_A, (0, false));
3842
assert_eq!(NEG_B, (1, true));
43+
44+
assert_eq!(ABS_POS, (10, false));
45+
assert_eq!(ABS_NEG, (10, false));
46+
assert_eq!(ABS_MIN, (i32::min_value(), true));
3947
}

src/test/ui/consts/const-int-sign-rpass.rs

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ const SIGNUM_POS: i32 = 10i32.signum();
1111
const SIGNUM_NIL: i32 = 0i32.signum();
1212
const SIGNUM_NEG: i32 = (-42i32).signum();
1313

14+
const ABS_A: i32 = 10i32.abs();
15+
const ABS_B: i32 = (-10i32).abs();
16+
1417
fn main() {
1518
assert!(NEGATIVE_A);
1619
assert!(!NEGATIVE_B);
@@ -20,4 +23,7 @@ fn main() {
2023
assert_eq!(SIGNUM_POS, 1);
2124
assert_eq!(SIGNUM_NIL, 0);
2225
assert_eq!(SIGNUM_NEG, -1);
26+
27+
assert_eq!(ABS_A, 10);
28+
assert_eq!(ABS_B, 10);
2329
}

src/test/ui/consts/const-int-wrapping-rpass.rs

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ const SHR_B: u32 = 128u32.wrapping_shr(128);
1818
const NEG_A: u32 = 5u32.wrapping_neg();
1919
const NEG_B: u32 = 1234567890u32.wrapping_neg();
2020

21+
const ABS_POS: i32 = 10i32.wrapping_abs();
22+
const ABS_NEG: i32 = (-10i32).wrapping_abs();
23+
const ABS_MIN: i32 = i32::min_value().wrapping_abs();
24+
2125
fn main() {
2226
assert_eq!(ADD_A, 255);
2327
assert_eq!(ADD_B, 199);
@@ -36,4 +40,8 @@ fn main() {
3640

3741
assert_eq!(NEG_A, 4294967291);
3842
assert_eq!(NEG_B, 3060399406);
43+
44+
assert_eq!(ABS_POS, 10);
45+
assert_eq!(ABS_NEG, 10);
46+
assert_eq!(ABS_MIN, i32::min_value());
3947
}

0 commit comments

Comments
 (0)