bitflags::bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct PropertyOptions: i32 {
const NONE = 0;
const INSERT_IF_MISSING = 1;
const INSERT_ELEMENT = 1;
const DELETE_IF_EXISTS = 2;
const REMOVE_ELEMENT = 2;
const DO_NOTHING_IF_EXISTS = 4;
const SET_ONLY_IF_DOES_NOT_EXIST = 5;
const COERCE_FROM_NUMBER = 8;
const COERCE_FROM_STRING = 16;
const COERCE_TO_ENUM = 24;
const COERCE_FROM_BOOLEAN = 32;
const COERCE_TO_NUMBER = 64;
const COERCE_TO_STRING = 128;
const COERCE_FROM_ENUM = 192;
const COERCE_TO_BOOLEAN = 256;
const NOT_OWNING = 512;
const REFER_TO_ALIAS = 1024;
const DO_NOT_ADOPT_CURRENT_NAME = 2048;
const CASE_INSENSITIVE = 4096;
const REQUIRE_IDENTICAL_STRUCTURE = 8192;
const DO_NOT_RECURSE = 16384;
const COERCE_FROM_REFERENCE = 65536;
const COERCE_TO_REFERENCE = 131_072;
const COERCE = 197_112;
const COERCE_BAD_NUMBERS_TO_ZERO = 262_144;
const OVERRIDE_NOT_DELETABLE = 4_194_304;
const DO_NOT_SHARE_PROPERTIES = 134_217_728;
const COPY_ALL_FLAGS = 536_870_912;
}
}
bitflags::bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct GetTemplatesFileOptions: i32 {
const NONE = 0;
const LOAD_IF_NOT_LOADED = 1;
}
}
#[cfg(test)]
mod tests {
use super::{GetTemplatesFileOptions, PropertyOptions};
#[test]
fn none_is_empty_and_combines_to_nothing() {
assert!(PropertyOptions::NONE.is_empty());
assert_eq!(PropertyOptions::NONE.bits(), 0);
}
#[test]
fn flags_combine_and_test_membership() {
let options = PropertyOptions::INSERT_IF_MISSING | PropertyOptions::COERCE_TO_STRING;
assert!(options.contains(PropertyOptions::INSERT_IF_MISSING));
assert!(options.contains(PropertyOptions::COERCE_TO_STRING));
assert!(!options.contains(PropertyOptions::DO_NOT_RECURSE));
assert_eq!(options.bits(), 1 | 128);
}
#[test]
fn round_trips_through_raw_bits() {
let raw = PropertyOptions::COERCE.bits();
assert_eq!(
PropertyOptions::from_bits_retain(raw),
PropertyOptions::COERCE
);
}
#[test]
fn asking_for_the_templates_file_defaults_to_not_loading_it() {
assert_eq!(GetTemplatesFileOptions::default().bits(), 0);
assert!(
!GetTemplatesFileOptions::default()
.contains(GetTemplatesFileOptions::LOAD_IF_NOT_LOADED)
);
}
#[test]
fn unknown_bits_from_the_engine_are_preserved() {
let unknown = 1 << 30;
assert_eq!(PropertyOptions::from_bits_retain(unknown).bits(), unknown);
}
}