From d1dac0b8de96cfb22ed865dad16cd8a8e4011669 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 29 Sep 2023 20:23:02 -0400 Subject: [PATCH] Compare document category. --- org_mode_samples/document/category.org | 1 + src/compare/diff.rs | 23 ++++++++++++++++++++++- src/parser/document.rs | 1 + src/types/document.rs | 3 +++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 org_mode_samples/document/category.org diff --git a/org_mode_samples/document/category.org b/org_mode_samples/document/category.org new file mode 100644 index 0000000..8dfa447 --- /dev/null +++ b/org_mode_samples/document/category.org @@ -0,0 +1 @@ +#+CATEGORY: theory diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 96757e9..ef37959 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -438,7 +438,28 @@ pub fn compare_document<'s>( Ok(_) => {} } - // TODO: Compare :path :CATEGORY + // TODO: Compare :path + + // Compare category + let category = get_property_quoted_string(emacs, ":CATEGORY")?; + match (category.as_ref(), rust.category) { + (None, None) => {} + (None, Some(_)) | (Some(_), None) => { + this_status = DiffStatus::Bad; + message = Some(format!( + "Category mismatch (emacs != rust) {:?} != {:?}", + category, rust.category + )); + } + (Some(e), Some(r)) if e != r => { + this_status = DiffStatus::Bad; + message = Some(format!( + "Category mismatch (emacs != rust) {:?} != {:?}", + category, rust.category + )); + } + (Some(_), Some(_)) => {} + }; // Skipping "org-data" and its properties for (i, token) in children.iter().skip(2).enumerate() { diff --git a/src/parser/document.rs b/src/parser/document.rs index 4d6a64b..53eb4e2 100644 --- a/src/parser/document.rs +++ b/src/parser/document.rs @@ -148,6 +148,7 @@ fn _document<'b, 'g, 'r, 's>( remaining, Document { source: source.into(), + category: None, zeroth_section, children, }, diff --git a/src/types/document.rs b/src/types/document.rs index 974d77b..bb0c99c 100644 --- a/src/types/document.rs +++ b/src/types/document.rs @@ -1,4 +1,5 @@ use super::macros::ref_getter; +use super::macros::simple_getter; use super::Element; use super::GetStandardProperties; use super::Object; @@ -10,6 +11,7 @@ pub type HeadlineLevel = u16; #[derive(Debug)] pub struct Document<'s> { pub(crate) source: &'s str, + pub(crate) category: Option<&'s str>, pub(crate) zeroth_section: Option>, pub(crate) children: Vec>, } @@ -73,6 +75,7 @@ impl<'s> StandardProperties<'s> for Heading<'s> { } impl<'s> Document<'s> { + simple_getter!(get_category, category, Option<&'s str>); ref_getter!(get_zeroth_section, zeroth_section, Option>); ref_getter!(get_children, children, Vec>); }