about summary refs log tree commit diff
path: root/src/libcore/tests/array.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/libcore/tests/array.rs')
-rw-r--r--src/libcore/tests/array.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/libcore/tests/array.rs b/src/libcore/tests/array.rs
index 6af031dee58..6278d5e23e0 100644
--- a/src/libcore/tests/array.rs
+++ b/src/libcore/tests/array.rs
@@ -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!(&array, result.unwrap());
+            })+
+        }
+    }
+    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
+    }
+}