1 use super::*;
2
3 use crate::Flags;
4
5 #[test]
cases()6 fn cases() {
7 case(
8 TestFlags::empty(),
9 &[(TestFlags::empty(), 0), (TestFlags::all(), 0)],
10 TestFlags::intersection,
11 );
12
13 case(
14 TestFlags::all(),
15 &[
16 (TestFlags::all(), 1 | 1 << 1 | 1 << 2),
17 (TestFlags::A, 1),
18 (TestFlags::from_bits_retain(1 << 3), 0),
19 ],
20 TestFlags::intersection,
21 );
22
23 case(
24 TestFlags::from_bits_retain(1 << 3),
25 &[(TestFlags::from_bits_retain(1 << 3), 1 << 3)],
26 TestFlags::intersection,
27 );
28
29 case(
30 TestOverlapping::AB,
31 &[(TestOverlapping::BC, 1 << 1)],
32 TestOverlapping::intersection,
33 );
34 }
35
36 #[track_caller]
case<T: Flags + std::fmt::Debug + std::ops::BitAnd<Output = T> + std::ops::BitAndAssign + Copy>( value: T, inputs: &[(T, T::Bits)], mut inherent: impl FnMut(T, T) -> T, ) where T::Bits: std::fmt::Debug + PartialEq + Copy,37 fn case<T: Flags + std::fmt::Debug + std::ops::BitAnd<Output = T> + std::ops::BitAndAssign + Copy>(
38 value: T,
39 inputs: &[(T, T::Bits)],
40 mut inherent: impl FnMut(T, T) -> T,
41 ) where
42 T::Bits: std::fmt::Debug + PartialEq + Copy,
43 {
44 for (input, expected) in inputs {
45 assert_eq!(
46 *expected,
47 inherent(value, *input).bits(),
48 "{:?}.intersection({:?})",
49 value,
50 input
51 );
52 assert_eq!(
53 *expected,
54 Flags::intersection(value, *input).bits(),
55 "Flags::intersection({:?}, {:?})",
56 value,
57 input
58 );
59 assert_eq!(
60 *expected,
61 (value & *input).bits(),
62 "{:?} & {:?}",
63 value,
64 input
65 );
66 assert_eq!(
67 *expected,
68 {
69 let mut value = value;
70 value &= *input;
71 value
72 }
73 .bits(),
74 "{:?} &= {:?}",
75 value,
76 input,
77 );
78 }
79 }
80