Compare commits

...

2 Commits

Author SHA1 Message Date
Tom Alexander
680b176501
Fix src block value.
Some checks failed
clippy Build clippy has failed
rust-foreign-document-test Build rust-foreign-document-test has succeeded
rust-build Build rust-build has failed
rust-test Build rust-test has succeeded
2023-12-30 21:30:08 -05:00
Tom Alexander
dc0338e978
Handle nil in object tree. 2023-12-30 21:28:25 -05:00
2 changed files with 25 additions and 9 deletions

View File

@ -74,7 +74,7 @@ to_wasm!(
WasmSrcBlock {
additional_properties,
language: original.language.map(|s| s.to_owned()),
value: original.value.to_owned(),
value: original.get_value().into_owned(),
switches: original.switches.map(|s| s.to_owned()),
parameters: original.parameters.map(|s| s.to_owned()),
number_lines: match original.number_lines {

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())?)?;
result.extend(wasm_compare_list(
source,
emacs_val.iter(),
wasm_val.iter(),
)?)?;
if let Ok("nil") = emacs_val.as_atom() {
result.extend(wasm_compare_list(
source,
std::iter::empty(),
wasm_val.iter(),
)?)?;
} else {
result.extend(wasm_compare_list(
source,
emacs_val.as_list()?.iter(),
wasm_val.iter(),
)?)?;
}
}
}