Add a default case for tokens which do not have any expected properties except for :standard-properties.
This commit is contained in:
parent
45dd38ac2d
commit
ae11e390d1
@ -2575,9 +2575,14 @@ fn compare_bold<'b, 's>(
|
||||
rust: &'b Bold<'s>,
|
||||
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
|
||||
let children = emacs.as_list()?;
|
||||
let this_status = DiffStatus::Good;
|
||||
let mut this_status = DiffStatus::Good;
|
||||
let mut child_status = Vec::new();
|
||||
let message = None;
|
||||
let mut message = None;
|
||||
|
||||
if let Some((new_status, new_message)) = compare_properties!(emacs)? {
|
||||
this_status = new_status;
|
||||
message = new_message;
|
||||
}
|
||||
|
||||
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())?);
|
||||
|
@ -10,7 +10,15 @@ macro_rules! compare_properties {
|
||||
.nth(1)
|
||||
.ok_or("Should have an attributes child.")?;
|
||||
let attributes_map = attributes_child.as_map()?;
|
||||
let mut emacs_keys: BTreeSet<&str> = attributes_map.keys().map(|s| *s).filter(|s| *s != ":standard-properties").collect();
|
||||
let mut emacs_keys: BTreeSet<&str> = attributes_map.keys().map(|s| *s).collect();
|
||||
if emacs_keys.contains(":standard-properties") {
|
||||
emacs_keys.remove(":standard-properties");
|
||||
} else {
|
||||
this_status = DiffStatus::Bad;
|
||||
message = Some(format!(
|
||||
"Emacs token lacks :standard-properties field.",
|
||||
));
|
||||
}
|
||||
$(
|
||||
match $emacs_field {
|
||||
EmacsField::Required(name) if emacs_keys.contains(name) => {
|
||||
@ -71,6 +79,47 @@ macro_rules! compare_properties {
|
||||
}
|
||||
}
|
||||
};
|
||||
// Default case for when there are no expected properties except for :standard-properties
|
||||
($emacs:expr) => {
|
||||
{
|
||||
let mut this_status = DiffStatus::Good;
|
||||
let mut message: Option<String> = None;
|
||||
let children = $emacs.as_list()?;
|
||||
let attributes_child = children
|
||||
.iter()
|
||||
.nth(1)
|
||||
.ok_or("Should have an attributes child.")?;
|
||||
let attributes_map = attributes_child.as_map()?;
|
||||
let mut emacs_keys: BTreeSet<&str> = attributes_map.keys().map(|s| *s).collect();
|
||||
if emacs_keys.contains(":standard-properties") {
|
||||
emacs_keys.remove(":standard-properties");
|
||||
} else {
|
||||
this_status = DiffStatus::Bad;
|
||||
message = Some(format!(
|
||||
"Emacs token lacks :standard-properties field.",
|
||||
));
|
||||
}
|
||||
|
||||
if !emacs_keys.is_empty() {
|
||||
let unexpected_keys: Vec<&str> = emacs_keys.into_iter().collect();
|
||||
let unexpected_keys = unexpected_keys.join(", ");
|
||||
this_status = DiffStatus::Bad;
|
||||
message = Some(format!(
|
||||
"Emacs token had extra field(s): {}",
|
||||
unexpected_keys
|
||||
));
|
||||
}
|
||||
match this_status {
|
||||
DiffStatus::Good => {
|
||||
let result: Result<_, Box<dyn std::error::Error>> = Ok(None);
|
||||
result
|
||||
},
|
||||
_ => {
|
||||
Ok(Some((this_status, message)))
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub(crate) use compare_properties;
|
||||
|
Loading…
x
Reference in New Issue
Block a user