From 7af5359e003959ebc1e62c3000472cd81855aa05 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 9 Oct 2023 22:45:32 -0400 Subject: [PATCH] compare_properties node property. --- src/compare/diff.rs | 48 +++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 00c09da..2857483 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -1625,36 +1625,38 @@ fn compare_property_drawer<'b, 's>( } fn compare_node_property<'b, 's>( - _source: &'s str, + source: &'s str, emacs: &'b Token<'s>, rust: &'b NodeProperty<'s>, ) -> Result, Box> { - let child_status = Vec::new(); let mut this_status = DiffStatus::Good; + let mut child_status = Vec::new(); let mut message = None; - // Compare key - let key = - get_property_quoted_string(emacs, ":key")?.ok_or("Node properties should have a key.")?; - if key != rust.property_name { - this_status = DiffStatus::Bad; - message = Some(format!( - "Key mismatch (emacs != rust) {:?} != {:?}", - key, rust.property_name - )); - } + assert_no_children(emacs, &mut this_status, &mut message)?; - // Compare value - let value = get_property_quoted_string(emacs, ":value")?; - match (value.as_ref(), rust.value) { - (None, None) => {} - (Some(emacs_value), Some(rust_value)) if emacs_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::Required(":key"), + |r| Some(r.property_name), + compare_property_quoted_string + ), + ( + EmacsField::Required(":value"), + |r| r.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), } }