use super::*;
use crate::persist::local::models::catalogued_test::TestLanguage;
use std::sync::Arc;
const MEMBERS: [&str; 3] = ["family/one", "family/two", "family/three"];
fn members() -> Vec<String> {
MEMBERS.iter().map(|m| m.to_string()).collect()
}
fn test(repo: &str, number: i64, name: &str, description: &str) -> CataloguedTest {
CataloguedTest {
id: format!("{repo}:{name}"),
repo: repo.to_string(),
language: TestLanguage::Rust,
number: Some(number),
function_name: name.to_string(),
description: description.to_string(),
file_path: "src/lib.rs".to_string(),
line_number: number,
}
}
fn catalogue(rows: &[CataloguedTest]) -> CatalogueRepo {
let service = crate::persist::global::DatabaseService::new_in_memory().expect("an in-memory database");
let repo = CatalogueRepo::new(Arc::new(service), "fleet/main");
for member in MEMBERS {
let owned: Vec<CataloguedTest> = rows
.iter()
.filter(|row| row.repo == member)
.cloned()
.collect();
repo.replace_repo(member, &owned).expect("the rows are written");
}
repo
}
#[test]
fn test11254_a_number_missing_from_a_mirror_is_reported_as_a_gap() {
let rows = vec![
test("family/one", 100, "test0100_everywhere", "everywhere"),
test("family/two", 100, "test0100_everywhere", "everywhere"),
test("family/three", 100, "test0100_everywhere", "everywhere"),
test("family/one", 200, "test0200_only_here", "only here"),
test("family/two", 200, "test0200_only_here", "only here"),
];
let document = parity_markdown(&catalogue(&rows), &members()).expect("the report renders");
let gaps = section(&document, "## Parity gaps");
assert!(
gaps.contains("TEST200") && gaps.contains("three"),
"the gap must be reported, and must name the mirror it is missing from:\n{gaps}"
);
assert!(
!gaps.contains("TEST100"),
"a number every mirror has is not a gap:\n{gaps}"
);
assert!(
document.contains("- Shared numbers with a parity gap (missing from ≥1 mirror): **1**"),
"the summary must agree with the table:\n{document}"
);
}
#[test]
fn test11255_the_shared_range_decides_whether_a_solo_test_is_a_backlog_item() {
let rows = vec![
test("family/one", 300, "test0300_shared_range_solo", "ports to the others"),
test("family/one", 8300, "test8300_impl_specific", "this mirror's own"),
];
let document = parity_markdown(&catalogue(&rows), &members()).expect("the report renders");
let worklist = section(&document, "## Solo tests in the shared range");
assert!(
worklist.contains("TEST300"),
"a solo test below the ceiling is a port target:\n{worklist}"
);
assert!(
!worklist.contains("TEST8300"),
"a solo test at or above the ceiling is correctly placed, not a backlog item:\n{worklist}"
);
assert!(
section(&document, "## Parity gaps").lines().all(|l| !l.contains("TEST8300")),
"an implementation-specific number is not a parity gap:\n{document}"
);
}
#[test]
fn test11256_divergent_descriptions_are_shown_and_whitespace_is_not_divergence() {
let rows = vec![
test("family/one", 400, "test0400_a", "the parser rejects an empty header"),
test("family/two", 400, "test0400_a", "the parser rejects an empty\nheader"),
test("family/one", 500, "test0500_b", "a cap resolves to its alias"),
test("family/two", 500, "test0500_b", "a media resolves to its alias"),
];
let document = parity_markdown(&catalogue(&rows), &members()).expect("the report renders");
let divergent = section(&document, "## Divergent descriptions");
assert!(
divergent.contains("### TEST500"),
"two mirrors describing one number differently must be shown:\n{divergent}"
);
assert!(
divergent.contains("a cap resolves to its alias")
&& divergent.contains("a media resolves to its alias"),
"and shown side by side, because that is the only way to judge them:\n{divergent}"
);
assert!(
!divergent.contains("### TEST400"),
"the same sentence wrapped differently is not a divergence:\n{divergent}"
);
}
#[test]
fn test11257_a_description_cannot_break_the_row_it_is_written_into() {
let rows = vec![test(
"family/one",
600,
"test0600_awkward",
"/// a | b\n/// and a second line",
)];
let document = parity_markdown(&catalogue(&rows), &members()).expect("the report renders");
let row = document
.lines()
.find(|line| line.contains("TEST600"))
.expect("the solo test is listed")
.to_string();
assert!(
!row.contains("\\n"),
"the description must be flattened onto the row: {row}"
);
assert_eq!(
row.matches(" | ").count(),
4,
"a five-column row has four separators; an unescaped pipe adds one: {row}"
);
assert!(
row.contains("a \\| b"),
"a pipe in the description must be escaped, not dropped: {row}"
);
}
#[test]
fn test11258_the_parity_document_does_not_name_the_private_tool() {
let rows = vec![test("family/one", 700, "test0700_a", "something")];
let document = parity_markdown(&catalogue(&rows), &members()).expect("the report renders");
let tool = concat!("sd", "x");
assert!(
!document.to_lowercase().contains(tool),
"the document names the private tool:\n{document}"
);
}
fn section<'a>(document: &'a str, heading: &str) -> &'a str {
let start = document
.find(heading)
.unwrap_or_else(|| panic!("the document has no '{heading}' section:\n{document}"));
let rest = &document[start + heading.len()..];
match rest.find("\n## ") {
Some(end) => &rest[..end],
None => rest,
}
}