Skip to content

Commit 6570e4c

Browse files
committed
Add TryFrom tests for array reference types
1 parent 1322177 commit 6570e4c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/libcore/tests/array.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010
use core::array::FixedSizeArray;
11+
use core::convert::TryFrom;
1112

1213
#[test]
1314
fn fixed_size_array() {
@@ -26,3 +27,25 @@ fn fixed_size_array() {
2627
assert_eq!(FixedSizeArray::as_mut_slice(&mut empty_array).len(), 0);
2728
assert_eq!(FixedSizeArray::as_mut_slice(&mut empty_zero_sized).len(), 0);
2829
}
30+
31+
#[test]
32+
fn array_try_from() {
33+
macro_rules! test {
34+
($($N:expr)+) => {
35+
$({
36+
type Array = [u8; $N];
37+
let array: Array = [0; $N];
38+
let slice: &[u8] = &array[..];
39+
40+
let result = <&Array>::try_from(slice);
41+
assert_eq!(Ok(&array), result);
42+
})+
43+
}
44+
}
45+
test! {
46+
0 1 2 3 4 5 6 7 8 9
47+
10 11 12 13 14 15 16 17 18 19
48+
20 21 22 23 24 25 26 27 28 29
49+
30 31 32
50+
}
51+
}

0 commit comments

Comments
 (0)