diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 762b435..9ac4c7a 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -2332,35 +2332,44 @@ fn compare_planning<'b, 's>( } fn compare_fixed_width_area<'b, 's>( - _source: &'s str, + source: &'s str, emacs: &'b Token<'s>, rust: &'b FixedWidthArea<'s>, ) -> Result, Box> { - let child_status = Vec::new(); let mut this_status = DiffStatus::Good; + let mut child_status = Vec::new(); let mut message = None; - // TODO: Compare :caption - // Compare name - let name = get_property_quoted_string(emacs, ":name")?; - if name.as_ref().map(String::as_str) != rust.name { - this_status = DiffStatus::Bad; - message = Some(format!( - "Name mismatch (emacs != rust) {:?} != {:?}", - name, rust.name - )); - } + assert_no_children(emacs, &mut this_status, &mut message)?; - // Compare value - let value = get_property_quoted_string(emacs, ":value")? - .ok_or("Fixed width area should have a value.")?; - let rust_value = rust.get_value(); - if value != rust_value { - this_status = DiffStatus::Bad; - message = Some(format!( - "Value mismatch (emacs != rust) {:?} != {:?}", - value, rust_value - )); + for diff in compare_properties!( + source, + emacs, + rust, + ( + EmacsField::Optional(":name"), + |r| r.name, + compare_property_quoted_string + ), + ( + EmacsField::Optional(":caption"), + compare_identity, + compare_noop + ), + ( + EmacsField::Required(":value"), + |r| Some(r.get_value()), + compare_property_quoted_string + ) + ) { + match diff { + ComparePropertiesResult::NoChange => {} + ComparePropertiesResult::SelfChange(new_status, new_message) => { + this_status = new_status; + message = new_message + } + ComparePropertiesResult::DiffEntry(diff_entry) => child_status.push(diff_entry), + } } Ok(DiffResult {