From f820e27b17e346ca83f9b16493e4a7c5ede0c611 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 29 Sep 2023 13:03:01 -0400 Subject: [PATCH] Compare plain list type in diff.rs. --- src/compare/diff.rs | 23 +++++++++++++++++++---- src/compare/util.rs | 12 ++++++++++++ src/parser/plain_list.rs | 2 +- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/compare/diff.rs b/src/compare/diff.rs index da654d6..0bfd6ba 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -9,6 +9,7 @@ use super::sexp::unquote; use super::sexp::Token; use super::util::compare_standard_properties; use super::util::get_property; +use super::util::get_property_unquoted_atom; use crate::types::AngleLink; use crate::types::BabelCall; use crate::types::Bold; @@ -50,6 +51,7 @@ use crate::types::Paragraph; use crate::types::PlainLink; use crate::types::PlainList; use crate::types::PlainListItem; +use crate::types::PlainListType; use crate::types::PlainText; use crate::types::Planning; use crate::types::PriorityCookie; @@ -748,11 +750,24 @@ fn compare_plain_list<'s>( ) -> Result, Box> { let children = emacs.as_list()?; let mut child_status = Vec::new(); - let this_status = DiffStatus::Good; - let message = None; - // TODO: Compare :type - // + let mut this_status = DiffStatus::Good; + let mut message = None; + // :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 (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) { child_status.push(compare_plain_list_item(source, emacs_child, rust_child)?); diff --git a/src/compare/util.rs b/src/compare/util.rs index 21580a9..f52ef47 100644 --- a/src/compare/util.rs +++ b/src/compare/util.rs @@ -190,3 +190,15 @@ pub(crate) fn get_property<'s, 'x>( }; Ok(Some(*prop)) } + +/// Get a named property containing an unquoted atom from the emacs token. +/// +/// Returns None if key is not found. +pub(crate) fn get_property_unquoted_atom<'s, 'x>( + emacs: &'s Token<'s>, + key: &'x str, +) -> Result, Box> { + Ok(get_property(emacs, key)? + .map(Token::as_atom) + .map_or(Ok(None), |r| r.map(Some))?) +} diff --git a/src/parser/plain_list.rs b/src/parser/plain_list.rs index b12451c..f2e4313 100644 --- a/src/parser/plain_list.rs +++ b/src/parser/plain_list.rs @@ -148,7 +148,7 @@ pub(crate) fn plain_list<'b, 'g, 'r, 's>( remaining, PlainList { source: source.into(), - list_type: PlainListType::Ordered, + list_type: first_item_list_type.expect("Plain lists require at least one element."), children: children.into_iter().map(|(_start, item)| item).collect(), }, ))