about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJonas Schievink <jonasschievink@gmail.com>2020-10-03 00:31:08 +0200
committerGitHub <noreply@github.com>2020-10-03 00:31:08 +0200
commit389f7cf7d6c333b490e208bcbda3406b9e0ef437 (patch)
treef2d46469b168c7d122e59c9256146205b6b9404f
parentca0ff934e939969e09abcc2d17f0cff89b8147ee (diff)
parent4e973966b95e5157754f91216456a3c37a1472b2 (diff)
downloadrust-389f7cf7d6c333b490e208bcbda3406b9e0ef437.tar.gz
rust-389f7cf7d6c333b490e208bcbda3406b9e0ef437.zip
Rollup merge of #76745 - workingjubilee:move-wrapping-tests, r=matklad
Move Wrapping<T> ui tests into library

Part of #76268
r? @matklad
-rw-r--r--library/core/tests/num/wrapping.rs76
-rw-r--r--src/test/ui/wrapping-int-combinations.rs77
2 files changed, 76 insertions, 77 deletions
diff --git a/library/core/tests/num/wrapping.rs b/library/core/tests/num/wrapping.rs
new file mode 100644
index 00000000000..5d4ecb2669a
--- /dev/null
+++ b/library/core/tests/num/wrapping.rs
@@ -0,0 +1,76 @@
+use core::num::Wrapping;
+
+macro_rules! wrapping_operation {
+    ($result:expr, $lhs:ident $op:tt $rhs:expr) => {
+        assert_eq!($result, $lhs $op $rhs);
+        assert_eq!($result, &$lhs $op $rhs);
+        assert_eq!($result, $lhs $op &$rhs);
+        assert_eq!($result, &$lhs $op &$rhs);
+    };
+    ($result:expr, $op:tt $expr:expr) => {
+        assert_eq!($result, $op $expr);
+        assert_eq!($result, $op &$expr);
+    };
+}
+
+macro_rules! wrapping_assignment {
+    ($result:expr, $lhs:ident $op:tt $rhs:expr) => {
+        let mut lhs1 = $lhs;
+        lhs1 $op $rhs;
+        assert_eq!($result, lhs1);
+
+        let mut lhs2 = $lhs;
+        lhs2 $op &$rhs;
+        assert_eq!($result, lhs2);
+    };
+}
+
+macro_rules! wrapping_test {
+    ($type:ty, $min:expr, $max:expr) => {
+        #[test]
+        fn wrapping_$type() {
+            let zero: Wrapping<$type> = Wrapping(0);
+            let one: Wrapping<$type> = Wrapping(1);
+            let min: Wrapping<$type> = Wrapping($min);
+            let max: Wrapping<$type> = Wrapping($max);
+
+            wrapping_operation!(min, max + one);
+            wrapping_assignment!(min, max += one);
+            wrapping_operation!(max, min - one);
+            wrapping_assignment!(max, min -= one);
+            wrapping_operation!(max, max * one);
+            wrapping_assignment!(max, max *= one);
+            wrapping_operation!(max, max / one);
+            wrapping_assignment!(max, max /= one);
+            wrapping_operation!(zero, max % one);
+            wrapping_assignment!(zero, max %= one);
+            wrapping_operation!(zero, zero & max);
+            wrapping_assignment!(zero, zero &= max);
+            wrapping_operation!(max, zero | max);
+            wrapping_assignment!(max, zero |= max);
+            wrapping_operation!(zero, max ^ max);
+            wrapping_assignment!(zero, max ^= max);
+            wrapping_operation!(zero, zero << 1usize);
+            wrapping_assignment!(zero, zero <<= 1usize);
+            wrapping_operation!(zero, zero >> 1usize);
+            wrapping_assignment!(zero, zero >>= 1usize);
+            wrapping_operation!(zero, -zero);
+            wrapping_operation!(max, !min);
+        }
+    };
+}
+
+wrapping_test!(i8, i8::MIN, i8::MAX);
+wrapping_test!(i16, i16::MIN, i16::MAX);
+wrapping_test!(i32, i32::MIN, i32::MAX);
+wrapping_test!(i64, i64::MIN, i64::MAX);
+#[cfg(not(target_os = "emscripten"))]
+wrapping_test!(i128, i128::MIN, i128::MAX);
+wrapping_test!(isize, isize::MIN, isize::MAX);
+wrapping_test!(u8, u8::MIN, u8::MAX);
+wrapping_test!(u16, u16::MIN, u16::MAX);
+wrapping_test!(u32, u32::MIN, u32::MAX);
+wrapping_test!(u64, u64::MIN, u64::MAX);
+#[cfg(not(target_os = "emscripten"))]
+wrapping_test!(u128, u128::MIN, u128::MAX);
+wrapping_test!(usize, usize::MIN, usize::MAX);
diff --git a/src/test/ui/wrapping-int-combinations.rs b/src/test/ui/wrapping-int-combinations.rs
deleted file mode 100644
index f0bc479ee0f..00000000000
--- a/src/test/ui/wrapping-int-combinations.rs
+++ /dev/null
@@ -1,77 +0,0 @@
-// run-pass
-
-use std::num::Wrapping;
-
-macro_rules! wrapping_operation {
-    ($result:expr, $lhs:ident $op:tt $rhs:expr) => {
-        assert_eq!($result, $lhs $op $rhs);
-        assert_eq!($result, &$lhs $op $rhs);
-        assert_eq!($result, $lhs $op &$rhs);
-        assert_eq!($result, &$lhs $op &$rhs);
-    };
-    ($result:expr, $op:tt $expr:expr) => {
-        assert_eq!($result, $op $expr);
-        assert_eq!($result, $op &$expr);
-    };
-}
-
-macro_rules! wrapping_assignment {
-    ($result:expr, $lhs:ident $op:tt $rhs:expr) => {
-        let mut lhs1 = $lhs;
-        lhs1 $op $rhs;
-        assert_eq!($result, lhs1);
-
-        let mut lhs2 = $lhs;
-        lhs2 $op &$rhs;
-        assert_eq!($result, lhs2);
-    };
-}
-
-macro_rules! wrapping_test {
-    ($type:ty, $min:expr, $max:expr) => {
-        let zero: Wrapping<$type> = Wrapping(0);
-        let one: Wrapping<$type> = Wrapping(1);
-        let min: Wrapping<$type> = Wrapping($min);
-        let max: Wrapping<$type> = Wrapping($max);
-
-        wrapping_operation!(min, max + one);
-        wrapping_assignment!(min, max += one);
-        wrapping_operation!(max, min - one);
-        wrapping_assignment!(max, min -= one);
-        wrapping_operation!(max, max * one);
-        wrapping_assignment!(max, max *= one);
-        wrapping_operation!(max, max / one);
-        wrapping_assignment!(max, max /= one);
-        wrapping_operation!(zero, max % one);
-        wrapping_assignment!(zero, max %= one);
-        wrapping_operation!(zero, zero & max);
-        wrapping_assignment!(zero, zero &= max);
-        wrapping_operation!(max, zero | max);
-        wrapping_assignment!(max, zero |= max);
-        wrapping_operation!(zero, max ^ max);
-        wrapping_assignment!(zero, max ^= max);
-        wrapping_operation!(zero, zero << 1usize);
-        wrapping_assignment!(zero, zero <<= 1usize);
-        wrapping_operation!(zero, zero >> 1usize);
-        wrapping_assignment!(zero, zero >>= 1usize);
-        wrapping_operation!(zero, -zero);
-        wrapping_operation!(max, !min);
-    };
-}
-
-fn main() {
-    wrapping_test!(i8, std::i8::MIN, std::i8::MAX);
-    wrapping_test!(i16, std::i16::MIN, std::i16::MAX);
-    wrapping_test!(i32, std::i32::MIN, std::i32::MAX);
-    wrapping_test!(i64, std::i64::MIN, std::i64::MAX);
-    #[cfg(not(target_os = "emscripten"))]
-    wrapping_test!(i128, std::i128::MIN, std::i128::MAX);
-    wrapping_test!(isize, std::isize::MIN, std::isize::MAX);
-    wrapping_test!(u8, std::u8::MIN, std::u8::MAX);
-    wrapping_test!(u16, std::u16::MIN, std::u16::MAX);
-    wrapping_test!(u32, std::u32::MIN, std::u32::MAX);
-    wrapping_test!(u64, std::u64::MIN, std::u64::MAX);
-    #[cfg(not(target_os = "emscripten"))]
-    wrapping_test!(u128, std::u128::MIN, std::u128::MAX);
-    wrapping_test!(usize, std::usize::MIN, std::usize::MAX);
-}