Skip to content

Commit

Permalink
Update tests.
Browse files Browse the repository at this point in the history
cast_slice error precedence changed, so attempting to cast an unaligned *and* slop-ful slice will now return
OutputSliceWouldHaveSlop instead of TargetAlignmentGreaterAndInputNotAligned.

The documentation of try_cast_slice doesn't *explicitly* say which error will be returned if multiple occur,
so this might just be fine as a behavior change.
  • Loading branch information
zachs18 committed Jul 21, 2024
1 parent 6417895 commit a5b1bd5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions tests/cast_slice_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn test_try_cast_slice() {
);

// by taking one byte off the front, we're definitely mis-aligned for u32.
let mis_aligned_bytes = &the_bytes[1..];
let mis_aligned_bytes = &the_bytes[1..][..4];
assert_eq!(
try_cast_slice::<u8, u32>(mis_aligned_bytes),
Err(PodCastError::TargetAlignmentGreaterAndInputNotAligned)
Expand Down Expand Up @@ -60,7 +60,7 @@ fn test_try_cast_slice_mut() {
assert_eq!(u32_len * size_of::<u32>(), the_bytes_len * size_of::<u8>());

// by taking one byte off the front, we're definitely mis-aligned for u32.
let mis_aligned_bytes = &mut the_bytes[1..];
let mis_aligned_bytes = &mut the_bytes[1..][..4];
assert_eq!(
try_cast_slice_mut::<u8, u32>(mis_aligned_bytes),
Err(PodCastError::TargetAlignmentGreaterAndInputNotAligned)
Expand Down
4 changes: 2 additions & 2 deletions tests/checked_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn test_try_cast_slice() {

// by taking one byte off the front, we're definitely mis-aligned for
// NonZeroU32.
let mis_aligned_bytes = &the_bytes[1..];
let mis_aligned_bytes = &the_bytes[1..][..4];
assert_eq!(
checked::try_cast_slice::<u8, NonZeroU32>(mis_aligned_bytes),
Err(CheckedCastError::PodCastError(
Expand Down Expand Up @@ -104,7 +104,7 @@ fn test_try_cast_slice_mut() {
);

// by taking one byte off the front, we're definitely mis-aligned for u32.
let mis_aligned_bytes = &mut the_bytes[1..];
let mis_aligned_bytes = &mut the_bytes[1..][..4];
assert_eq!(
checked::try_cast_slice_mut::<u8, NonZeroU32>(mis_aligned_bytes),
Err(CheckedCastError::PodCastError(
Expand Down

0 comments on commit a5b1bd5

Please sign in to comment.