From d04c8c832ccb79d45a8be6b6cb9e0fd333784141 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 2 Oct 2023 13:33:00 -0400 Subject: [PATCH] Compare timestamp type. --- src/compare/diff.rs | 24 +++++++++++++++++++++--- src/parser/timestamp.rs | 9 +++++++++ src/types/mod.rs | 1 + src/types/object.rs | 11 +++++++++++ 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/compare/diff.rs b/src/compare/diff.rs index 654a1ed..511cda2 100644 --- a/src/compare/diff.rs +++ b/src/compare/diff.rs @@ -12,8 +12,8 @@ use super::util::get_property; use super::util::get_property_boolean; use super::util::get_property_quoted_string; use super::util::get_property_unquoted_atom; -use crate::types::AstNode; use crate::types::AngleLink; +use crate::types::AstNode; use crate::types::BabelCall; use crate::types::Bold; use crate::types::CheckboxType; @@ -74,6 +74,7 @@ use crate::types::TableCell; use crate::types::TableRow; use crate::types::Target; use crate::types::Timestamp; +use crate::types::TimestampType; use crate::types::TodoKeywordType; use crate::types::Underline; use crate::types::Verbatim; @@ -2116,8 +2117,25 @@ fn compare_timestamp<'b, 's>( emacs: &'b Token<'s>, rust: &'b Timestamp<'s>, ) -> Result, Box> { - let this_status = DiffStatus::Good; - let message = None; + let mut this_status = DiffStatus::Good; + let mut message = None; + + // Compare type + let timestamp_type = get_property_unquoted_atom(emacs, ":type")?; + match (timestamp_type, &rust.timestamp_type) { + (Some("diary"), TimestampType::Diary) => {} + (Some("active"), TimestampType::Active) => {} + (Some("inactive"), TimestampType::Inactive) => {} + (Some("active-range"), TimestampType::ActiveRange) => {} + (Some("inactive-range"), TimestampType::InactiveRange) => {} + _ => { + this_status = DiffStatus::Bad; + message = Some(format!( + "Timestamp type mismatch (emacs != rust) {:?} != {:?}", + timestamp_type, rust.timestamp_type + )); + } + } // TODO: Compare :type :range-type :raw-value :year-start :month-start :day-start :hour-start :minute-start :year-end :month-end :day-end :hour-end :minute-end :repeater-type :repeater-value :repeater-unit :warning-type :warning-value :warning-unit // diff --git a/src/parser/timestamp.rs b/src/parser/timestamp.rs index 1d4e50c..a23f9c5 100644 --- a/src/parser/timestamp.rs +++ b/src/parser/timestamp.rs @@ -22,6 +22,7 @@ use crate::context::RefContext; use crate::error::Res; use crate::parser::util::get_consumed; use crate::types::Timestamp; +use crate::types::TimestampType; #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] pub(crate) fn timestamp<'b, 'g, 'r, 's>( @@ -57,6 +58,7 @@ fn diary_timestamp<'b, 'g, 'r, 's>( remaining, Timestamp { source: source.into(), + timestamp_type: TimestampType::Diary, }, )) } @@ -121,6 +123,7 @@ fn active_timestamp<'b, 'g, 'r, 's>( remaining, Timestamp { source: source.into(), + timestamp_type: TimestampType::Active, }, )) } @@ -155,6 +158,7 @@ fn inactive_timestamp<'b, 'g, 'r, 's>( remaining, Timestamp { source: source.into(), + timestamp_type: TimestampType::Inactive, }, )) } @@ -177,6 +181,7 @@ fn active_date_range_timestamp<'b, 'g, 'r, 's>( remaining, Timestamp { source: source.into(), + timestamp_type: TimestampType::ActiveRange, }, )) } @@ -218,6 +223,7 @@ fn active_time_range_timestamp<'b, 'g, 'r, 's>( remaining, Timestamp { source: source.into(), + timestamp_type: TimestampType::Active, }, )) } @@ -240,6 +246,8 @@ fn inactive_date_range_timestamp<'b, 'g, 'r, 's>( remaining, Timestamp { source: source.into(), + + timestamp_type: TimestampType::InactiveRange, }, )) } @@ -281,6 +289,7 @@ fn inactive_time_range_timestamp<'b, 'g, 'r, 's>( remaining, Timestamp { source: source.into(), + timestamp_type: TimestampType::Inactive, }, )) } diff --git a/src/types/mod.rs b/src/types/mod.rs index 6f41156..d635cd5 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -75,6 +75,7 @@ pub use object::Subscript; pub use object::Superscript; pub use object::Target; pub use object::Timestamp; +pub use object::TimestampType; pub use object::Underline; pub use object::Verbatim; pub(crate) use source::SetSource; diff --git a/src/types/object.rs b/src/types/object.rs index 2d8e06e..90f095d 100644 --- a/src/types/object.rs +++ b/src/types/object.rs @@ -1,6 +1,7 @@ use super::GetStandardProperties; use super::StandardProperties; +// TODO: Why did we make Object implement PartialEq again? Was it just for tests? #[derive(Debug, PartialEq)] pub enum Object<'s> { Bold(Bold<'s>), @@ -184,6 +185,16 @@ pub struct Superscript<'s> { #[derive(Debug, PartialEq)] pub struct Timestamp<'s> { pub source: &'s str, + pub timestamp_type: TimestampType, +} + +#[derive(Debug, PartialEq)] +pub enum TimestampType { + Diary, + Active, + Inactive, + ActiveRange, + InactiveRange, } impl<'s> GetStandardProperties<'s> for Object<'s> {