From 1df6777b0bf4d38859a5d6525469f7d4e4cccebc Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 8 Oct 2023 17:24:03 -0400 Subject: [PATCH] Starting to compare entity properties. --- src/compare/diff.rs | 53 +++++++++++++++++++++++++++++++++++++++++--- src/parser/entity.rs | 2 +- src/types/object.rs | 2 +- 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 5afb6e0..c7ad99d 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -5,6 +5,7 @@ use std::collections::BTreeSet; use std::collections::HashSet; use super::compare_field::compare_identity; +use super::compare_field::compare_noop; use super::compare_field::compare_property_always_nil; use super::compare_field::compare_property_list_of_quoted_string; use super::compare_field::compare_property_quoted_string; @@ -3115,10 +3116,56 @@ fn compare_entity<'b, 's>( emacs: &'b Token<'s>, rust: &'b Entity<'s>, ) -> Result, Box> { - let this_status = DiffStatus::Good; - let message = None; + let mut this_status = DiffStatus::Good; + let mut message = None; - // TODO: Compare :name :latex :latex-math-p :html :ascii :latin1 :utf-8 :use-brackets-p + if let Some((new_status, new_message)) = compare_properties!( + emacs, + rust, + ( + EmacsField::Required(":name"), + |r| Some(r.name), + compare_property_quoted_string + ), + ( + EmacsField::Required(":latex"), + compare_identity, + compare_noop + ), + ( + EmacsField::Required(":latex-math-p"), + compare_identity, + compare_noop + ), + ( + EmacsField::Required(":html"), + compare_identity, + compare_noop + ), + ( + EmacsField::Required(":ascii"), + compare_identity, + compare_noop + ), + ( + EmacsField::Required(":latin1"), + compare_identity, + compare_noop + ), + ( + EmacsField::Required(":utf-8"), + compare_identity, + compare_noop + ), + ( + EmacsField::Required(":use-brackets-p"), + compare_identity, + compare_noop + ) + )? { + this_status = new_status; + message = new_message; + } Ok(DiffResult { status: this_status, diff --git a/src/parser/entity.rs b/src/parser/entity.rs index 53a0b09..8ada3f9 100644 --- a/src/parser/entity.rs +++ b/src/parser/entity.rs @@ -448,7 +448,7 @@ pub(crate) fn entity<'b, 'g, 'r, 's>( remaining, Entity { source: source.into(), - entity_name: entity_name.into(), + name: entity_name.into(), }, )) } diff --git a/src/types/object.rs b/src/types/object.rs index 2242043..f769b06 100644 --- a/src/types/object.rs +++ b/src/types/object.rs @@ -167,7 +167,7 @@ pub struct OrgMacro<'s> { #[derive(Debug, PartialEq)] pub struct Entity<'s> { pub source: &'s str, - pub entity_name: &'s str, + pub name: &'s str, } #[derive(Debug, PartialEq)]