Skip to content

Commit 09928a9

Browse files
committed
Add tests
1 parent eefd790 commit 09928a9

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

library/core/tests/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#![feature(const_ptr_read)]
1414
#![feature(const_ptr_write)]
1515
#![feature(const_ptr_offset)]
16+
#![feature(const_trait_impl)]
17+
#![feature(const_num_from_num)]
1618
#![feature(core_intrinsics)]
1719
#![feature(core_private_bignum)]
1820
#![feature(core_private_diy_float)]

library/core/tests/num/const_from.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
// Upper bounded
11+
const U8_FROM_U16: Result<u8, TryFromIntError> = u8::try_from(1u16);
12+
assert_eq!(U8_FROM_U16, Ok(1u8));
13+
14+
// Both bounded
15+
const I8_FROM_I16: Result<i8, TryFromIntError> = i8::try_from(1i16);
16+
assert_eq!(I8_FROM_I16, Ok(1i8));
17+
18+
// Lower bounded
19+
const I16_FROM_U16: Result<i16, TryFromIntError> = i16::try_from(1u16);
20+
assert_eq!(I16_FROM_U16, Ok(1i16));
21+
}

library/core/tests/num/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ mod u64;
2727
mod u8;
2828

2929
mod bignum;
30+
31+
mod const_from;
3032
mod dec2flt;
3133
mod flt2dec;
3234
mod int_log;

0 commit comments

Comments
 (0)