Fix handling of optval.

This commit is contained in:
Tom Alexander 2023-12-29 22:58:32 -05:00
parent 0edf5620a2
commit 606bab9e6d
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -574,11 +574,11 @@ fn compare_object_tree<'e, 's, 'w>(
.expect("If-statement proves this will be Some.");
result.extend(compare_json_value(source, emacs_val, wasm_val)?)?;
} else {
// If optval is not null, then the emacs array should contain 3 values, the optval, a dot, and the val.
if emacs_attribute.len() != 3 {
// If optval is not null, then the emacs array should contain a list, the first child of which is a list for optval, and all other entries to the outer list are the val.
if emacs_attribute.len() < 2 {
result.status.push(WasmDiffStatus::Bad(
format!(
"Emacs middle layer in object tree should have a length of 3. Emacs=({emacs:?}) Wasm=({wasm:?}).",
"Emacs middle layer in object tree should have a length of at least 2. Emacs=({emacs:?}) Wasm=({wasm:?}).",
emacs = emacs_attribute,
wasm = wasm_attribute
)
@ -586,20 +586,27 @@ fn compare_object_tree<'e, 's, 'w>(
));
return Ok(result);
}
let emacs_optval = emacs_attribute
.first()
.expect("If-statement proves this will be Some.");
let emacs_optval = emacs_attribute.iter().skip(1);
let wasm_optval = wasm_attribute
.first()
.expect("If-statement proves this will be Some.");
.expect("If-statement proves this will be Some.")
.as_array()
.ok_or("first value in wasm object tree should be a list.")?;
let emacs_val = emacs_attribute
.get(2)
.expect("If-statement proves this will be Some.");
.first()
.ok_or("If-statement proves this will be Some.")?
.as_list()?;
let wasm_val = wasm_attribute
.get(1)
.expect("If-statement proves this will be Some.");
result.extend(compare_json_value(source, emacs_optval, wasm_optval)?)?;
result.extend(compare_json_value(source, emacs_val, wasm_val)?)?;
.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())?)?;
result.extend(wasm_compare_list(
source,
emacs_val.iter(),
wasm_val.iter(),
)?)?;
}
}