aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / vendor / bitflags / src / tests / remove.rs
| 1 | use super::*; |
| 2 | |
| 3 | use crate::Flags; |
| 4 | |
| 5 | #[test] |
| 6 | fn cases() { |
| 7 | case( |
| 8 | TestFlags::empty(), |
| 9 | &[ |
| 10 | (TestFlags::A, 0), |
| 11 | (TestFlags::empty(), 0), |
| 12 | (TestFlags::from_bits_retain(1 << 3), 0), |
| 13 | ], |
| 14 | TestFlags::remove, |
| 15 | TestFlags::set, |
| 16 | ); |
| 17 | |
| 18 | case( |
| 19 | TestFlags::A, |
| 20 | &[ |
| 21 | (TestFlags::A, 0), |
| 22 | (TestFlags::empty(), 1), |
| 23 | (TestFlags::B, 1), |
| 24 | ], |
| 25 | TestFlags::remove, |
| 26 | TestFlags::set, |
| 27 | ); |
| 28 | |
| 29 | case( |
| 30 | TestFlags::ABC, |
| 31 | &[ |
| 32 | (TestFlags::A, 1 << 1 | 1 << 2), |
| 33 | (TestFlags::A | TestFlags::C, 1 << 1), |
| 34 | ], |
| 35 | TestFlags::remove, |
| 36 | TestFlags::set, |
| 37 | ); |
| 38 | } |
| 39 | |
| 40 | #[track_caller] |
| 41 | fn case<T: Flags + std::fmt::Debug + Copy>( |
| 42 | value: T, |
| 43 | inputs: &[(T, T::Bits)], |
| 44 | mut inherent_remove: impl FnMut(&mut T, T), |
| 45 | mut inherent_set: impl FnMut(&mut T, T, bool), |
| 46 | ) where |
| 47 | T::Bits: std::fmt::Debug + PartialEq + Copy, |
| 48 | { |
| 49 | for (input, expected) in inputs { |
| 50 | assert_eq!( |
| 51 | *expected, |
| 52 | { |
| 53 | let mut value = value; |
| 54 | inherent_remove(&mut value, *input); |
| 55 | value |
| 56 | } |
| 57 | .bits(), |
| 58 | "{:?}.remove({:?})", |
| 59 | value, |
| 60 | input |
| 61 | ); |
| 62 | assert_eq!( |
| 63 | *expected, |
| 64 | { |
| 65 | let mut value = value; |
| 66 | Flags::remove(&mut value, *input); |
| 67 | value |
| 68 | } |
| 69 | .bits(), |
| 70 | "Flags::remove({:?}, {:?})", |
| 71 | value, |
| 72 | input |
| 73 | ); |
| 74 | |
| 75 | assert_eq!( |
| 76 | *expected, |
| 77 | { |
| 78 | let mut value = value; |
| 79 | inherent_set(&mut value, *input, false); |
| 80 | value |
| 81 | } |
| 82 | .bits(), |
| 83 | "{:?}.set({:?}, false)", |
| 84 | value, |
| 85 | input |
| 86 | ); |
| 87 | assert_eq!( |
| 88 | *expected, |
| 89 | { |
| 90 | let mut value = value; |
| 91 | Flags::set(&mut value, *input, false); |
| 92 | value |
| 93 | } |
| 94 | .bits(), |
| 95 | "Flags::set({:?}, {:?}, false)", |
| 96 | value, |
| 97 | input |
| 98 | ); |
| 99 | } |
| 100 | } |