interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / vendor / bitflags / src / tests / from_bits.rs

45 lines · 1006 bytes Raw Blame History
1use super::*;
2
3use crate::Flags;
4
5#[test]
6fn cases() {
7 case(Some(0), 0, TestFlags::from_bits);
8 case(Some(1), 1, TestFlags::from_bits);
9 case(
10 Some(1 | 1 << 1 | 1 << 2),
11 1 | 1 << 1 | 1 << 2,
12 TestFlags::from_bits,
13 );
14
15 case(None, 1 << 3, TestFlags::from_bits);
16 case(None, 1 | 1 << 3, TestFlags::from_bits);
17
18 case(Some(1 | 1 << 1), 1 | 1 << 1, TestOverlapping::from_bits);
19
20 case(Some(1 << 1), 1 << 1, TestOverlapping::from_bits);
21
22 case(Some(1 << 5), 1 << 5, TestExternal::from_bits);
23}
24
25#[track_caller]
26fn case<T: Flags>(
27 expected: Option<T::Bits>,
28 input: T::Bits,
29 inherent: impl FnOnce(T::Bits) -> Option<T>,
30) where
31 <T as Flags>::Bits: std::fmt::Debug + PartialEq,
32{
33 assert_eq!(
34 expected,
35 inherent(input).map(|f| f.bits()),
36 "T::from_bits({:?})",
37 input
38 );
39 assert_eq!(
40 expected,
41 T::from_bits(input).map(|f| f.bits()),
42 "Flags::from_bits({:?})",
43 input
44 );
45}