Calculate bad children on-the-fly.
This commit is contained in:
parent
52b401d548
commit
52df376553
@ -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>(
|
||||
|
Loading…
x
Reference in New Issue
Block a user