compare_properties node property.

This commit is contained in:
Tom Alexander 2023-10-09 22:45:32 -04:00
parent d1184fa1d0
commit 7af5359e00
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
1 changed files with 25 additions and 23 deletions

View File

@ -1625,36 +1625,38 @@ fn compare_property_drawer<'b, 's>(
}
fn compare_node_property<'b, 's>(
_source: &'s str,
source: &'s str,
emacs: &'b Token<'s>,
rust: &'b NodeProperty<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let child_status = Vec::new();
let mut this_status = DiffStatus::Good;
let mut child_status = Vec::new();
let mut message = None;
// Compare key
let key =
get_property_quoted_string(emacs, ":key")?.ok_or("Node properties should have a key.")?;
if key != rust.property_name {
this_status = DiffStatus::Bad;
message = Some(format!(
"Key mismatch (emacs != rust) {:?} != {:?}",
key, rust.property_name
));
}
assert_no_children(emacs, &mut this_status, &mut message)?;
// 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
));
for diff in compare_properties!(
source,
emacs,
rust,
(
EmacsField::Required(":key"),
|r| Some(r.property_name),
compare_property_quoted_string
),
(
EmacsField::Required(":value"),
|r| r.value,
compare_property_quoted_string
)
) {
match diff {
ComparePropertiesResult::NoChange => {}
ComparePropertiesResult::SelfChange(new_status, new_message) => {
this_status = new_status;
message = new_message
}
ComparePropertiesResult::DiffEntry(diff_entry) => child_status.push(diff_entry),
}
}