From 8bc942a26f796d8c775fb2e839e9253881c7b870 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Wed, 11 Oct 2023 19:13:45 -0400 Subject: [PATCH] Create artificial scopes for the optional value and mandatory value. --- src/compare/compare_field.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/compare/compare_field.rs b/src/compare/compare_field.rs index edf86b28..01896aad 100644 --- a/src/compare/compare_field.rs +++ b/src/compare/compare_field.rs @@ -460,7 +460,7 @@ pub(crate) fn compare_property_list_of_list_of_list_of_ast_nodes< (Some(value), Some(rust_value)) => (value, rust_value), }; - let mut child_status: Vec> = Vec::with_capacity(rust_value.len()); + let mut full_status: Vec> = Vec::with_capacity(rust_value.len()); // Iterate the outer lists for (value, (rust_optional, rust_value)) in value.iter().zip(rust_value.iter()) { @@ -481,6 +481,7 @@ pub(crate) fn compare_property_list_of_list_of_list_of_ast_nodes< // Compare optional value if let Some(rust_optional) = rust_optional { + let mut child_status: Vec> = Vec::with_capacity(rust_value.len()); if rust_optional.len() != middle_value.len() { let this_status = DiffStatus::Bad; let message = Some(format!( @@ -495,9 +496,14 @@ pub(crate) fn compare_property_list_of_list_of_list_of_ast_nodes< for (e, r) in middle_value.zip(rust_optional) { child_status.push(compare_ast_node(source, e, r.into())?); } + if !child_status.is_empty() { + let diff_scope = artificial_diff_scope("optional value", child_status)?; + full_status.push(diff_scope); + } } // Compare mandatory value + let mut child_status: Vec> = Vec::with_capacity(rust_value.len()); let mandatory_value = mandatory_value.as_list()?; if rust_value.len() != mandatory_value.len() { let this_status = DiffStatus::Bad; @@ -513,11 +519,15 @@ pub(crate) fn compare_property_list_of_list_of_list_of_ast_nodes< for (e, r) in mandatory_value.iter().zip(rust_value) { child_status.push(compare_ast_node(source, e, r.into())?); } + if !child_status.is_empty() { + let diff_scope = artificial_diff_scope("mandatory value", child_status)?; + full_status.push(diff_scope); + } } - if child_status.is_empty() { + if full_status.is_empty() { Ok(ComparePropertiesResult::NoChange) } else { - let diff_scope = artificial_owned_diff_scope(emacs_field, child_status)?; + let diff_scope = artificial_owned_diff_scope(emacs_field, full_status)?; Ok(ComparePropertiesResult::DiffEntry(diff_scope)) } }