Skip to content

Commit 25d2b78

Browse files
authored
Add tests for TryFrom<&Box> and ...&Vec> for Array (#212)
These have a `Clone` bound and otherwise act like the `TryFrom` impl which converts from slices by cloning their contents
1 parent dd850e2 commit 25d2b78

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

tests/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,13 +490,30 @@ mod allocating {
490490
);
491491
}
492492

493+
#[test]
494+
fn array_try_from_boxed_slice_ref() {
495+
type A = Array<u8, U2>;
496+
assert!(A::try_from(&vec![1].into_boxed_slice()).is_err());
497+
assert_eq!(
498+
&A::try_from(&vec![1, 2].into_boxed_slice()).unwrap(),
499+
&[1, 2]
500+
);
501+
}
502+
493503
#[test]
494504
fn array_try_from_vec() {
495505
type A = Array<u8, U2>;
496506
assert!(A::try_from(vec![1]).is_err());
497507
assert_eq!(&A::try_from(vec![1, 2]).unwrap(), &[1, 2]);
498508
}
499509

510+
#[test]
511+
fn array_try_from_vec_ref() {
512+
type A = Array<u8, U2>;
513+
assert!(A::try_from(&vec![1]).is_err());
514+
assert_eq!(&A::try_from(&vec![1, 2]).unwrap(), &[1, 2]);
515+
}
516+
500517
#[test]
501518
fn boxed_slice_from_array() {
502519
let array: Array<u8, U4> = Array([1, 2, 3, 4]);

0 commit comments

Comments
 (0)