From 42dcd41e4843a9b8f7026cfc0f1400e68cb2e21b Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Wed, 11 Oct 2023 16:02:44 -0400 Subject: [PATCH 1/3] Add tests for document properties. --- .../property_drawer/headline/comment.org | 5 ++++ .../headline/comment_space.org | 6 +++++ .../property_drawer/headline/immediate.org | 4 +++ .../property_drawer/headline/space.org | 5 ++++ .../headline/space_comment_space.org | 13 ++++++++++ .../property_drawer/inheritance.org | 19 ++++++++++++++ .../property_drawer/zeroth_section.org | 25 ------------------- .../zeroth_section/comment.org | 4 +++ .../zeroth_section/comment_space.org | 5 ++++ .../zeroth_section/immediate.org | 3 +++ .../property_drawer/zeroth_section/space.org | 4 +++ .../zeroth_section/space_comment_space.org | 12 +++++++++ .../zeroth_section_spaces_after_comment.org | 12 --------- 13 files changed, 80 insertions(+), 37 deletions(-) create mode 100644 org_mode_samples/greater_element/property_drawer/headline/comment.org create mode 100644 org_mode_samples/greater_element/property_drawer/headline/comment_space.org create mode 100644 org_mode_samples/greater_element/property_drawer/headline/immediate.org create mode 100644 org_mode_samples/greater_element/property_drawer/headline/space.org create mode 100644 org_mode_samples/greater_element/property_drawer/headline/space_comment_space.org create mode 100644 org_mode_samples/greater_element/property_drawer/inheritance.org delete mode 100644 org_mode_samples/greater_element/property_drawer/zeroth_section.org create mode 100644 org_mode_samples/greater_element/property_drawer/zeroth_section/comment.org create mode 100644 org_mode_samples/greater_element/property_drawer/zeroth_section/comment_space.org create mode 100644 org_mode_samples/greater_element/property_drawer/zeroth_section/immediate.org create mode 100644 org_mode_samples/greater_element/property_drawer/zeroth_section/space.org create mode 100644 org_mode_samples/greater_element/property_drawer/zeroth_section/space_comment_space.org delete mode 100644 org_mode_samples/greater_element/property_drawer/zeroth_section_spaces_after_comment.org diff --git a/org_mode_samples/greater_element/property_drawer/headline/comment.org b/org_mode_samples/greater_element/property_drawer/headline/comment.org new file mode 100644 index 0000000..f6b9691 --- /dev/null +++ b/org_mode_samples/greater_element/property_drawer/headline/comment.org @@ -0,0 +1,5 @@ +* baz +# lorem +:PROPERTIES: +:FOO: bar +:END: diff --git a/org_mode_samples/greater_element/property_drawer/headline/comment_space.org b/org_mode_samples/greater_element/property_drawer/headline/comment_space.org new file mode 100644 index 0000000..e36d8e3 --- /dev/null +++ b/org_mode_samples/greater_element/property_drawer/headline/comment_space.org @@ -0,0 +1,6 @@ +* baz +# lorem + +:PROPERTIES: +:FOO: bar +:END: diff --git a/org_mode_samples/greater_element/property_drawer/headline/immediate.org b/org_mode_samples/greater_element/property_drawer/headline/immediate.org new file mode 100644 index 0000000..64f4f03 --- /dev/null +++ b/org_mode_samples/greater_element/property_drawer/headline/immediate.org @@ -0,0 +1,4 @@ +* baz +:PROPERTIES: +:FOO: bar +:END: diff --git a/org_mode_samples/greater_element/property_drawer/headline/space.org b/org_mode_samples/greater_element/property_drawer/headline/space.org new file mode 100644 index 0000000..50f97bd --- /dev/null +++ b/org_mode_samples/greater_element/property_drawer/headline/space.org @@ -0,0 +1,5 @@ +* baz + +:PROPERTIES: +:FOO: bar +:END: diff --git a/org_mode_samples/greater_element/property_drawer/headline/space_comment_space.org b/org_mode_samples/greater_element/property_drawer/headline/space_comment_space.org new file mode 100644 index 0000000..8396730 --- /dev/null +++ b/org_mode_samples/greater_element/property_drawer/headline/space_comment_space.org @@ -0,0 +1,13 @@ +* baz + + + + +# lorem + + + + +:PROPERTIES: +:FOO: bar +:END: diff --git a/org_mode_samples/greater_element/property_drawer/inheritance.org b/org_mode_samples/greater_element/property_drawer/inheritance.org new file mode 100644 index 0000000..873c00d --- /dev/null +++ b/org_mode_samples/greater_element/property_drawer/inheritance.org @@ -0,0 +1,19 @@ +:PROPERTIES: +:foo: bar +:foo+: baz +:cat: dog +:END: + +# Even though these are inheriting the properties and overwriting and/or appending to them, this is not represented in the parser AST so Organic does not do any special handling of this. + +* Overwrite +:PROPERTIES: +:foo: lorem +:bat: car +:END: + +* Append +:PROPERTIES: +:foo+: ipsum +:cake: lie +:END: diff --git a/org_mode_samples/greater_element/property_drawer/zeroth_section.org b/org_mode_samples/greater_element/property_drawer/zeroth_section.org deleted file mode 100644 index 2538054..0000000 --- a/org_mode_samples/greater_element/property_drawer/zeroth_section.org +++ /dev/null @@ -1,25 +0,0 @@ - - - - -# Blank lines and comments can come before property drawers in the zeroth section -:PROPERTIES: -:FOO: bar -:END: - - - -* Spaces turn property drawers into regular drawers - -:PROPERTIES: -:FOO: bar -:END: -* Comments turn property drawers into regular drawers -# Comment -:PROPERTIES: -:FOO: bar -:END: -* Baseline -:PROPERTIES: -:FOO: bar -:END: diff --git a/org_mode_samples/greater_element/property_drawer/zeroth_section/comment.org b/org_mode_samples/greater_element/property_drawer/zeroth_section/comment.org new file mode 100644 index 0000000..6edce5b --- /dev/null +++ b/org_mode_samples/greater_element/property_drawer/zeroth_section/comment.org @@ -0,0 +1,4 @@ +# lorem +:PROPERTIES: +:FOO: bar +:END: diff --git a/org_mode_samples/greater_element/property_drawer/zeroth_section/comment_space.org b/org_mode_samples/greater_element/property_drawer/zeroth_section/comment_space.org new file mode 100644 index 0000000..cdc3436 --- /dev/null +++ b/org_mode_samples/greater_element/property_drawer/zeroth_section/comment_space.org @@ -0,0 +1,5 @@ +# lorem + +:PROPERTIES: +:FOO: bar +:END: diff --git a/org_mode_samples/greater_element/property_drawer/zeroth_section/immediate.org b/org_mode_samples/greater_element/property_drawer/zeroth_section/immediate.org new file mode 100644 index 0000000..bb43b87 --- /dev/null +++ b/org_mode_samples/greater_element/property_drawer/zeroth_section/immediate.org @@ -0,0 +1,3 @@ +:PROPERTIES: +:FOO: bar +:END: diff --git a/org_mode_samples/greater_element/property_drawer/zeroth_section/space.org b/org_mode_samples/greater_element/property_drawer/zeroth_section/space.org new file mode 100644 index 0000000..e03bfe0 --- /dev/null +++ b/org_mode_samples/greater_element/property_drawer/zeroth_section/space.org @@ -0,0 +1,4 @@ + +:PROPERTIES: +:FOO: bar +:END: diff --git a/org_mode_samples/greater_element/property_drawer/zeroth_section/space_comment_space.org b/org_mode_samples/greater_element/property_drawer/zeroth_section/space_comment_space.org new file mode 100644 index 0000000..e87aa0c --- /dev/null +++ b/org_mode_samples/greater_element/property_drawer/zeroth_section/space_comment_space.org @@ -0,0 +1,12 @@ + + + + +# lorem + + + + +:PROPERTIES: +:FOO: bar +:END: diff --git a/org_mode_samples/greater_element/property_drawer/zeroth_section_spaces_after_comment.org b/org_mode_samples/greater_element/property_drawer/zeroth_section_spaces_after_comment.org deleted file mode 100644 index e432ad0..0000000 --- a/org_mode_samples/greater_element/property_drawer/zeroth_section_spaces_after_comment.org +++ /dev/null @@ -1,12 +0,0 @@ - - - - -# Blank lines and comments can come before property drawers in the zeroth section - - - - -:PROPERTIES: -:FOO: bar -:END: From d965dd6fd1e9fb5e09a8152b56ba259c8e512a6d Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Wed, 11 Oct 2023 16:14:03 -0400 Subject: [PATCH 2/3] Implement get_additional_properties for Document. --- src/types/document.rs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/types/document.rs b/src/types/document.rs index 3437586..1102261 100644 --- a/src/types/document.rs +++ b/src/types/document.rs @@ -93,8 +93,7 @@ impl<'s> Heading<'s> { } pub fn get_additional_properties(&self) -> impl Iterator> { - let foo = self - .children + self.children .iter() .take(1) .filter_map(|c| match c { @@ -107,7 +106,28 @@ impl<'s> Heading<'s> { Element::PropertyDrawer(property_drawer) => Some(property_drawer), _ => None, }) - .flat_map(|property_drawer| property_drawer.children.iter()); - foo + .flat_map(|property_drawer| property_drawer.children.iter()) + } +} + +impl<'s> Document<'s> { + pub fn get_additional_properties(&self) -> impl Iterator> { + let zeroth_section_children = self + .zeroth_section + .iter() + .flat_map(|zeroth_section| zeroth_section.children.iter()); + let property_drawer = zeroth_section_children + .take_while(|element| match element { + Element::Comment(_) => true, + Element::PropertyDrawer(_) => true, + _ => false, + }) + .find_map(|element| match element { + Element::PropertyDrawer(property_drawer) => Some(property_drawer), + _ => None, + }); + property_drawer + .into_iter() + .flat_map(|property_drawer| property_drawer.children.iter()) } } From 3fcf1b3864928f835dc26601fb5b8bb4321d515e Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Wed, 11 Oct 2023 16:27:25 -0400 Subject: [PATCH 3/3] Compare Document additional properties. --- src/compare/diff.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 87a9bf3..7ad080e 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -455,6 +455,27 @@ fn _compare_document<'b, 's>( let mut child_status = Vec::new(); let mut message = None; + let additional_property_names: Vec = rust + .get_additional_properties() + .map(|node_property| format!(":{}", node_property.property_name.to_uppercase())) + .collect(); + + let additional_properties: Vec<(String, &str)> = rust + .get_additional_properties() + .map(|node_property| { + ( + format!(":{}", node_property.property_name.to_uppercase()), + node_property.value.unwrap_or(""), + ) + }) + .collect(); + + compare_additional_properties(emacs, additional_properties.into_iter())?.apply( + &mut child_status, + &mut this_status, + &mut message, + ); + compare_children_iter( source, emacs, @@ -468,6 +489,10 @@ fn _compare_document<'b, 's>( source, emacs, rust, + additional_property_names + .iter() + .map(String::as_str) + .map(EmacsField::Required), ( EmacsField::Required(":path"), |r| r.path.as_ref().map(|p| p.to_str()).flatten(),