Avoid indexing in test assertions
This commit is contained in:
+19
-7
@@ -84,7 +84,7 @@ fn test_send_type_erased_vec_retains_send_elements_across_threads() {
|
||||
.join()
|
||||
.expect("worker thread panicked");
|
||||
|
||||
assert_eq!(values[0].get(), 42);
|
||||
assert_eq!(values.first().map(Cell::get), Some(42));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -294,12 +294,18 @@ fn test_cast_type_success_and_mutation() {
|
||||
assert_guard_state(&guard, 2);
|
||||
assert!(guard.capacity() >= initial_cap);
|
||||
|
||||
let slice = guard.as_slice_mut();
|
||||
slice[0] = 42;
|
||||
let mutable_slice = guard.as_slice_mut();
|
||||
assert_eq!(
|
||||
mutable_slice.first_mut().map(|first| {
|
||||
*first = 42;
|
||||
*first
|
||||
}),
|
||||
Some(42)
|
||||
);
|
||||
|
||||
let slice = guard.as_slice();
|
||||
let immutable_slice = guard.as_slice();
|
||||
// Casting -2_i32 into u32 results in u32::MAX - 1 due to two's complement.
|
||||
assert_eq!(slice, &[42, u32::MAX - 1]);
|
||||
assert_eq!(immutable_slice, &[42, u32::MAX - 1]);
|
||||
|
||||
let restored = guard.take();
|
||||
assert_eq!(restored, vec![42, u32::MAX - 1]);
|
||||
@@ -511,7 +517,13 @@ fn test_guard_into_slice_mut() {
|
||||
|
||||
let guard = unsafe { erased.cast_type::<i32>() };
|
||||
let slice = guard.into_slice_mut();
|
||||
slice[0] = 99;
|
||||
assert_eq!(
|
||||
slice.first_mut().map(|first| {
|
||||
*first = 99;
|
||||
*first
|
||||
}),
|
||||
Some(99)
|
||||
);
|
||||
assert_eq!(slice, &[99, 2]);
|
||||
}
|
||||
|
||||
@@ -522,7 +534,7 @@ fn test_guard_push() {
|
||||
let mut guard = erased.as_type::<i32>();
|
||||
|
||||
guard.push(42);
|
||||
assert_eq!(guard.with(|v| v[0]), 42);
|
||||
assert_eq!(guard.with(|values| values.first().copied()), Some(42));
|
||||
assert_eq!(guard.length(), 1);
|
||||
assert_eq!(guard.as_slice(), &[42]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user