diff options
| author | bors <bors@rust-lang.org> | 2015-10-15 07:11:33 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-10-15 07:11:33 +0000 |
| commit | fa9a4213945d63d5505039429329694ddfe1875d (patch) | |
| tree | 57a374f83ce06d7dde102aea2f95a7f331325451 /src/libcoretest/num | |
| parent | 99dc12472a3e4f194b33829339701205bf3afcf5 (diff) | |
| parent | 6f3e84dbe9434b020da73d66275c3609a2b7bb1b (diff) | |
| download | rust-fa9a4213945d63d5505039429329694ddfe1875d.tar.gz rust-fa9a4213945d63d5505039429329694ddfe1875d.zip | |
Auto merge of #28921 - petrochenkov:intconv, r=alexcrichton
Part of https://github.com/rust-lang/rfcs/pull/1218#issuecomment-146615171 r? @aturon
Diffstat (limited to 'src/libcoretest/num')
| -rw-r--r-- | src/libcoretest/num/mod.rs | 40 |
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 } } |
