From 0fcfdd5ff22a21b148354c4ffc04c6576424b950 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 21 Apr 2023 15:45:35 -0400 Subject: [PATCH] Compare table row and table cell bounds. --- src/compare/diff.rs | 62 +++++++++++++++++++++++++++++++++++++++++++ src/parser/element.rs | 14 ++++++++++ src/parser/mod.rs | 2 ++ 3 files changed, 78 insertions(+) diff --git a/src/compare/diff.rs b/src/compare/diff.rs index b0b6210..11975d2 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -15,6 +15,8 @@ use crate::parser::PlainListItem; use crate::parser::PropertyDrawer; use crate::parser::Section; use crate::parser::Table; +use crate::parser::TableCell; +use crate::parser::TableRow; use crate::DynamicBlock; #[derive(Debug)] @@ -479,6 +481,66 @@ fn compare_table<'s>( this_status = DiffStatus::Bad; } + for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) { + child_status.push(compare_table_row(source, emacs_child, rust_child)?); + } + + Ok(DiffResult { + status: this_status, + name: emacs_name.to_owned(), + message: None, + children: child_status, + }) +} + +fn compare_table_row<'s>( + source: &'s str, + emacs: &'s Token<'s>, + rust: &'s TableRow<'s>, +) -> Result> { + let children = emacs.as_list()?; + let mut child_status = Vec::new(); + let mut this_status = DiffStatus::Good; + let emacs_name = "table-row"; + if assert_name(emacs, emacs_name).is_err() { + this_status = DiffStatus::Bad; + } + + if assert_bounds(source, emacs, rust).is_err() { + this_status = DiffStatus::Bad; + } + + for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) { + child_status.push(compare_table_cell(source, emacs_child, rust_child)?); + } + + Ok(DiffResult { + status: this_status, + name: emacs_name.to_owned(), + message: None, + children: child_status, + }) +} + +fn compare_table_cell<'s>( + source: &'s str, + emacs: &'s Token<'s>, + rust: &'s TableCell<'s>, +) -> Result> { + let children = emacs.as_list()?; + let mut child_status = Vec::new(); + let mut this_status = DiffStatus::Good; + let emacs_name = "table-cell"; + if assert_name(emacs, emacs_name).is_err() { + this_status = DiffStatus::Bad; + } + + if assert_bounds(source, emacs, rust).is_err() { + this_status = DiffStatus::Bad; + } + + for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) {} + Ok(DiffResult { status: this_status, name: emacs_name.to_owned(), diff --git a/src/parser/element.rs b/src/parser/element.rs index 9f9f97f..abfaf4b 100644 --- a/src/parser/element.rs +++ b/src/parser/element.rs @@ -10,8 +10,10 @@ use super::greater_element::GreaterBlock; use super::greater_element::PlainList; use super::greater_element::PropertyDrawer; use super::greater_element::Table; +use super::greater_element::TableRow; use super::lesser_element::Comment; use super::lesser_element::Paragraph; +use super::lesser_element::TableCell; use super::paragraph::paragraph; use super::plain_list::plain_list; use super::source::Source; @@ -113,6 +115,18 @@ impl<'s> Source<'s> for Table<'s> { } } +impl<'s> Source<'s> for TableRow<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + +impl<'s> Source<'s> for TableCell<'s> { + fn get_source(&'s self) -> &'s str { + self.source + } +} + #[tracing::instrument(ret, level = "debug")] pub fn element<'r, 's>(context: Context<'r, 's>, input: &'s str) -> Res<&'s str, Element<'s>> { let non_paragraph_matcher = parser_with_context!(non_paragraph_element)(context); diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 74ddbe1..33eb7de 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -34,7 +34,9 @@ pub use greater_element::PlainList; pub use greater_element::PlainListItem; pub use greater_element::PropertyDrawer; pub use greater_element::Table; +pub use greater_element::TableRow; pub use lesser_element::Comment; pub use lesser_element::Paragraph; +pub use lesser_element::TableCell; pub use source::Source; type Context<'r, 's> = &'r parser_context::ContextTree<'r, 's>;