use std::collections::BTreeSet;
use low_expectations::ExpectationSuite;
use prosesmasher_domain_types::{CheckConfig, Document, Locale};
use crate::check::Check;
#[derive(Debug)]
pub struct SimplicityCheck;
impl Check for SimplicityCheck {
fn id(&self) -> &'static str {
"simplicity"
}
fn label(&self) -> &'static str {
"Simplicity"
}
fn supported_locales(&self) -> Option<&'static [Locale]> {
None
}
fn run(&self, doc: &Document, config: &CheckConfig, suite: &mut ExpectationSuite) {
let simplicity_pairs = super::resolve_simplicity_pairs(config);
if simplicity_pairs.is_empty() {
return;
}
let complex_set: BTreeSet<String> = simplicity_pairs
.iter()
.map(|pair| pair.complex.to_lowercase())
.collect();
let all_words: Vec<&str> = doc
.sections
.iter()
.flat_map(|s| &s.blocks)
.flat_map(|b| super::collect_paragraph_words(b))
.collect();
let _result = suite
.expect_terms_absent("simplicity", &all_words, &complex_set)
.label("Simplicity")
.checking("plain language");
}
}
#[cfg(test)]
#[path = "simplicity_tests.rs"]
mod tests;