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_truncate.rs

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