use std::collections::HashSet;
use std::sync::LazyLock;
const CULTURE_COLLECTIONS_TXT: &str = include_str!("../../resources/culture-collections.txt");
static ACRONYMS: LazyLock<HashSet<&'static str>> = LazyLock::new(|| {
CULTURE_COLLECTIONS_TXT
.lines()
.map(str::trim)
.filter(|line| !line.is_empty() && !line.starts_with('#'))
.collect()
});
pub(crate) fn acronym_alternation() -> &'static str {
static ALT: LazyLock<String> = LazyLock::new(|| {
let mut v: Vec<&str> = ACRONYMS.iter().copied().collect();
v.sort_by(|a, b| b.len().cmp(&a.len()).then(a.cmp(b)));
format!("(?:{})", v.join("|"))
});
&ALT
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn seed_list_loads_and_skips_the_comment_header() {
assert_eq!(ACRONYMS.len(), 29);
assert!(!ACRONYMS.iter().any(|a| a.starts_with('#')));
}
#[test]
fn alternation_contains_the_major_acronyms() {
let alt = acronym_alternation();
for a in ["ATCC", "DSM", "DSMZ", "CBS", "JCM", "NBRC", "LMG"] {
assert!(alt.contains(a), "{a} must be in the alternation {alt}");
}
}
#[test]
fn alternation_lists_longer_acronyms_before_their_prefixes() {
let alt = acronym_alternation();
let dsmz = alt.find("DSMZ").expect("DSMZ present");
let dsm = alt
.find("DSM|")
.or_else(|| alt.find("DSM)"))
.expect("DSM present");
assert!(dsmz < dsm, "DSMZ must precede the bare DSM in {alt}");
assert!(alt.starts_with("(?:"));
}
}