compare_properties clock.

This commit is contained in:
Tom Alexander 2023-10-10 01:19:14 -04:00
parent ec755bae8b
commit 384242af87
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -2173,51 +2173,46 @@ fn compare_src_block<'b, 's>(
}
fn compare_clock<'b, 's>(
_source: &'s str,
source: &'s str,
emacs: &'b Token<'s>,
rust: &'b Clock<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let mut child_status = Vec::new();
let mut this_status = DiffStatus::Good;
let mut child_status = Vec::new();
let mut message = None;
// Compare value
let value = get_property(emacs, ":value")?;
match value {
Some(e) => {
let result = compare_ast_node(_source, e, (&rust.timestamp).into())?;
child_status.push(artificial_diff_scope("value", vec![result])?);
}
None => {
this_status = DiffStatus::Bad;
message = Some(format!(
"Value mismatch (emacs != rust) {:?} != {:?}",
value, rust.timestamp
));
}
}
assert_no_children(emacs, &mut this_status, &mut message)?;
// Compare duration
let duration = get_property_quoted_string(emacs, ":duration")?;
if duration.as_ref().map(String::as_str) != rust.duration {
this_status = DiffStatus::Bad;
message = Some(format!(
"Duration mismatch (emacs != rust) {:?} != {:?}",
duration, rust.duration
));
for diff in compare_properties!(
source,
emacs,
rust,
(
EmacsField::Required(":value"),
|r| Some(&r.timestamp),
compare_property_single_ast_node
),
(
EmacsField::Required(":duration"),
|r| r.duration,
compare_property_quoted_string
),
(
EmacsField::Required(":status"),
|r| Some(match r.status {
ClockStatus::Running => "running",
ClockStatus::Closed => "closed",
}),
compare_property_unquoted_atom
)
) {
match diff {
ComparePropertiesResult::NoChange => {}
ComparePropertiesResult::SelfChange(new_status, new_message) => {
this_status = new_status;
message = new_message
}
// Compare status
let status = get_property_unquoted_atom(emacs, ":status")?;
match (status, &rust.status) {
(Some("running"), ClockStatus::Running) => {}
(Some("closed"), ClockStatus::Closed) => {}
_ => {
this_status = DiffStatus::Bad;
message = Some(format!(
"Status mismatch (emacs != rust) {:?} != {:?}",
status, rust.status
));
ComparePropertiesResult::DiffEntry(diff_entry) => child_status.push(diff_entry),
}
}