Skip to content

Commit c34d536

Browse files
authored
Add tests for From impls on Box and Vec (#205)
1 parent 7894fd6 commit c34d536

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/mod.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,32 @@ fn slice_as_flattened() {
400400
assert_eq!(Array::slice_as_flattened(slice), &[1, 2, 3, 4, 5, 6, 7, 8]);
401401
}
402402

403+
#[cfg(feature = "alloc")]
404+
mod allocating {
405+
use super::*;
406+
use typenum::U4;
407+
408+
#[test]
409+
fn boxed_slice_from_array() {
410+
let array: Array<u8, U4> = Array([1, 2, 3, 4]);
411+
let boxed_slice1: Box<[u8]> = Box::from(array);
412+
assert_eq!(&*boxed_slice1, &[1, 2, 3, 4]);
413+
414+
let boxed_slice2: Box<[u8]> = Box::from(&array);
415+
assert_eq!(&*boxed_slice2, &[1, 2, 3, 4]);
416+
}
417+
418+
#[test]
419+
fn vec_from_array() {
420+
let array: Array<u8, U4> = Array([1, 2, 3, 4]);
421+
let vec1: Vec<u8> = Vec::from(array);
422+
assert_eq!(&vec1, &[1, 2, 3, 4]);
423+
424+
let vec2: Vec<u8> = Vec::from(&array);
425+
assert_eq!(&*vec2, &[1, 2, 3, 4]);
426+
}
427+
}
428+
403429
#[test]
404430
#[cfg(feature = "zerocopy")]
405431
#[allow(unused)]

0 commit comments

Comments
 (0)