From 409a92333ec94211167a95e14ee24f0aeca39911 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 9 Oct 2023 21:42:07 -0400 Subject: [PATCH] compare_properties plain list. --- src/compare/diff.rs | 70 ++++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 30 deletions(-) diff --git a/src/compare/diff.rs b/src/compare/diff.rs index ff868fc..f37c596 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -1059,43 +1059,53 @@ fn compare_plain_list<'b, 's>( emacs: &'b Token<'s>, rust: &'b PlainList<'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 type - // :type is an unquoted atom of either descriptive, ordered, or unordered - let list_type = get_property_unquoted_atom(emacs, ":type")?; - match (list_type, &rust.list_type) { - (None, _) => panic!("Emacs returned a list with no type."), - (Some("unordered"), PlainListType::Unordered) => {} - (Some("ordered"), PlainListType::Ordered) => {} - (Some("descriptive"), PlainListType::Descriptive) => {} - _ => { - this_status = DiffStatus::Bad; - message = Some(format!( - "List type mismatch (emacs != rust) {:?} != {:?}", - list_type, rust.list_type - )); + 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(":type"), + |r| Some(match r.list_type { + PlainListType::Unordered => "unordered", + PlainListType::Ordered => "ordered", + PlainListType::Descriptive => "descriptive", + }), + 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), } } - 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())?); - } - Ok(DiffResult { status: this_status, name: rust.get_elisp_name(),