diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 0c881a5..bc812d1 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -45,6 +45,7 @@ use crate::types::PlainList; use crate::types::PlainListItem; use crate::types::PlainText; use crate::types::Planning; +use crate::types::PriorityCookie; use crate::types::PropertyDrawer; use crate::types::RadioLink; use crate::types::RadioTarget; @@ -553,7 +554,57 @@ fn compare_heading<'s>( .collect::, _>>()?; child_status.push(artificial_diff_scope("title".to_owned(), title_status)?); - // TODO: Compare priority, :footnote-section-p, :archivedp, :commentedp + // Compare priority + let priority = get_property(emacs, ":priority")?; + match (priority, rust.priority_cookie) { + (None, None) => {} + (None, Some(_)) | (Some(_), None) => { + this_status = DiffStatus::Bad; + message = Some(format!( + "Priority cookie mismatch (emacs != rust) {:?} != {:?}", + priority, rust.priority_cookie + )); + } + (Some(emacs_priority_cookie), Some(rust_priority_cookie)) => { + let emacs_priority_cookie = + emacs_priority_cookie.as_atom()?.parse::()?; + if emacs_priority_cookie != rust_priority_cookie { + this_status = DiffStatus::Bad; + message = Some(format!( + "Priority cookie mismatch (emacs != rust) {:?} != {:?}", + emacs_priority_cookie, rust_priority_cookie + )); + } + } + } + + // Compare archived + let archived = get_property(emacs, ":archivedp")?; + match (archived, rust.is_archived) { + (None, true) | (Some(_), false) => { + this_status = DiffStatus::Bad; + message = Some(format!( + "archived mismatch (emacs != rust) {:?} != {:?}", + archived, rust.is_archived + )); + } + (None, false) | (Some(_), true) => {} + } + + // Compare commented + let commented = get_property(emacs, ":commentedp")?; + match (commented, rust.is_comment) { + (None, true) | (Some(_), false) => { + this_status = DiffStatus::Bad; + message = Some(format!( + "commented mismatch (emacs != rust) {:?} != {:?}", + commented, rust.is_comment + )); + } + (None, false) | (Some(_), true) => {} + } + + // TODO: Compare :footnote-section-p // Compare section let section_status = children diff --git a/src/compare/util.rs b/src/compare/util.rs index 6367bf9..173ecd0 100644 --- a/src/compare/util.rs +++ b/src/compare/util.rs @@ -141,6 +141,11 @@ fn maybe_token_to_usize( .map_or(Ok(None), |r| r.map(Some))?) } +/// Get a named property from the emacs token. +/// +/// Returns Ok(None) if value is nil. +/// +/// Returns error if the attribute is not specified on the token at all. pub fn get_property<'s, 'x>( emacs: &'s Token<'s>, key: &'x str,