compare_properties dynamic block.

This commit is contained in:
Tom Alexander 2023-10-09 22:28:32 -04:00
parent 9ab649ebd4
commit 62926bb91d
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -1360,51 +1360,54 @@ fn compare_dynamic_block<'b, 's>(
emacs: &'b Token<'s>, emacs: &'b Token<'s>,
rust: &'b DynamicBlock<'s>, rust: &'b DynamicBlock<'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 block-name for diff in compare_properties!(
let block_name = get_property_quoted_string(emacs, ":block-name")? source,
.ok_or("Dynamic blocks should have a name.")?; emacs,
if block_name != rust.block_name { rust,
this_status = DiffStatus::Bad; (
message = Some(format!( EmacsField::Optional(":name"),
"Name mismatch (emacs != rust) {:?} != {:?}", |r| r.name,
block_name, rust.block_name compare_property_quoted_string
)); ),
} (
EmacsField::Optional(":caption"),
// Compare arguments compare_identity,
let parameters = get_property_quoted_string(emacs, ":arguments")?; compare_noop
match (parameters.as_ref(), rust.parameters) { ),
(None, None) => {} (
(Some(emacs_parameters), Some(rust_parameters)) if emacs_parameters == rust_parameters => {} EmacsField::Required(":block-name"),
_ => { |r| Some(r.block_name),
this_status = DiffStatus::Bad; compare_property_quoted_string
message = Some(format!( ),
"Parameters mismatch (emacs != rust) {:?} != {:?}", (
parameters, rust.parameters EmacsField::Required(":arguments"),
)); |r| r.parameters,
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),
} }
} }
for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) {
child_status.push(compare_ast_node(source, emacs_child, rust_child.into())?);
}
Ok(DiffResult { Ok(DiffResult {
status: this_status, status: this_status,
name: rust.get_elisp_name(), name: rust.get_elisp_name(),