Compare optional value.
This commit is contained in:
parent
aeb2b6fe68
commit
b1a0fa4acf
@ -424,7 +424,7 @@ pub(crate) fn compare_property_list_of_list_of_list_of_ast_nodes<
|
|||||||
's,
|
's,
|
||||||
'x,
|
'x,
|
||||||
R,
|
R,
|
||||||
RG: Fn(R) -> Option<&'b Vec<Vec<Object<'s>>>>,
|
RG: Fn(R) -> Option<&'b Vec<(Option<Vec<Object<'s>>>, Vec<Object<'s>>)>>,
|
||||||
>(
|
>(
|
||||||
source: &'s str,
|
source: &'s str,
|
||||||
emacs: &'b Token<'s>,
|
emacs: &'b Token<'s>,
|
||||||
@ -461,10 +461,41 @@ pub(crate) fn compare_property_list_of_list_of_list_of_ast_nodes<
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Iterate the outer lists
|
// Iterate the outer lists
|
||||||
for (value, rust_value) in value.iter().zip(rust_value.iter()) {
|
for (value, (rust_optional, rust_value)) in value.iter().zip(rust_value.iter()) {
|
||||||
// Assert the middle list is a length of 1 because I've never seen it any other way.
|
let mut middle_value = value.as_list()?.iter();
|
||||||
let value = value.as_list()?;
|
// First element of middle list is the mandatory value (the value past the colon).
|
||||||
if value.len() != 1 {
|
let mandatory_value = middle_value.next();
|
||||||
|
let mandatory_value = match mandatory_value {
|
||||||
|
Some(mandatory_value) => mandatory_value,
|
||||||
|
None => {
|
||||||
|
let this_status = DiffStatus::Bad;
|
||||||
|
let message = Some(format!(
|
||||||
|
"{} mismatch (emacs != rust) {:?} != {:?}",
|
||||||
|
emacs_field, value, rust_value
|
||||||
|
));
|
||||||
|
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let mut child_status: Vec<DiffEntry<'b, 's>> = Vec::with_capacity(rust_value.len());
|
||||||
|
|
||||||
|
// Compare optional value
|
||||||
|
if let Some(rust_optional) = rust_optional {
|
||||||
|
if rust_optional.len() != middle_value.len() {
|
||||||
|
let this_status = DiffStatus::Bad;
|
||||||
|
let message = Some(format!(
|
||||||
|
"{} mismatch (emacs != rust) {:?} != {:?}",
|
||||||
|
emacs_field, value, rust_value
|
||||||
|
));
|
||||||
|
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
||||||
|
}
|
||||||
|
for (e, r) in middle_value.zip(rust_optional) {
|
||||||
|
child_status.push(compare_ast_node(source, e, r.into())?);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compare mandatory value
|
||||||
|
let mandatory_value = mandatory_value.as_list()?;
|
||||||
|
if rust_value.len() != mandatory_value.len() {
|
||||||
let this_status = DiffStatus::Bad;
|
let this_status = DiffStatus::Bad;
|
||||||
let message = Some(format!(
|
let message = Some(format!(
|
||||||
"{} mismatch (emacs != rust) {:?} != {:?}",
|
"{} mismatch (emacs != rust) {:?} != {:?}",
|
||||||
@ -472,14 +503,7 @@ pub(crate) fn compare_property_list_of_list_of_list_of_ast_nodes<
|
|||||||
));
|
));
|
||||||
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
||||||
}
|
}
|
||||||
// Drill past the middle list to the inner list.
|
for (e, r) in mandatory_value.iter().zip(rust_value) {
|
||||||
let value = value
|
|
||||||
.first()
|
|
||||||
.expect("The above if-statement asserts this exists.");
|
|
||||||
let value = value.as_list()?;
|
|
||||||
// Compare inner lists
|
|
||||||
let mut child_status: Vec<DiffEntry<'b, 's>> = Vec::with_capacity(rust_value.len());
|
|
||||||
for (e, r) in value.iter().zip(rust_value) {
|
|
||||||
child_status.push(compare_ast_node(source, e, r.into())?);
|
child_status.push(compare_ast_node(source, e, r.into())?);
|
||||||
}
|
}
|
||||||
let diff_scope = artificial_owned_diff_scope(emacs_field, child_status)?;
|
let diff_scope = artificial_owned_diff_scope(emacs_field, child_status)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user