From cf257443b08e329ef303ce0f1b4fc7e334b8bfe0 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Tue, 10 Oct 2023 00:07:34 -0400 Subject: [PATCH] compare_properties table row. --- src/compare/diff.rs | 48 ++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 3159bcf..5b654ab 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -1750,28 +1750,40 @@ fn compare_table_row<'b, 's>( emacs: &'b Token<'s>, rust: &'b TableRow<'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; - // Compare type - let row_type = get_property_unquoted_atom(emacs, ":type")?; - let rust_row_type = rust.get_type(); - match (row_type, &rust_row_type) { - (Some("standard"), TableRowType::Standard) => {} - (Some("rule"), TableRowType::Rule) => {} - _ => { - this_status = DiffStatus::Bad; - message = Some(format!( - "Type mismatch (emacs != rust) {:?} != {:?}", - row_type, rust_row_type - )); - } - } + compare_children( + source, + emacs, + &rust.children, + &mut child_status, + &mut this_status, + &mut message, + )?; - 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::Required(":type"), + |r| Some(match r.get_type() { + TableRowType::Standard => "standard", + TableRowType::Rule => "rule", + }), + 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), + } } Ok(DiffResult {