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