1 //! Unit tests for the `boxed` module.
2 
3 use crate::prelude::*;
4 
5 #[test]
6 #[allow(deprecated)]
api()7 fn api() {
8 	let boxed: Box<[u8]> = Box::new([0; 4]);
9 	let bb = BitBox::<LocalBits, _>::from_boxed_slice(boxed);
10 	assert_eq!(bb, bits![0; 32]);
11 	let boxed = bb.into_boxed_slice();
12 	assert_eq!(boxed[..], [0u8; 4][..]);
13 
14 	let pinned = BitBox::pin(bits![0, 1, 0, 1]);
15 	let unpinned = BitBox::new(bits![0, 1, 0, 1]);
16 	assert_eq!(pinned.as_ref().get_ref(), unpinned[..]);
17 
18 	let boxed = bitbox![0; 10];
19 	let bitptr = boxed.bitptr();
20 	let reboxed = unsafe { BitBox::from_raw(BitBox::into_raw(boxed)) };
21 	let bv = reboxed.into_bitvec();
22 	let bb = bv.into_boxed_bitslice();
23 	assert_eq!(bb.bitptr(), bitptr);
24 
25 	let mut bb = 0b1001_0110u8.view_bits::<Msb0>()[2 .. 6]
26 		.to_bitvec()
27 		.into_boxed_bitslice();
28 	bb.set_uninitialized(false);
29 	assert_eq!(bb.as_slice(), &[0b0001_0100]);
30 	bb.set_uninitialized(true);
31 	assert_eq!(bb.as_slice(), &[0b1101_0111]);
32 	assert_eq!(bb, bits![0, 1, 0, 1]);
33 }
34