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/symmetric_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 / symmetric_difference.rs` 110 lines ยท 2638 bytes Raw Blame History 1 use super::*; 2 3 use crate::Flags; 4 5 #[test] 6 fn cases() { 7 case( 8 TestFlags::empty(), 9 &[ 10 (TestFlags::empty(), 0), 11 (TestFlags::all(), 1 | 1 << 1 | 1 << 2), 12 (TestFlags::from_bits_retain(1 << 3), 1 << 3), 13 ], 14 TestFlags::symmetric_difference, 15 TestFlags::toggle, 16 ); 17 18 case( 19 TestFlags::A, 20 &[ 21 (TestFlags::empty(), 1), 22 (TestFlags::A, 0), 23 (TestFlags::all(), 1 << 1 | 1 << 2), 24 ], 25 TestFlags::symmetric_difference, 26 TestFlags::toggle, 27 ); 28 29 case( 30 TestFlags::A | TestFlags::B | TestFlags::from_bits_retain(1 << 3), 31 &[ 32 (TestFlags::ABC, 1 << 2 | 1 << 3), 33 (TestFlags::from_bits_retain(1 << 3), 1 | 1 << 1), 34 ], 35 TestFlags::symmetric_difference, 36 TestFlags::toggle, 37 ); 38 } 39 40 #[track_caller] 41 fn case + std::ops::BitXorAssign + Copy>( 42 value: T, 43 inputs: &[(T, T::Bits)], 44 mut inherent_sym_diff: impl FnMut(T, T) -> T, 45 mut inherent_toggle: impl FnMut(&mut T, T), 46 ) where 47 T::Bits: std::fmt::Debug + PartialEq + Copy, 48 { 49 for (input, expected) in inputs { 50 assert_eq!( 51 *expected, 52 inherent_sym_diff(value, *input).bits(), 53 "{:?}.symmetric_difference({:?})", 54 value, 55 input 56 ); 57 assert_eq!( 58 *expected, 59 Flags::symmetric_difference(value, *input).bits(), 60 "Flags::symmetric_difference({:?}, {:?})", 61 value, 62 input 63 ); 64 assert_eq!( 65 *expected, 66 (value ^ *input).bits(), 67 "{:?} ^ {:?}", 68 value, 69 input 70 ); 71 assert_eq!( 72 *expected, 73 { 74 let mut value = value; 75 value ^= *input; 76 value 77 } 78 .bits(), 79 "{:?} ^= {:?}", 80 value, 81 input, 82 ); 83 84 assert_eq!( 85 *expected, 86 { 87 let mut value = value; 88 inherent_toggle(&mut value, *input); 89 value 90 } 91 .bits(), 92 "{:?}.toggle({:?})", 93 value, 94 input, 95 ); 96 97 assert_eq!( 98 *expected, 99 { 100 let mut value = value; 101 Flags::toggle(&mut value, *input); 102 value 103 } 104 .bits(), 105 "{:?}.toggle({:?})", 106 value, 107 input, 108 ); 109 } 110 }