]> git.lizzy.rs Git - rust.git/blob - library/core/tests/num/const_from.rs
Auto merge of #106340 - saethlin:propagate-operands, r=oli-obk
[rust.git] / library / core / tests / num / const_from.rs
1 #[test]
2 fn from() {
3     use core::convert::TryFrom;
4     use core::num::TryFromIntError;
5
6     // From
7     const FROM: i64 = i64::from(1i32);
8     assert_eq!(FROM, 1i64);
9
10     // From int to float
11     const FROM_F64: f64 = f64::from(42u8);
12     assert_eq!(FROM_F64, 42f64);
13
14     // Upper bounded
15     const U8_FROM_U16: Result<u8, TryFromIntError> = u8::try_from(1u16);
16     assert_eq!(U8_FROM_U16, Ok(1u8));
17
18     // Both bounded
19     const I8_FROM_I16: Result<i8, TryFromIntError> = i8::try_from(1i16);
20     assert_eq!(I8_FROM_I16, Ok(1i8));
21
22     // Lower bounded
23     const I16_FROM_U16: Result<i16, TryFromIntError> = i16::try_from(1u16);
24     assert_eq!(I16_FROM_U16, Ok(1i16));
25 }