Merge branch 'compare_additional_properties'
This commit is contained in:
commit
32d6b3d1ee
@ -32,6 +32,26 @@ pub(crate) enum ComparePropertiesResult<'b, 's> {
|
||||
DiffEntry(DiffEntry<'b, 's>),
|
||||
}
|
||||
|
||||
impl<'b, 's> ComparePropertiesResult<'b, 's> {
|
||||
pub(crate) fn apply(
|
||||
self,
|
||||
child_status: &mut Vec<DiffEntry<'b, 's>>,
|
||||
this_status: &mut DiffStatus,
|
||||
message: &mut Option<String>,
|
||||
) {
|
||||
match self {
|
||||
ComparePropertiesResult::NoChange => {}
|
||||
ComparePropertiesResult::SelfChange(new_status, new_message) => {
|
||||
*this_status = new_status;
|
||||
*message = new_message
|
||||
}
|
||||
ComparePropertiesResult::DiffEntry(diff_entry) => child_status.push(diff_entry),
|
||||
}
|
||||
|
||||
// foo
|
||||
}
|
||||
}
|
||||
|
||||
/// Do no comparison.
|
||||
///
|
||||
/// This is for when you want to acknowledge that a field exists in the emacs token, but you do not have any validation for it when using the compare_properties!() macro. Ideally, this should be kept to a minimum since this represents untested values.
|
||||
|
@ -21,6 +21,7 @@ use super::elisp_fact::GetElispFact;
|
||||
use super::sexp::unquote;
|
||||
use super::sexp::Token;
|
||||
use super::util::assert_no_children;
|
||||
use super::util::compare_additional_properties;
|
||||
use super::util::compare_children;
|
||||
use super::util::compare_children_iter;
|
||||
use super::util::compare_standard_properties;
|
||||
@ -542,6 +543,22 @@ fn compare_heading<'b, 's>(
|
||||
.map(|node_property| format!(":{}", node_property.property_name.to_uppercase()))
|
||||
.collect();
|
||||
|
||||
let additional_properties: Vec<(String, &str)> = rust
|
||||
.get_additional_properties()
|
||||
.map(|node_property| {
|
||||
(
|
||||
format!(":{}", node_property.property_name.to_uppercase()),
|
||||
node_property.value.unwrap_or(""),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
compare_additional_properties(emacs, additional_properties.into_iter())?.apply(
|
||||
&mut child_status,
|
||||
&mut this_status,
|
||||
&mut message,
|
||||
);
|
||||
|
||||
compare_children(
|
||||
source,
|
||||
emacs,
|
||||
|
@ -1,5 +1,6 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use super::compare_field::ComparePropertiesResult;
|
||||
use super::diff::DiffEntry;
|
||||
use super::diff::DiffStatus;
|
||||
use super::elisp_fact::GetElispFact;
|
||||
@ -311,3 +312,28 @@ pub(crate) fn assert_no_children<'b, 's>(
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn compare_additional_properties<'b, 's, RK, RV, RI>(
|
||||
emacs: &'b Token<'s>,
|
||||
rust_children: RI,
|
||||
) -> Result<ComparePropertiesResult<'b, 's>, Box<dyn std::error::Error>>
|
||||
where
|
||||
RK: AsRef<str>,
|
||||
RV: AsRef<str>,
|
||||
RI: Iterator<Item = (RK, RV)> + ExactSizeIterator,
|
||||
{
|
||||
for (rust_key, rust_value) in rust_children {
|
||||
let rust_key = rust_key.as_ref();
|
||||
let rust_value = rust_value.as_ref();
|
||||
let emacs_value = get_property_quoted_string(emacs, rust_key)?;
|
||||
if Some(rust_value) != emacs_value.as_ref().map(String::as_str) {
|
||||
let this_status = DiffStatus::Bad;
|
||||
let message = Some(format!(
|
||||
"{} mismatch (emacs != rust) {:?} != {:?}",
|
||||
rust_key, emacs_value, rust_value
|
||||
));
|
||||
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
||||
}
|
||||
}
|
||||
Ok(ComparePropertiesResult::NoChange)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user