From 165414e0d9709bbf282ee3083198e4c42459d77e Mon Sep 17 00:00:00 2001 From: rodrimati1992 Date: Sun, 28 Mar 2021 14:49:45 -0300 Subject: [PATCH] Added tests for construction in const context Updated the capacity panic test --- tests/tests.rs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/tests/tests.rs b/tests/tests.rs index f4698e0..662f5e4 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -718,12 +718,37 @@ fn allow_max_capacity_arrayvec_type() { let _v: ArrayVec<(), {usize::MAX}>; } -#[should_panic(expected="ArrayVec: largest supported")] +#[should_panic(expected="index out of bounds")] #[test] fn deny_max_capacity_arrayvec_value() { if mem::size_of::() <= mem::size_of::() { - panic!("This test does not work on this platform. 'ArrayVec: largest supported'"); + panic!("This test does not work on this platform. 'index out of bounds'"); } // this type is allowed to be used (but can't be constructed) let _v: ArrayVec<(), {usize::MAX}> = ArrayVec::new(); } + +#[test] +fn test_arrayvec_const_constructible() { + const OF_U8: ArrayVec, 10> = ArrayVec::new(); + + let mut var = OF_U8; + assert!(var.is_empty()); + assert_eq!(var, ArrayVec::new()); + var.push(vec![3, 5, 8]); + assert_eq!(var[..], [vec![3, 5, 8]]); +} + + +#[test] +fn test_arraystring_const_constructible() { + const AS: ArrayString<10> = ArrayString::new(); + + let mut var = AS; + assert!(var.is_empty()); + assert_eq!(var, ArrayString::new()); + var.push_str("hello"); + assert_eq!(var, *"hello"); +} + +