summary refs log tree commit diff
path: root/src/libcoretest
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2015-10-15 05:23:44 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2015-10-15 05:23:44 +0300
commit6f3e84dbe9434b020da73d66275c3609a2b7bb1b (patch)
tree461d44a5702638a25ef98f4a080f0393f126c0b4 /src/libcoretest
parente38210b195a4aaf91f3daa37dfcfd7059bd22ddc (diff)
downloadrust-6f3e84dbe9434b020da73d66275c3609a2b7bb1b.tar.gz
rust-6f3e84dbe9434b020da73d66275c3609a2b7bb1b.zip
Implement conversion traits for primitive integer types
Diffstat (limited to 'src/libcoretest')
-rw-r--r--src/libcoretest/num/mod.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/libcoretest/num/mod.rs b/src/libcoretest/num/mod.rs
index 2a3ff88fe6d..5e2ec66baba 100644
--- a/src/libcoretest/num/mod.rs
+++ b/src/libcoretest/num/mod.rs
@@ -137,4 +137,44 @@ mod tests {
         assert_eq!("+".parse::<i8>().ok(), None);
         assert_eq!("".parse::<u8>().ok(), None);
     }
+
+    macro_rules! test_impl_from {
+        ($fn_name: ident, $Small: ty, $Large: ty) => {
+            #[test]
+            fn $fn_name() {
+                let small_max = <$Small>::max_value();
+                let small_min = <$Small>::min_value();
+                let large_max: $Large = small_max.into();
+                let large_min: $Large = small_min.into();
+                assert_eq!(large_max as $Small, small_max);
+                assert_eq!(large_min as $Small, small_min);
+            }
+        }
+    }
+
+    // Unsigned -> Unsigned
+    test_impl_from! { test_u8u16, u8, u16 }
+    test_impl_from! { test_u8u32, u8, u32 }
+    test_impl_from! { test_u8u64, u8, u64 }
+    test_impl_from! { test_u8usize, u8, usize }
+    test_impl_from! { test_u16u32, u16, u32 }
+    test_impl_from! { test_u16u64, u16, u64 }
+    test_impl_from! { test_u32u64, u32, u64 }
+
+    // Signed -> Signed
+    test_impl_from! { test_i8i16, i8, i16 }
+    test_impl_from! { test_i8i32, i8, i32 }
+    test_impl_from! { test_i8i64, i8, i64 }
+    test_impl_from! { test_i8isize, i8, isize }
+    test_impl_from! { test_i16i32, i16, i32 }
+    test_impl_from! { test_i16i64, i16, i64 }
+    test_impl_from! { test_i32i64, i32, i64 }
+
+    // Unsigned -> Signed
+    test_impl_from! { test_u8i16, u8, i16 }
+    test_impl_from! { test_u8i32, u8, i32 }
+    test_impl_from! { test_u8i64, u8, i64 }
+    test_impl_from! { test_u16i32, u16, i32 }
+    test_impl_from! { test_u16i64, u16, i64 }
+    test_impl_from! { test_u32i64, u32, i64 }
 }