compare_properties drawer.

This commit is contained in:
Tom Alexander 2023-10-09 22:37:53 -04:00
parent 926682d513
commit 5b146d7c07
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -1530,35 +1530,47 @@ fn compare_drawer<'b, 's>(
emacs: &'b Token<'s>, emacs: &'b Token<'s>,
rust: &'b Drawer<'s>, rust: &'b Drawer<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> { ) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let children = emacs.as_list()?;
let mut child_status = Vec::new();
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;
// TODO: Compare :caption compare_children(
// Compare name source,
let name = get_property_quoted_string(emacs, ":name")?; emacs,
if name.as_ref().map(String::as_str) != rust.name { &rust.children,
this_status = DiffStatus::Bad; &mut child_status,
message = Some(format!( &mut this_status,
"Name mismatch (emacs != rust) {:?} != {:?}", &mut message,
name, rust.name )?;
));
}
// Compare drawer-name for diff in compare_properties!(
let drawer_name = source,
get_property_quoted_string(emacs, ":drawer-name")?.ok_or("Drawers should have a name.")?; emacs,
if drawer_name != rust.drawer_name { rust,
this_status = DiffStatus::Bad; (
message = Some(format!( EmacsField::Optional(":name"),
"Drawer name mismatch (emacs != rust) {:?} != {:?}", |r| r.name,
drawer_name, rust.drawer_name compare_property_quoted_string
)); ),
} (
EmacsField::Optional(":caption"),
for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) { compare_identity,
child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?); compare_noop
),
(
EmacsField::Required(":drawer-name"),
|r| Some(r.drawer_name),
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),
}
} }
Ok(DiffResult { Ok(DiffResult {