pub(super) const FLAGS: [&str; 4] = ["APPEND_ONLY", "HASH_CHAIN", "BITEMPORAL", "SIGNED_DELTAS"];
pub(super) fn flag_index(word: &str) -> Option<usize> {
FLAGS.iter().position(|f| word.eq_ignore_ascii_case(f))
}
pub(super) fn is_truthy(value: &str) -> bool {
["true", "1", "on", "yes"]
.iter()
.any(|truthy| value.trim().eq_ignore_ascii_case(truthy))
}
pub(super) fn flag_names(set: [bool; FLAGS.len()]) -> Vec<String> {
FLAGS
.iter()
.zip(set)
.filter(|(_, enabled)| *enabled)
.map(|(flag, _)| (*flag).to_string())
.collect()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn flag_words_match_whole_and_case_insensitive() {
assert_eq!(flag_index("append_only"), Some(0));
assert_eq!(flag_index("Signed_Deltas"), Some(3));
assert_eq!(flag_index("hash_chains"), None);
}
#[test]
fn only_true_values_set_an_assigned_flag() {
for v in ["true", "TRUE", "1", "on", "yes"] {
assert!(is_truthy(v), "{v}");
}
for v in ["false", "no", "0", "maybe"] {
assert!(!is_truthy(v), "{v}");
}
}
#[test]
fn names_follow_flag_order() {
assert_eq!(
flag_names([false, true, true, false]),
vec!["HASH_CHAIN", "BITEMPORAL"]
);
}
}