Skip to content

Commit 165414e

Browse files
committed
Added tests for construction in const context
Updated the capacity panic test
1 parent 5ad4687 commit 165414e

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

tests/tests.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,12 +718,37 @@ fn allow_max_capacity_arrayvec_type() {
718718
let _v: ArrayVec<(), {usize::MAX}>;
719719
}
720720

721-
#[should_panic(expected="ArrayVec: largest supported")]
721+
#[should_panic(expected="index out of bounds")]
722722
#[test]
723723
fn deny_max_capacity_arrayvec_value() {
724724
if mem::size_of::<usize>() <= mem::size_of::<u32>() {
725-
panic!("This test does not work on this platform. 'ArrayVec: largest supported'");
725+
panic!("This test does not work on this platform. 'index out of bounds'");
726726
}
727727
// this type is allowed to be used (but can't be constructed)
728728
let _v: ArrayVec<(), {usize::MAX}> = ArrayVec::new();
729729
}
730+
731+
#[test]
732+
fn test_arrayvec_const_constructible() {
733+
const OF_U8: ArrayVec<Vec<u8>, 10> = ArrayVec::new();
734+
735+
let mut var = OF_U8;
736+
assert!(var.is_empty());
737+
assert_eq!(var, ArrayVec::new());
738+
var.push(vec![3, 5, 8]);
739+
assert_eq!(var[..], [vec![3, 5, 8]]);
740+
}
741+
742+
743+
#[test]
744+
fn test_arraystring_const_constructible() {
745+
const AS: ArrayString<10> = ArrayString::new();
746+
747+
let mut var = AS;
748+
assert!(var.is_empty());
749+
assert_eq!(var, ArrayString::new());
750+
var.push_str("hello");
751+
assert_eq!(var, *"hello");
752+
}
753+
754+

0 commit comments

Comments
 (0)