Cover scoped panic restoration
This commit is contained in:
@@ -892,6 +892,38 @@ fn test_scoped_guard_reserve_restore_and_take() {
|
||||
assert_eq!(erased.capacity(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_scoped_guard_restores_after_panic_and_clears_stale_bytes() {
|
||||
let mut erased = TypeErasedVec::new(Vec::<&'static str>::with_capacity(4));
|
||||
let (retained_ptr, retained_capacity);
|
||||
|
||||
{
|
||||
let first = String::from("first");
|
||||
let second = String::from("second");
|
||||
let mut guard = erased.as_type_scoped::<&str>();
|
||||
retained_ptr = guard.as_slice().as_ptr();
|
||||
retained_capacity = guard.capacity();
|
||||
|
||||
let result = panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
||||
guard.with(|values| {
|
||||
values.push(&first);
|
||||
values.push(&second);
|
||||
panic!("stop after scoped mutations");
|
||||
});
|
||||
}));
|
||||
|
||||
assert!(result.is_err());
|
||||
assert_eq!(guard.as_slice(), &["first", "second"]);
|
||||
assert_eq!(guard.as_slice().as_ptr(), retained_ptr);
|
||||
assert_eq!(guard.capacity(), retained_capacity);
|
||||
}
|
||||
|
||||
assert_eq!(erased.length(), 2);
|
||||
erased.clear();
|
||||
assert!(erased.is_empty());
|
||||
assert_eq!(erased.capacity(), retained_capacity);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unchecked_methods() {
|
||||
let vec = vec![123_u32];
|
||||
|
||||
Reference in New Issue
Block a user