From 3d1b2713ed0f15b75f4cfd9c72ebfc2e4b4e7f91 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 2 Oct 2023 23:45:31 -0400 Subject: [PATCH] Compare key and value. --- src/compare/diff.rs | 29 ++++++++++++++++++++++++++--- src/parser/property_drawer.rs | 4 +++- src/types/greater_element.rs | 1 + 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/compare/diff.rs b/src/compare/diff.rs index adcf8cb0..dd444021 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -1301,10 +1301,33 @@ fn compare_node_property<'b, 's>( rust: &'b NodeProperty<'s>, ) -> Result, Box> { let child_status = Vec::new(); - let this_status = DiffStatus::Good; - let message = None; + let mut this_status = DiffStatus::Good; + let mut message = None; - // TODO: Compare :key :value + // Compare key + let key = + get_property_quoted_string(emacs, ":key")?.ok_or("Node properties should have a key.")?; + if key != rust.name { + this_status = DiffStatus::Bad; + message = Some(format!( + "Key mismatch (emacs != rust) {:?} != {:?}", + key, rust.name + )); + } + + // Compare value + let value = get_property_quoted_string(emacs, ":value")?; + match (value.as_ref(), rust.value) { + (None, None) => {} + (Some(emacs_value), Some(rust_value)) if emacs_value == rust_value => {} + _ => { + this_status = DiffStatus::Bad; + message = Some(format!( + "Value mismatch (emacs != rust) {:?} != {:?}", + value, rust.value + )); + } + } Ok(DiffResult { status: this_status, diff --git a/src/parser/property_drawer.rs b/src/parser/property_drawer.rs index 67d86f5e..06a4ac52 100644 --- a/src/parser/property_drawer.rs +++ b/src/parser/property_drawer.rs @@ -101,7 +101,7 @@ fn node_property<'b, 'g, 'r, 's>( context: RefContext<'b, 'g, 'r, 's>, input: OrgSource<'s>, ) -> Res, NodeProperty<'s>> { - let (remaining, (_start_of_line, _leading_whitespace, _open_colon, _name, _close_colon)) = + let (remaining, (_start_of_line, _leading_whitespace, _open_colon, name, _close_colon)) = tuple(( start_of_line, space0, @@ -120,6 +120,7 @@ fn node_property<'b, 'g, 'r, 's>( remaining, NodeProperty { source: source.into(), + name: Into::<&str>::into(name), value: None, }, )) @@ -132,6 +133,7 @@ fn node_property<'b, 'g, 'r, 's>( remaining, NodeProperty { source: source.into(), + name: Into::<&str>::into(name), value: Some(value.into()), }, )) diff --git a/src/types/greater_element.rs b/src/types/greater_element.rs index ec1f2818..bbf88f70 100644 --- a/src/types/greater_element.rs +++ b/src/types/greater_element.rs @@ -94,6 +94,7 @@ pub struct PropertyDrawer<'s> { #[derive(Debug)] pub struct NodeProperty<'s> { pub source: &'s str, + pub name: &'s str, pub value: Option<&'s str>, }