Add TryFrom tests for array reference types
This commit is contained in:
parent
13221770a3
commit
6570e4cd05
@ -8,6 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
use core::array::FixedSizeArray;
|
||||
use core::convert::TryFrom;
|
||||
|
||||
#[test]
|
||||
fn fixed_size_array() {
|
||||
@ -26,3 +27,25 @@ fn fixed_size_array() {
|
||||
assert_eq!(FixedSizeArray::as_mut_slice(&mut empty_array).len(), 0);
|
||||
assert_eq!(FixedSizeArray::as_mut_slice(&mut empty_zero_sized).len(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn array_try_from() {
|
||||
macro_rules! test {
|
||||
($($N:expr)+) => {
|
||||
$({
|
||||
type Array = [u8; $N];
|
||||
let array: Array = [0; $N];
|
||||
let slice: &[u8] = &array[..];
|
||||
|
||||
let result = <&Array>::try_from(slice);
|
||||
assert_eq!(Ok(&array), result);
|
||||
})+
|
||||
}
|
||||
}
|
||||
test! {
|
||||
0 1 2 3 4 5 6 7 8 9
|
||||
10 11 12 13 14 15 16 17 18 19
|
||||
20 21 22 23 24 25 26 27 28 29
|
||||
30 31 32
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user