From b18a703529bfae9cd7eab6c1142bbf05e57c3a40 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Tue, 31 Oct 2023 17:19:35 -0400 Subject: [PATCH] Handle nil values for compare_property_object_tree. --- .../affiliated_keyword/empty_caption.org | 5 ++ src/compare/compare_field.rs | 52 ++++++++++++++----- 2 files changed, 45 insertions(+), 12 deletions(-) create mode 100644 org_mode_samples/affiliated_keyword/empty_caption.org diff --git a/org_mode_samples/affiliated_keyword/empty_caption.org b/org_mode_samples/affiliated_keyword/empty_caption.org new file mode 100644 index 00000000..08d802f8 --- /dev/null +++ b/org_mode_samples/affiliated_keyword/empty_caption.org @@ -0,0 +1,5 @@ +#+caption: +#+caption: *foo* +#+caption[bar]: +#+begin_src bash +#+end_src diff --git a/src/compare/compare_field.rs b/src/compare/compare_field.rs index 3d40dd9a..9ab611f9 100644 --- a/src/compare/compare_field.rs +++ b/src/compare/compare_field.rs @@ -548,6 +548,21 @@ where let mut full_status: Vec> = Vec::with_capacity(outer_rust_list.len()); for (kw_e, kw_r) in outer_emacs_list.iter().zip(outer_rust_list) { + match (kw_e.as_atom(), kw_r) { + (Ok("nil"), (None, mandatory_value)) if mandatory_value.is_empty() => { + // If its an empty keyword then it becomes nil in the elisp. + continue; + } + (Ok("nil"), _) => { + let this_status = DiffStatus::Bad; + let message = Some(format!( + "{} mismatch (emacs != rust) {:?} != {:?}", + emacs_field, kw_e, kw_r + )); + return Ok(ComparePropertiesResult::SelfChange(this_status, message)); + } + _ => {} + } let kw_e = kw_e.as_list()?; let child_status_length = kw_r.1.len() + kw_r.0.as_ref().map(|opt| opt.len()).unwrap_or(0); let mut child_status: Vec> = Vec::with_capacity(child_status_length); @@ -556,18 +571,31 @@ where let mut kw_e = kw_e.iter(); // First element is a list representing the mandatory value. if let Some(val_e) = kw_e.next() { - let el = val_e.as_list()?; - if el.len() != kw_r.1.len() { - let this_status = DiffStatus::Bad; - let message = Some(format!( - "{} mismatch (emacs != rust) {:?} != {:?}", - emacs_field, kw_e, kw_r - )); - return Ok(ComparePropertiesResult::SelfChange(this_status, message)); - } - for (e, r) in el.iter().zip(kw_r.1.iter()) { - child_status.push(compare_ast_node(source, e, r.into())?); - } + match (val_e.as_atom(), kw_r) { + (Ok("nil"), (_, mandatory_value)) if mandatory_value.is_empty() => {} + (Ok("nil"), _) => { + let this_status = DiffStatus::Bad; + let message = Some(format!( + "{} mismatch (emacs != rust) {:?} != {:?}", + emacs_field, kw_e, kw_r + )); + return Ok(ComparePropertiesResult::SelfChange(this_status, message)); + } + _ => { + let el = val_e.as_list()?; + if el.len() != kw_r.1.len() { + let this_status = DiffStatus::Bad; + let message = Some(format!( + "{} mismatch (emacs != rust) {:?} != {:?}", + emacs_field, kw_e, kw_r + )); + return Ok(ComparePropertiesResult::SelfChange(this_status, message)); + } + for (e, r) in el.iter().zip(kw_r.1.iter()) { + child_status.push(compare_ast_node(source, e, r.into())?); + } + } + }; } else { let this_status = DiffStatus::Bad; let message = Some(format!(