From 384242af876172c54e09abca724515a99a35a1cf Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Tue, 10 Oct 2023 01:19:14 -0400 Subject: [PATCH] compare_properties clock. --- src/compare/diff.rs | 71 +++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 9550869..bb65c33 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -2173,51 +2173,46 @@ fn compare_src_block<'b, 's>( } fn compare_clock<'b, 's>( - _source: &'s str, + source: &'s str, emacs: &'b Token<'s>, rust: &'b Clock<'s>, ) -> Result, Box> { - let mut child_status = Vec::new(); let mut this_status = DiffStatus::Good; + let mut child_status = Vec::new(); let mut message = None; - // Compare value - let value = get_property(emacs, ":value")?; - match value { - Some(e) => { - let result = compare_ast_node(_source, e, (&rust.timestamp).into())?; - child_status.push(artificial_diff_scope("value", vec![result])?); - } - None => { - this_status = DiffStatus::Bad; - message = Some(format!( - "Value mismatch (emacs != rust) {:?} != {:?}", - value, rust.timestamp - )); - } - } + assert_no_children(emacs, &mut this_status, &mut message)?; - // Compare duration - let duration = get_property_quoted_string(emacs, ":duration")?; - if duration.as_ref().map(String::as_str) != rust.duration { - this_status = DiffStatus::Bad; - message = Some(format!( - "Duration mismatch (emacs != rust) {:?} != {:?}", - duration, rust.duration - )); - } - - // Compare status - let status = get_property_unquoted_atom(emacs, ":status")?; - match (status, &rust.status) { - (Some("running"), ClockStatus::Running) => {} - (Some("closed"), ClockStatus::Closed) => {} - _ => { - this_status = DiffStatus::Bad; - message = Some(format!( - "Status mismatch (emacs != rust) {:?} != {:?}", - status, rust.status - )); + for diff in compare_properties!( + source, + emacs, + rust, + ( + EmacsField::Required(":value"), + |r| Some(&r.timestamp), + compare_property_single_ast_node + ), + ( + EmacsField::Required(":duration"), + |r| r.duration, + compare_property_quoted_string + ), + ( + EmacsField::Required(":status"), + |r| Some(match r.status { + ClockStatus::Running => "running", + ClockStatus::Closed => "closed", + }), + compare_property_unquoted_atom + ) + ) { + 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), } }