Handle nil in object tree.

This commit is contained in:
Tom Alexander 2023-12-30 21:26:23 -05:00
parent ff3e0a50af
commit dc0338e978
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -566,7 +566,6 @@ fn compare_object_tree<'e, 's, 'w>(
}
for (emacs_attribute, wasm_attribute) in emacs.iter().zip(wasm_attributes.iter()) {
let emacs_attribute = emacs_attribute.as_list()?;
let wasm_attribute = wasm_attribute
.as_array()
.ok_or("Wasm middle layer in object tree should be a list.")?;
@ -580,6 +579,16 @@ fn compare_object_tree<'e, 's, 'w>(
));
return Ok(result);
}
if let Ok("nil") = emacs_attribute.as_atom() {
if let Some(serde_json::Value::Null) = wasm_attribute.first() {
if let Some(serde_json::Value::Array(w)) = wasm_attribute.get(1) {
if w.is_empty() {
continue;
}
}
}
}
let emacs_attribute = emacs_attribute.as_list()?;
if let Some(serde_json::Value::Null) = wasm_attribute.first() {
// If optval is null then the emacs array should only contain 1 value.
if emacs_attribute.len() != 1 {
@ -622,19 +631,26 @@ fn compare_object_tree<'e, 's, 'w>(
.ok_or("first value in wasm object tree should be a list.")?;
let emacs_val = emacs_attribute
.first()
.ok_or("If-statement proves this will be Some.")?
.as_list()?;
.ok_or("If-statement proves this will be Some.")?;
let wasm_val = wasm_attribute
.get(1)
.expect("If-statement proves this will be Some.")
.as_array()
.ok_or("2nd value in wasm object tree should be a list.")?;
result.extend(wasm_compare_list(source, emacs_optval, wasm_optval.iter())?)?;
if let Ok("nil") = emacs_val.as_atom() {
result.extend(wasm_compare_list(
source,
emacs_val.iter(),
std::iter::empty(),
wasm_val.iter(),
)?)?;
} else {
result.extend(wasm_compare_list(
source,
emacs_val.as_list()?.iter(),
wasm_val.iter(),
)?)?;
}
}
}