use std::ffi::c_int;
use bitflags::bitflags;
bitflags! {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Default)]
#[doc(alias(
"GN_VISIBLE", "GN_COLORED", "GN_DEMANGLED", "GN_STRICT", "GN_SHORT", "GN_LONG",
"GN_LOCAL", "GN_ISRET", "GN_NOT_ISRET", "GN_NOT_DUMMY"
))]
pub struct NameFlags: c_int {
#[doc(alias("GN_VISIBLE"))]
const VISIBLE = 0x0001;
#[doc(alias("GN_COLORED"))]
const COLORED = 0x0002;
#[doc(alias("GN_DEMANGLED"))]
const DEMANGLED = 0x0004;
#[doc(alias("GN_STRICT"))]
const STRICT = 0x0008;
#[doc(alias("GN_SHORT"))]
const SHORT = 0x0010;
#[doc(alias("GN_LONG"))]
const LONG = 0x0020;
#[doc(alias("GN_LOCAL"))]
const LOCAL = 0x0040;
#[doc(alias("GN_ISRET"))]
const ISRET = 0x0080;
#[doc(alias("GN_NOT_ISRET"))]
const NOT_ISRET = 0x0100;
#[doc(alias("GN_NOT_DUMMY"))]
const NOT_DUMMY = 0x0200;
}
}
#[cfg(test)]
mod tests {
use assert2::assert;
use proptest::prelude::*;
use rstest::rstest;
use super::*;
#[rstest]
#[case::visible(NameFlags::VISIBLE, 0x0001)]
#[case::colored(NameFlags::COLORED, 0x0002)]
#[case::demangled(NameFlags::DEMANGLED, 0x0004)]
#[case::strict(NameFlags::STRICT, 0x0008)]
#[case::short(NameFlags::SHORT, 0x0010)]
#[case::long(NameFlags::LONG, 0x0020)]
#[case::local(NameFlags::LOCAL, 0x0040)]
#[case::isret(NameFlags::ISRET, 0x0080)]
#[case::not_isret(NameFlags::NOT_ISRET, 0x0100)]
#[case::not_dummy(NameFlags::NOT_DUMMY, 0x0200)]
fn flags_pin_the_raw_sdk_values(#[case] flag: NameFlags, #[case] raw: c_int) {
assert!(flag.bits() == raw);
}
proptest! {
#[test]
fn from_bits_retain_round_trips_every_bit_pattern(raw: c_int) {
prop_assert_eq!(NameFlags::from_bits_retain(raw).bits(), raw);
}
#[test]
fn union_and_intersection_are_raw_bitwise_ops(a: c_int, b: c_int) {
let (fa, fb) = (NameFlags::from_bits_retain(a), NameFlags::from_bits_retain(b));
prop_assert_eq!((fa | fb).bits(), a | b);
prop_assert_eq!((fa & fb).bits(), a & b);
}
#[test]
fn complement_truncates_to_the_known_flag_mask(a: c_int) {
let fa = NameFlags::from_bits_retain(a);
prop_assert_eq!((!fa).bits(), !a & NameFlags::all().bits());
}
}
}