Debian Codegraph @

debian/rust-vendor/bitvec/src/vec/tests/traits.rs

raw
1 use alloc::{
2 borrow::{
3 Borrow,
4 BorrowMut,
5 Cow,
6 },
7 vec::Vec,
8 };
9 use core::{
10 convert::TryFrom,
11 fmt::Debug,
12 hash::Hash,
13 iter::FromIterator,
14 ops::{
15 Deref,
16 DerefMut,
17 Index,
18 Range,
19 },
20 panic::{
21 RefUnwindSafe,
22 UnwindSafe,
23 },
24 };
25 #[cfg(feature = "std")]
26 use std::io::Write;
27
28 use static_assertions::*;
29
30 use crate::prelude::*;
31
32 #[test]
33 fn alloc_impl() {
34 assert_impl_all!(BitVec<usize, Lsb0>:
35 AsMut<BitSlice<usize, Lsb0>>,
36 AsMut<BitVec<usize, Lsb0>>,
37 AsRef<BitSlice<usize, Lsb0>>,
38 AsRef<BitVec<usize, Lsb0>>,
39 Borrow<BitSlice<usize, Lsb0>>,
40 BorrowMut<BitSlice<usize, Lsb0>>,
41 Clone,
42 Debug,
43 Default,
44 Deref,
45 DerefMut,
46 Drop,
47 Eq,
48 Extend<&'static bool>,
49 Extend<bool>,
50 From<&'static BitSlice<usize, Lsb0>>,
51 From<&'static mut BitSlice<usize, Lsb0>>,
52 From<BitArray<[usize; 20], Lsb0>>,
53 From<BitBox<usize, Lsb0>>,
54 From<Cow<'static, BitSlice<usize, Lsb0>>>,
55 FromIterator<bool>,
56 Hash,
57 Index<usize>,
58 Index<Range<usize>>,
59 IntoIterator,
60 Ord,
61 PartialEq<&'static BitSlice<usize, Lsb0>>,
62 PartialEq<BitArray<[usize; 20], Lsb0>>,
63 RefUnwindSafe,
64 Send,
65 Sync,
66 TryFrom<Vec<usize>>,
67 Unpin,
68 UnwindSafe,
69 );
70 }
71
72 #[test]
73 #[cfg(feature = "std")]
74 fn std_impl() {
75 assert_impl_all!(BitVec<usize, Lsb0>: Write);
76 }
77
78 #[test]
79 fn format() {
80 #[cfg(not(feature = "std"))]
81 use alloc::format;
82
83 let bv = bitvec![0, 0, 1, 1, 0, 1, 0, 1];
84 assert_eq!(format!("{}", bv), format!("{}", bv.as_bitslice()));
85 assert_eq!(format!("{:b}", bv), format!("{:b}", bv.as_bitslice()));
86 assert_eq!(format!("{:o}", bv), format!("{:o}", bv.as_bitslice()));
87 assert_eq!(format!("{:x}", bv), format!("{:x}", bv.as_bitslice()));
88 assert_eq!(format!("{:X}", bv), format!("{:X}", bv.as_bitslice()));
89
90 let text = format!("{:?}", bitvec![u8, Msb0; 0, 1, 0, 0]);
91 assert!(
92 text.starts_with("BitVec<u8, bitvec::order::Msb0> { addr: 0x"),
93 "{}",
94 text
95 );
96 assert!(
97 text.contains(", head: 000, bits: 4, capacity: "),
98 "{}",
99 text
100 );
101 assert!(text.ends_with(" } [0, 1, 0, 0]"), "{}", text);
102 }