compare_properties timestamp.

This commit is contained in:
Tom Alexander 2023-10-10 02:05:31 -04:00
parent 1a67aac502
commit bdaf90af03
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -26,9 +26,7 @@ use super::util::compare_children;
use super::util::compare_standard_properties; use super::util::compare_standard_properties;
use super::util::get_property; use super::util::get_property;
use super::util::get_property_boolean; use super::util::get_property_boolean;
use super::util::get_property_numeric;
use super::util::get_property_quoted_string; use super::util::get_property_quoted_string;
use super::util::get_property_unquoted_atom;
use crate::compare::compare_field::ComparePropertiesResult; use crate::compare::compare_field::ComparePropertiesResult;
use crate::compare::compare_field::EmacsField; use crate::compare::compare_field::EmacsField;
use crate::compare::macros::compare_properties; use crate::compare::macros::compare_properties;
@ -47,7 +45,6 @@ use crate::types::Comment;
use crate::types::CommentBlock; use crate::types::CommentBlock;
use crate::types::Date; use crate::types::Date;
use crate::types::DayOfMonth; use crate::types::DayOfMonth;
use crate::types::DayOfMonthInner;
use crate::types::DiarySexp; use crate::types::DiarySexp;
use crate::types::Document; use crate::types::Document;
use crate::types::DocumentElement; use crate::types::DocumentElement;
@ -65,7 +62,6 @@ use crate::types::GetStandardProperties;
use crate::types::Heading; use crate::types::Heading;
use crate::types::HorizontalRule; use crate::types::HorizontalRule;
use crate::types::Hour; use crate::types::Hour;
use crate::types::HourInner;
use crate::types::InlineBabelCall; use crate::types::InlineBabelCall;
use crate::types::InlineSourceBlock; use crate::types::InlineSourceBlock;
use crate::types::Italic; use crate::types::Italic;
@ -75,9 +71,7 @@ use crate::types::LatexFragment;
use crate::types::LineBreak; use crate::types::LineBreak;
use crate::types::LinkType; use crate::types::LinkType;
use crate::types::Minute; use crate::types::Minute;
use crate::types::MinuteInner;
use crate::types::Month; use crate::types::Month;
use crate::types::MonthInner;
use crate::types::NodeProperty; use crate::types::NodeProperty;
use crate::types::OrgMacro; use crate::types::OrgMacro;
use crate::types::Paragraph; use crate::types::Paragraph;
@ -94,7 +88,6 @@ use crate::types::RadioLink;
use crate::types::RadioTarget; use crate::types::RadioTarget;
use crate::types::RegularLink; use crate::types::RegularLink;
use crate::types::RepeaterType; use crate::types::RepeaterType;
use crate::types::RepeaterWarningDelayValueType;
use crate::types::Section; use crate::types::Section;
use crate::types::SpecialBlock; use crate::types::SpecialBlock;
use crate::types::SrcBlock; use crate::types::SrcBlock;
@ -119,7 +112,6 @@ use crate::types::Verbatim;
use crate::types::VerseBlock; use crate::types::VerseBlock;
use crate::types::WarningDelayType; use crate::types::WarningDelayType;
use crate::types::Year; use crate::types::Year;
use crate::types::YearInner;
#[derive(Debug)] #[derive(Debug)]
pub enum DiffEntry<'b, 's> { pub enum DiffEntry<'b, 's> {
@ -4000,279 +3992,180 @@ fn compare_superscript<'b, 's>(
} }
fn compare_timestamp<'b, 's>( fn compare_timestamp<'b, 's>(
_source: &'s str, source: &'s str,
emacs: &'b Token<'s>, emacs: &'b Token<'s>,
rust: &'b Timestamp<'s>, rust: &'b Timestamp<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error + 's>> { ) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error + 's>> {
let mut this_status = DiffStatus::Good; let mut this_status = DiffStatus::Good;
let mut child_status = Vec::new();
let mut message = None; let mut message = None;
// Compare type assert_no_children(emacs, &mut this_status, &mut message)?;
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
));
}
}
// Compare range-type for diff in compare_properties!(
let range_type = get_property_unquoted_atom(emacs, ":range-type")?; source,
match (range_type, &rust.range_type) { emacs,
(Some("daterange"), TimestampRangeType::DateRange) => {} rust,
(Some("timerange"), TimestampRangeType::TimeRange) => {} (
(None, TimestampRangeType::None) => {} EmacsField::Required(":type"),
_ => { |r| Some(match r.timestamp_type {
this_status = DiffStatus::Bad; TimestampType::Diary => "diary",
message = Some(format!( TimestampType::Active => "active",
"Range type mismatch (emacs != rust) {:?} != {:?}", TimestampType::Inactive => "inactive",
range_type, rust.range_type TimestampType::ActiveRange => "active-range",
)); TimestampType::InactiveRange => "inactive-range",
} }),
} compare_property_unquoted_atom
),
// Compare raw-value (
let raw_value = get_property_quoted_string(emacs, ":raw-value")? EmacsField::Required(":range-type"),
.ok_or("Timestamps should have a :raw-value.")?; |r| match r.range_type {
if raw_value != rust.get_raw_value() { TimestampRangeType::DateRange => Some("daterange"),
this_status = DiffStatus::Bad; TimestampRangeType::TimeRange => Some("timerange"),
message = Some(format!( TimestampRangeType::None => None,
"Raw value mismatch (emacs != rust) {:?} != {:?}", },
raw_value, compare_property_unquoted_atom
rust.get_raw_value() ),
)); (
} EmacsField::Required(":raw-value"),
|r| Some(r.get_raw_value()),
// Compare start compare_property_quoted_string
let year_start: Option<YearInner> = get_property_numeric(emacs, ":year-start")?; ),
let month_start: Option<MonthInner> = get_property_numeric(emacs, ":month-start")?; (
let day_of_month_start: Option<DayOfMonthInner> = get_property_numeric(emacs, ":day-start")?; EmacsField::Required(":year-start"),
let rust_year_start = rust.start.as_ref().map(Date::get_year).map(Year::get_value); |r| r.start.as_ref().map(Date::get_year).map(Year::get_value),
let rust_month_start = rust compare_property_numeric
.start ),
.as_ref() (
.map(Date::get_month) EmacsField::Required(":month-start"),
.map(Month::get_value); |r| r.start.as_ref().map(Date::get_month).map(Month::get_value),
let rust_day_of_month_start = rust compare_property_numeric
.start ),
.as_ref() (
.map(Date::get_day_of_month) EmacsField::Required(":day-start"),
.map(DayOfMonth::get_value); |r| r
if year_start != rust_year_start { .start
this_status = DiffStatus::Bad; .as_ref()
message = Some(format!( .map(Date::get_day_of_month)
"year start mismatch (emacs != rust) {:?} != {:?}", .map(DayOfMonth::get_value),
year_start, rust_year_start compare_property_numeric
)); ),
} (
if month_start != rust_month_start { EmacsField::Required(":year-end"),
this_status = DiffStatus::Bad; |r| r.end.as_ref().map(Date::get_year).map(Year::get_value),
message = Some(format!( compare_property_numeric
"month start mismatch (emacs != rust) {:?} != {:?}", ),
month_start, rust_month_start (
)); EmacsField::Required(":month-end"),
} |r| r.end.as_ref().map(Date::get_month).map(Month::get_value),
if day_of_month_start != rust_day_of_month_start { compare_property_numeric
this_status = DiffStatus::Bad; ),
message = Some(format!( (
"day of month start mismatch (emacs != rust) {:?} != {:?}", EmacsField::Required(":day-end"),
day_of_month_start, rust_day_of_month_start |r| r
)); .end
} .as_ref()
.map(Date::get_day_of_month)
// Compare end .map(DayOfMonth::get_value),
let year_end: Option<YearInner> = get_property_numeric(emacs, ":year-end")?; compare_property_numeric
let month_end: Option<MonthInner> = get_property_numeric(emacs, ":month-end")?; ),
let day_of_month_end: Option<DayOfMonthInner> = get_property_numeric(emacs, ":day-end")?; (
let rust_year_end = rust.end.as_ref().map(Date::get_year).map(Year::get_value); EmacsField::Required(":hour-start"),
let rust_month_end = rust.end.as_ref().map(Date::get_month).map(Month::get_value); |r| r
let rust_day_of_month_end = rust .start_time
.end .as_ref()
.as_ref() .map(Time::get_hour)
.map(Date::get_day_of_month) .map(Hour::get_value),
.map(DayOfMonth::get_value); compare_property_numeric
if year_end != rust_year_end { ),
this_status = DiffStatus::Bad; (
message = Some(format!( EmacsField::Required(":minute-start"),
"year end mismatch (emacs != rust) {:?} != {:?}", |r| r
year_end, rust_year_end .start_time
)); .as_ref()
} .map(Time::get_minute)
if month_end != rust_month_end { .map(Minute::get_value),
this_status = DiffStatus::Bad; compare_property_numeric
message = Some(format!( ),
"month end mismatch (emacs != rust) {:?} != {:?}", (
month_end, rust_month_end EmacsField::Required(":hour-end"),
)); |r| r.end_time.as_ref().map(Time::get_hour).map(Hour::get_value),
} compare_property_numeric
if day_of_month_end != rust_day_of_month_end { ),
this_status = DiffStatus::Bad; (
message = Some(format!( EmacsField::Required(":minute-end"),
"day of month end mismatch (emacs != rust) {:?} != {:?}", |r| r
day_of_month_end, rust_day_of_month_end .end_time
)); .as_ref()
} .map(Time::get_minute)
.map(Minute::get_value),
// Compare time start compare_property_numeric
let hour_start: Option<HourInner> = get_property_numeric(emacs, ":hour-start")?; ),
let minute_start: Option<MinuteInner> = get_property_numeric(emacs, ":minute-start")?; (
let rust_hour_start = rust EmacsField::Optional(":repeater-type"),
.start_time |r| match r.repeater.as_ref().map(|repeater| &repeater.repeater_type) {
.as_ref() Some(RepeaterType::Cumulative) => Some("cumulate"),
.map(Time::get_hour) Some(RepeaterType::CatchUp) => Some("catch-up"),
.map(Hour::get_value); Some(RepeaterType::Restart) => Some("restart"),
let rust_minute_start = rust None => None,
.start_time },
.as_ref() compare_property_unquoted_atom
.map(Time::get_minute) ),
.map(Minute::get_value); (
if hour_start != rust_hour_start { EmacsField::Optional(":repeater-unit"),
this_status = DiffStatus::Bad; |r| match r.repeater.as_ref().map(|repeater| &repeater.unit) {
message = Some(format!( Some(TimeUnit::Hour) => Some("hour"),
"hour start mismatch (emacs != rust) {:?} != {:?}", Some(TimeUnit::Day) => Some("day"),
hour_start, rust_hour_start Some(TimeUnit::Week) => Some("week"),
)); Some(TimeUnit::Month) => Some("month"),
} Some(TimeUnit::Year) => Some("year"),
if minute_start != rust_minute_start { None => None,
this_status = DiffStatus::Bad; },
message = Some(format!( compare_property_unquoted_atom
"minute start mismatch (emacs != rust) {:?} != {:?}", ),
minute_start, rust_minute_start (
)); EmacsField::Optional(":repeater-value"),
} |r| r.repeater.as_ref().map(|repeater| repeater.value),
compare_property_numeric
// Compare time end ),
let hour_end: Option<HourInner> = get_property_numeric(emacs, ":hour-end")?; (
let minute_end: Option<MinuteInner> = get_property_numeric(emacs, ":minute-end")?; EmacsField::Optional(":warning-type"),
let rust_hour_end = rust |r| match r
.end_time .warning_delay
.as_ref() .as_ref()
.map(Time::get_hour) .map(|repeater| &repeater.warning_delay_type)
.map(Hour::get_value); {
let rust_minute_end = rust Some(WarningDelayType::All) => Some("all"),
.end_time Some(WarningDelayType::First) => Some("first"),
.as_ref() None => None,
.map(Time::get_minute) },
.map(Minute::get_value); compare_property_unquoted_atom
if hour_end != rust_hour_end { ),
this_status = DiffStatus::Bad; (
message = Some(format!( EmacsField::Optional(":warning-unit"),
"hour end mismatch (emacs != rust) {:?} != {:?}", |r| match r.warning_delay.as_ref().map(|repeater| &repeater.unit) {
hour_end, rust_hour_end Some(TimeUnit::Hour) => Some("hour"),
)); Some(TimeUnit::Day) => Some("day"),
} Some(TimeUnit::Week) => Some("week"),
if minute_end != rust_minute_end { Some(TimeUnit::Month) => Some("month"),
this_status = DiffStatus::Bad; Some(TimeUnit::Year) => Some("year"),
message = Some(format!( None => None,
"minute end mismatch (emacs != rust) {:?} != {:?}", },
minute_end, rust_minute_end compare_property_unquoted_atom
)); ),
} (
EmacsField::Optional(":warning-value"),
// Compare repeater |r| r.warning_delay.as_ref().map(|repeater| repeater.value),
let repeater_type = get_property_unquoted_atom(emacs, ":repeater-type")?; compare_property_numeric
let repeater_value: Option<RepeaterWarningDelayValueType> = )
get_property_numeric(emacs, ":repeater-value")?; ) {
let repeater_unit = get_property_unquoted_atom(emacs, ":repeater-unit")?; match diff {
let rust_repeater_type = rust ComparePropertiesResult::NoChange => {}
.repeater ComparePropertiesResult::SelfChange(new_status, new_message) => {
.as_ref() this_status = new_status;
.map(|repeater| &repeater.repeater_type); message = new_message
let rust_repeater_value = rust.repeater.as_ref().map(|repeater| repeater.value); }
let rust_repeater_unit = rust.repeater.as_ref().map(|repeater| &repeater.unit); ComparePropertiesResult::DiffEntry(diff_entry) => child_status.push(diff_entry),
match (repeater_type, rust_repeater_type) {
(Some("cumulate"), Some(RepeaterType::Cumulative)) => {}
(Some("catch-up"), Some(RepeaterType::CatchUp)) => {}
(Some("restart"), Some(RepeaterType::Restart)) => {}
(None, None) => {}
_ => {
this_status = DiffStatus::Bad;
message = Some(format!(
"Repeater type mismatch (emacs != rust) {:?} != {:?}",
repeater_type, rust_repeater_type
));
}
}
if repeater_value != rust_repeater_value {
this_status = DiffStatus::Bad;
message = Some(format!(
"Repeater value mismatch (emacs != rust) {:?} != {:?}",
repeater_value, rust_repeater_value
));
}
match (repeater_unit, rust_repeater_unit) {
(Some("hour"), Some(TimeUnit::Hour)) => {}
(Some("day"), Some(TimeUnit::Day)) => {}
(Some("week"), Some(TimeUnit::Week)) => {}
(Some("month"), Some(TimeUnit::Month)) => {}
(Some("year"), Some(TimeUnit::Year)) => {}
(None, None) => {}
_ => {
this_status = DiffStatus::Bad;
message = Some(format!(
"Repeater unit mismatch (emacs != rust) {:?} != {:?}",
repeater_unit, rust_repeater_unit
));
}
}
// Compare warning_delay
let warning_delay_type = get_property_unquoted_atom(emacs, ":warning-type")?;
let warning_delay_value: Option<RepeaterWarningDelayValueType> =
get_property_numeric(emacs, ":warning-value")?;
let warning_delay_unit = get_property_unquoted_atom(emacs, ":warning-unit")?;
let rust_warning_delay_type = rust
.warning_delay
.as_ref()
.map(|warning_delay| &warning_delay.warning_delay_type);
let rust_warning_delay_value = rust
.warning_delay
.as_ref()
.map(|warning_delay| warning_delay.value);
let rust_warning_delay_unit = rust
.warning_delay
.as_ref()
.map(|warning_delay| &warning_delay.unit);
match (warning_delay_type, rust_warning_delay_type) {
(Some("all"), Some(WarningDelayType::All)) => {}
(Some("first"), Some(WarningDelayType::First)) => {}
(None, None) => {}
_ => {
this_status = DiffStatus::Bad;
message = Some(format!(
"Warning delay type mismatch (emacs != rust) {:?} != {:?}",
warning_delay_type, rust_warning_delay_type
));
}
}
if warning_delay_value != rust_warning_delay_value {
this_status = DiffStatus::Bad;
message = Some(format!(
"Warning delay value mismatch (emacs != rust) {:?} != {:?}",
warning_delay_value, rust_warning_delay_value
));
}
match (warning_delay_unit, rust_warning_delay_unit) {
(Some("hour"), Some(TimeUnit::Hour)) => {}
(Some("day"), Some(TimeUnit::Day)) => {}
(Some("week"), Some(TimeUnit::Week)) => {}
(Some("month"), Some(TimeUnit::Month)) => {}
(Some("year"), Some(TimeUnit::Year)) => {}
(None, None) => {}
_ => {
this_status = DiffStatus::Bad;
message = Some(format!(
"Warning delay unit mismatch (emacs != rust) {:?} != {:?}",
warning_delay_unit, rust_warning_delay_unit
));
} }
} }
@ -4280,7 +4173,7 @@ fn compare_timestamp<'b, 's>(
status: this_status, status: this_status,
name: rust.get_elisp_name(), name: rust.get_elisp_name(),
message, message,
children: Vec::new(), children: child_status,
rust_source: rust.get_source(), rust_source: rust.get_source(),
emacs_token: emacs, emacs_token: emacs,
} }