1
Fork 0

Move various ui const tests to library

Move:
 - `src\test\ui\consts\const-nonzero.rs` to `library\core`
 - `src\test\ui\consts\ascii.rs` to `library\core`
 - `src\test\ui\consts\cow-is-borrowed` to `library\alloc`

Part of #76268
This commit is contained in:
Christiaan Dirkx 2020-09-04 02:35:27 +02:00
parent 0d0f6b1130
commit 538e198193
7 changed files with 42 additions and 46 deletions

View file

@ -397,3 +397,14 @@ fn test_is_ascii_align_size_thoroughly() {
}
}
}
#[test]
fn ascii_const() {
// test that the `is_ascii` methods of `char` and `u8` are usable in a const context
const CHAR_IS_ASCII: bool = 'a'.is_ascii();
assert!(CHAR_IS_ASCII);
const BYTE_IS_ASCII: bool = 97u8.is_ascii();
assert!(BYTE_IS_ASCII);
}

View file

@ -195,3 +195,20 @@ fn test_nonzero_from_int_on_err() {
assert!(NonZeroI8::try_from(0).is_err());
assert!(NonZeroI32::try_from(0).is_err());
}
#[test]
fn nonzero_const() {
// test that the methods of `NonZeroX>` are usable in a const context
// Note: only tests NonZero8
const NONZERO: NonZeroU8 = unsafe { NonZeroU8::new_unchecked(5) };
const GET: u8 = NONZERO.get();
assert_eq!(GET, 5);
const ZERO: Option<NonZeroU8> = NonZeroU8::new(0);
assert!(ZERO.is_none());
const ONE: Option<NonZeroU8> = NonZeroU8::new(1);
assert!(ONE.is_some());
}