Calculate bad children on-the-fly.

This commit is contained in:
Tom Alexander 2023-04-11 19:22:42 -04:00
parent 52b401d548
commit 52df376553
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -11,10 +11,9 @@ pub struct DiffResult {
children: Vec<DiffResult>,
}
#[derive(Debug)]
#[derive(Debug, PartialEq)]
pub enum DiffStatus {
Good,
ChildBad,
Bad,
}
@ -24,10 +23,22 @@ impl DiffResult {
}
fn print_indented(&self, indentation: usize) -> Result<(), Box<dyn std::error::Error>> {
let status_text = {
match self.status {
DiffStatus::Good => {
if self.has_bad_children() {
"BADCHILD"
} else {
"GOOD"
}
},
DiffStatus::Bad => "BAD",
}
};
println!(
"{}{:?} {}",
"{}{} {}",
" ".repeat(indentation),
self.status,
status_text,
self.name
);
for child in self.children.iter() {
@ -35,6 +46,10 @@ impl DiffResult {
}
Ok(())
}
pub fn has_bad_children(&self) -> bool {
self.children.iter().any(|child| {child.status == DiffStatus::Bad || child.has_bad_children()})
}
}
pub fn compare_document<'s>(