use unicode_normalization::UNICODE_VERSION;
const PROVENANCE: &str = include_str!("../docs/provenance.md");
const RUST_DOC: &str = include_str!("../src/api/text.rs");
const PYTHON_DOC: &str = include_str!("../python/disarm/_api.py");
fn version() -> String {
let (major, minor, patch) = UNICODE_VERSION;
format!("{major}.{minor}.{patch}")
}
fn flatten(source: &str) -> String {
source
.lines()
.map(|line| line.trim().trim_start_matches("///").trim())
.collect::<Vec<_>>()
.join(" ")
}
fn provenance_row() -> &'static str {
PROVENANCE
.lines()
.find(|line| line.contains("unicode-normalization"))
.expect("docs/provenance.md has no `unicode-normalization` row")
}
#[test]
fn provenance_row_states_the_crate_version() {
let version = version();
let row = provenance_row();
assert!(
row.contains(&version),
"docs/provenance.md's normalization row does not name UCD {version}.\n\
The crate moved; the row did not. Row was:\n {row}"
);
}
#[test]
fn the_rustdoc_states_the_crate_version() {
let version = version();
let wanted = format!("UCD {version}");
assert!(
flatten(RUST_DOC).contains(&wanted),
"src/api/text.rs does not document {wanted} for `normalize`. \
`unicode-normalization` moved and the rustdoc did not follow."
);
}
#[test]
fn the_python_docstring_states_the_crate_version() {
let version = version();
let wanted = format!("UCD {version}");
assert!(
flatten(PYTHON_DOC).contains(&wanted),
"python/disarm/_api.py does not document {wanted} for `normalize`. \
`unicode-normalization` moved and the docstring did not follow."
);
}
#[test]
fn the_three_surfaces_do_not_disagree_with_each_other() {
let version = version();
let stated = [
("docs/provenance.md", provenance_row().contains(&version)),
("src/api/text.rs", flatten(RUST_DOC).contains(&version)),
(
"python/disarm/_api.py",
flatten(PYTHON_DOC).contains(&version),
),
];
let missing: Vec<&str> = stated
.iter()
.filter(|(_, found)| !found)
.map(|(name, _)| *name)
.collect();
assert!(
missing.is_empty(),
"UCD {version} is documented in some places and not others; missing from {missing:?}"
);
}