#[test] fn test_or_operations() {
assert_eq!(flag_to_string(Flags::A | Flags::B), "A or B");
assert_eq!(
flag_to_string(Flags::A | Flags::B | Flags::C), "A or B or C"
);
assert_eq!(
flag_to_string(Flags::A | Flags::B | Flags::C | Flags::D), "All flags"
);
}
#[test] fn test_and_operations() {
assert_eq!(flag_to_string(Flags::A & Flags::A), "A");
assert_eq!(flag_to_string(Flags::A & Flags::B), "A and B | empty");
assert_eq!(
flag_to_string(Flags::A & Flags::B & Flags::C), "A and B | empty"
); // Since A, B, and C are mutually exclusive, the result of A & B & C is 0 ==> A & B & C = 0000 (i.e., empty). // However, in the bitflags_match! statement (actually is if {..} else if {..} .. else {..}), // the "A & B = 0000" condition is listed first, so 0000 will match "A & B" first, // resulting in the output of the "A and B | empty" branch.
assert_eq!(
flag_to_string(Flags::A & Flags::B & Flags::C & Flags::D), "A and B | empty"
);
}
#[test] fn test_xor_operations() {
assert_eq!(flag_to_string(Flags::A ^ Flags::B), "A or B"); // A | B = A ^ B == 0011
assert_eq!(flag_to_string(Flags::A ^ Flags::A), "A and B | empty");
assert_eq!(
flag_to_string(Flags::A ^ Flags::B ^ Flags::C), "A or B or C"
);
}
#[test] fn test_complex_operations() {
assert_eq!(flag_to_string(Flags::A | (Flags::B & Flags::C)), "A");
assert_eq!(
flag_to_string((Flags::A | Flags::B) & (Flags::B | Flags::C)), "B"
);
assert_eq!(
flag_to_string(Flags::A ^ (Flags::B | Flags::C)), "A or B or C"
);
}
#[test] fn test_empty_and_full_flags() {
assert_eq!(flag_to_string(Flags::empty()), "A and B | empty");
assert_eq!(flag_to_string(Flags::all()), "All flags");
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.