From 5b146d7c074de0305177f349f435e4593f2664b3 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 9 Oct 2023 22:37:53 -0400 Subject: [PATCH] compare_properties drawer. --- src/compare/diff.rs | 62 +++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 859189a5..8bacae30 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -1530,35 +1530,47 @@ fn compare_drawer<'b, 's>( emacs: &'b Token<'s>, rust: &'b Drawer<'s>, ) -> Result, Box> { - let children = emacs.as_list()?; - let mut 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 - )); - } + compare_children( + source, + emacs, + &rust.children, + &mut child_status, + &mut this_status, + &mut message, + )?; - // Compare drawer-name - let drawer_name = - get_property_quoted_string(emacs, ":drawer-name")?.ok_or("Drawers should have a name.")?; - if drawer_name != rust.drawer_name { - this_status = DiffStatus::Bad; - message = Some(format!( - "Drawer name mismatch (emacs != rust) {:?} != {:?}", - drawer_name, rust.drawer_name - )); - } - - for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) { - child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?); + 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(":drawer-name"), + |r| Some(r.drawer_name), + 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 {