]> git.lizzy.rs Git - rust.git/commitdiff
Add TryFrom tests for array reference types
authorNikolai Vazquez <nvazquez1297@gmail.com>
Sun, 24 Sep 2017 16:35:37 +0000 (12:35 -0400)
committerNikolai Vazquez <nvazquez1297@gmail.com>
Sun, 24 Sep 2017 16:35:37 +0000 (12:35 -0400)
src/libcore/tests/array.rs

index 6af031dee5845b9875776ef0933cff27f97dc187..a3bd9220929a2076344b6093c78e1432efd84571 100644 (file)
@@ -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
+    }
+}