Added tests for construction in const context

Updated the capacity panic test
This commit is contained in:
rodrimati1992
2021-03-28 14:49:45 -03:00
parent 5ad4687b1b
commit 165414e0d9
+27 -2
View File
@@ -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::<usize>() <= mem::size_of::<u32>() {
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<Vec<u8>, 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");
}