From 672848d06aa83728fe607bdb94eb55936307ab2b Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 6 Oct 2023 12:12:24 -0400 Subject: [PATCH] Compare the properties of text markup. --- src/compare/diff.rs | 60 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 10 deletions(-) diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 66de6b3..d4af397 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -2567,13 +2567,19 @@ fn compare_plain_text<'b, 's>( } fn compare_bold<'b, 's>( - _source: &'s str, + source: &'s str, emacs: &'b Token<'s>, rust: &'b Bold<'s>, ) -> Result, Box> { + let children = emacs.as_list()?; let this_status = DiffStatus::Good; + let mut child_status = Vec::new(); let message = None; + 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(), @@ -2586,13 +2592,19 @@ fn compare_bold<'b, 's>( } fn compare_italic<'b, 's>( - _source: &'s str, + source: &'s str, emacs: &'b Token<'s>, rust: &'b Italic<'s>, ) -> Result, Box> { + let children = emacs.as_list()?; let this_status = DiffStatus::Good; + let mut child_status = Vec::new(); let message = None; + 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(), @@ -2605,13 +2617,19 @@ fn compare_italic<'b, 's>( } fn compare_underline<'b, 's>( - _source: &'s str, + source: &'s str, emacs: &'b Token<'s>, rust: &'b Underline<'s>, ) -> Result, Box> { + let children = emacs.as_list()?; let this_status = DiffStatus::Good; + let mut child_status = Vec::new(); let message = None; + 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(), @@ -2628,10 +2646,18 @@ fn compare_verbatim<'b, 's>( emacs: &'b Token<'s>, rust: &'b Verbatim<'s>, ) -> Result, Box> { - let this_status = DiffStatus::Good; - let message = None; + let mut this_status = DiffStatus::Good; + let mut message = None; - // TODO: Compare :value + // Compare value + let value = get_property_quoted_string(emacs, ":value")?; + if value.as_ref().map(String::as_str) != Some(rust.contents) { + this_status = DiffStatus::Bad; + message = Some(format!( + "Value mismatch (emacs != rust) {:?} != {:?}", + value, rust.contents + )); + } Ok(DiffResult { status: this_status, @@ -2649,10 +2675,18 @@ fn compare_code<'b, 's>( emacs: &'b Token<'s>, rust: &'b Code<'s>, ) -> Result, Box> { - let this_status = DiffStatus::Good; - let message = None; + let mut this_status = DiffStatus::Good; + let mut message = None; - // TODO: Compare :value + // Compare value + let value = get_property_quoted_string(emacs, ":value")?; + if value.as_ref().map(String::as_str) != Some(rust.contents) { + this_status = DiffStatus::Bad; + message = Some(format!( + "Value mismatch (emacs != rust) {:?} != {:?}", + value, rust.contents + )); + } Ok(DiffResult { status: this_status, @@ -2666,13 +2700,19 @@ fn compare_code<'b, 's>( } fn compare_strike_through<'b, 's>( - _source: &'s str, + source: &'s str, emacs: &'b Token<'s>, rust: &'b StrikeThrough<'s>, ) -> Result, Box> { + let children = emacs.as_list()?; let this_status = DiffStatus::Good; + let mut child_status = Vec::new(); let message = None; + 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(),