compare_properties special block.

This commit is contained in:
Tom Alexander 2023-10-09 22:01:26 -04:00
parent ca1b633a9f
commit 9ab649ebd4
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -1291,51 +1291,59 @@ fn compare_special_block<'b, 's>(
emacs: &'b Token<'s>,
rust: &'b SpecialBlock<'s>,
) -> 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 child_status = Vec::new();
let mut message = None;
// TODO: Compare :caption
// Compare name
let name = get_property_quoted_string(emacs, ":name")?;
if name.as_ref().map(String::as_str) != rust.name {
this_status = DiffStatus::Bad;
message = Some(format!(
"Name mismatch (emacs != rust) {:?} != {:?}",
name, rust.name
));
}
compare_children(
source,
emacs,
&rust.children,
&mut child_status,
&mut this_status,
&mut message,
)?;
// Compare type
let special_block_type =
get_property_quoted_string(emacs, ":type")?.ok_or("Special blocks should have a name.")?;
if special_block_type != rust.block_type {
this_status = DiffStatus::Bad;
message = Some(format!(
"Name mismatch (emacs != rust) {:?} != {:?}",
special_block_type, rust.block_type
));
}
// Compare parameters
let parameters = get_property_quoted_string(emacs, ":parameters")?;
match (parameters.as_ref(), rust.parameters) {
(None, None) => {}
(Some(emacs_parameters), Some(rust_parameters)) if emacs_parameters == rust_parameters => {}
_ => {
this_status = DiffStatus::Bad;
message = Some(format!(
"Parameters mismatch (emacs != rust) {:?} != {:?}",
parameters, rust.parameters
));
for diff in compare_properties!(
source,
emacs,
rust,
(
EmacsField::Optional(":name"),
|r| r.name,
compare_property_quoted_string
),
(
EmacsField::Optional(":caption"),
compare_identity,
compare_noop
),
(
EmacsField::Required(":type"),
|r| Some(r.block_type),
compare_property_quoted_string
),
(
EmacsField::Required(":parameters"),
|r| r.parameters,
compare_property_quoted_string
),
(
EmacsField::Optional(":results"),
compare_identity,
compare_noop
)
) {
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 {
status: this_status,
name: rust.get_elisp_name(),