mod terms;
pub use terms::*;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Term {
accession: &'static str,
name: &'static str,
}
impl Term {
pub const fn accession(self) -> &'static str {
self.accession
}
pub const fn name(self) -> &'static str {
self.name
}
pub fn cv_ref(self) -> &'static str {
if self.accession.starts_with("UO:") {
"UO"
} else {
"MS"
}
}
}
pub fn lookup(accession: &str) -> Option<Term> {
ALL.iter().copied().find(|t| t.accession == accession)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn lookup_finds_generated_terms() {
assert_eq!(lookup("MS:1000016"), Some(SCAN_START_TIME));
assert_eq!(lookup("MS:0000000"), None);
assert_eq!(MINUTE.cv_ref(), "UO");
assert_eq!(MZ.cv_ref(), "MS");
}
#[test]
fn accessions_are_unique() {
let mut seen = std::collections::HashSet::new();
for t in ALL {
assert!(seen.insert(t.accession()), "duplicate {}", t.accession());
}
}
}