Skip to content

Commit 81196f2

Browse files
authored
Add tests for TryFrom<&mut [T]> for &mut Array (#206)
1 parent c34d536 commit 81196f2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tests/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,20 @@ fn tryfrom_slice_for_array_ref() {
219219
assert!(<&Array::<u8, U7>>::try_from(EXAMPLE_SLICE).is_err());
220220
}
221221

222+
#[test]
223+
fn tryfrom_mut_slice_for_array_mut() {
224+
let mut example_arr = [1, 2, 3, 4, 5, 6];
225+
226+
assert!(<&mut Array<u8, U0>>::try_from(example_arr.as_mut()).is_err());
227+
assert!(<&mut Array::<u8, U3>>::try_from(example_arr.as_mut()).is_err());
228+
229+
let array_ref =
230+
<&mut Array<u8, U6>>::try_from(example_arr.as_mut()).expect("slice contains 6 bytes");
231+
assert_eq!(array_ref.as_slice(), EXAMPLE_SLICE);
232+
233+
assert!(<&mut Array::<u8, U7>>::try_from(example_arr.as_mut()).is_err());
234+
}
235+
222236
#[test]
223237
fn slice_as_array() {
224238
type A = Array<u8, U2>;

0 commit comments

Comments
 (0)