use std::{fs, path::PathBuf};
pub fn each_fixture(corpus: &str, expected: usize, check: impl Fn(&str, &str)) {
let dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests/corpus")
.join(corpus);
let mut total = 0;
for entry in fs::read_dir(&dir).expect("read corpus dir") {
let path = entry.expect("dir entry").path();
if path.extension().and_then(|e| e.to_str()) != Some("vcf") {
continue;
}
let name = path.file_name().unwrap().to_str().unwrap().to_string();
let input = String::from_utf8(fs::read(&path).expect("read fixture"))
.unwrap_or_else(|_| panic!("{name} is not valid UTF-8"));
total += 1;
check(&name, &input);
}
assert_eq!(
total, expected,
"expected {expected} fixtures, found {total}"
);
}