Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/bitflags/src/tests/difference.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / vendor / bitflags / src / tests / difference.rs` 92 lines ยท 2144 bytes Raw Blame History 1 use super::*; 2 3 use crate::Flags; 4 5 #[test] 6 fn 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] 50 fn case + std::ops::SubAssign + Copy>( 51 value: T, 52 inputs: &[(T, T::Bits)], 53 mut inherent: impl FnMut(T, T) -> T, 54 ) where 55 T::Bits: std::fmt::Debug + PartialEq + Copy, 56 { 57 for (input, expected) in inputs { 58 assert_eq!( 59 *expected, 60 inherent(value, *input).bits(), 61 "{:?}.difference({:?})", 62 value, 63 input 64 ); 65 assert_eq!( 66 *expected, 67 Flags::difference(value, *input).bits(), 68 "Flags::difference({:?}, {:?})", 69 value, 70 input 71 ); 72 assert_eq!( 73 *expected, 74 (value - *input).bits(), 75 "{:?} - {:?}", 76 value, 77 input 78 ); 79 assert_eq!( 80 *expected, 81 { 82 let mut value = value; 83 value -= *input; 84 value 85 } 86 .bits(), 87 "{:?} -= {:?}", 88 value, 89 input, 90 ); 91 } 92 }