MCPcopy Create free account
hub / github.com/bitflags/bitflags / cases

Function cases

src/tests/difference.rs:6–47  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4
5#[test]
6fn cases() {
7 case(
8 TestFlags::A | TestFlags::B,
9 &[
10 (TestFlags::A, 1 << 1),
11 (TestFlags::B, 1),
12 (TestFlags::from_bits_retain(1 << 3), 1 | 1 << 1),
13 ],
14 TestFlags::difference,
15 );
16
17 case(
18 TestFlags::from_bits_retain(1 | 1 << 3),
19 &[
20 (TestFlags::A, 1 << 3),
21 (TestFlags::from_bits_retain(1 << 3), 1),
22 ],
23 TestFlags::difference,
24 );
25
26 case(
27 TestExternal::from_bits_retain(!0),
28 &[(TestExternal::A, 0b1111_1110)],
29 TestExternal::difference,
30 );
31
32 assert_eq!(
33 0b1111_1110,
34 (TestExternal::from_bits_retain(!0) & !TestExternal::A).bits()
35 );
36
37 assert_eq!(
38 0b1111_1110,
39 (TestFlags::from_bits_retain(!0).difference(TestFlags::A)).bits()
40 );
41
42 // The `!` operator unsets bits that don't correspond to known flags
43 assert_eq!(
44 1 << 1 | 1 << 2,
45 (TestFlags::from_bits_retain(!0) & !TestFlags::A).bits()
46 );
47}
48
49#[track_caller]
50fn case<T: Flags + std::fmt::Debug + std::ops::Sub<Output = T> + std::ops::SubAssign + Copy>(

Callers

nothing calls this directly

Calls 1

caseFunction · 0.70

Tested by

no test coverage detected