#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
const LIB: &str = include_str!("../src/lib.rs");
const README: &str = include_str!("../README.md");
const THE_SENTENCE: &str = "A judge score is not a substitute for a deterministic assertion";
#[test]
fn the_crate_documentation_says_a_judge_score_is_not_a_substitute() {
let heading = format!("//! # {THE_SENTENCE}");
assert!(
LIB.contains(&heading),
"the sentence must be a heading in the crate documentation, not a remark buried in a \
paragraph: `{heading}`"
);
let position = LIB.find(&heading).unwrap_or(usize::MAX);
let features = LIB.find("//! # What is here").unwrap_or(usize::MAX);
assert!(
position < features,
"it must come before the feature tour, because it is more important than the features"
);
}
#[test]
fn the_readme_says_a_judge_score_is_not_a_substitute() {
let heading = format!("## {THE_SENTENCE}");
assert!(
README.contains(&heading),
"the sentence must be a section heading in the README: `{heading}`"
);
}
fn prose(text: &str) -> String {
text.replace("//!", " ")
.replace(['*', '`', '[', ']'], "")
.split_whitespace()
.collect::<Vec<&str>>()
.join(" ")
}
#[test]
fn both_explain_why_the_type_level_separation_makes_it_impossible() {
for (name, text) in [("lib.rs", LIB), ("README.md", README)] {
let prose = prose(text);
let start = prose
.find(THE_SENTENCE)
.unwrap_or_else(|| panic!("{name} states the rule"));
let section = &prose[start..];
for evidence in [
"JudgeInput",
"two strings",
"JudgeCriterion",
"exactly four variants",
] {
assert!(
section.contains(evidence),
"{name} must explain the mechanism beside the rule, and does not mention \
`{evidence}`"
);
}
}
}