macro_rules! documents {
($($name:literal),* $(,)?) => {
pub(crate) fn document(name: &str) -> &'static str {
match name {
$($name => include_str!(concat!("../../fixtures/documents/", $name)),)*
other => panic!("no corpus document named {other:?}"),
}
}
pub(crate) const DOCUMENTS: &[&str] = &[$($name),*];
};
}
documents!(
"app.log",
"calendar.js",
"dates.ts",
"events.json",
"feed.xml",
"handler.go",
"notations.txt",
"page.html",
"project.toml",
"release-notes.md",
"rows.csv",
"schedule.yaml",
"settings.py",
);
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn every_document_is_present_and_not_empty() {
for name in DOCUMENTS {
assert!(!document(name).is_empty(), "{name}");
}
}
#[test]
#[should_panic(expected = "no corpus document named")]
fn an_unknown_document_is_a_broken_test() {
document("nope.json");
}
}