diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 798a29c..c4b15c8 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -11,10 +11,9 @@ pub struct DiffResult { children: Vec, } -#[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> { + 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>(