compare_properties plain list.

This commit is contained in:
Tom Alexander 2023-10-09 21:42:07 -04:00
parent 7a38d1ead3
commit 409a92333e
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -1059,43 +1059,53 @@ fn compare_plain_list<'b, 's>(
emacs: &'b Token<'s>, emacs: &'b Token<'s>,
rust: &'b PlainList<'s>, rust: &'b PlainList<'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 type for diff in compare_properties!(
// :type is an unquoted atom of either descriptive, ordered, or unordered source,
let list_type = get_property_unquoted_atom(emacs, ":type")?; emacs,
match (list_type, &rust.list_type) { rust,
(None, _) => panic!("Emacs returned a list with no type."), (
(Some("unordered"), PlainListType::Unordered) => {} EmacsField::Optional(":name"),
(Some("ordered"), PlainListType::Ordered) => {} |r| r.name,
(Some("descriptive"), PlainListType::Descriptive) => {} compare_property_quoted_string
_ => { ),
this_status = DiffStatus::Bad; (
message = Some(format!( EmacsField::Optional(":caption"),
"List type mismatch (emacs != rust) {:?} != {:?}", compare_identity,
list_type, rust.list_type compare_noop
)); ),
(
EmacsField::Required(":type"),
|r| Some(match r.list_type {
PlainListType::Unordered => "unordered",
PlainListType::Ordered => "ordered",
PlainListType::Descriptive => "descriptive",
}),
compare_property_unquoted_atom
)
) {
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(),