compare_properties table.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use std::collections::BTreeSet;
|
||||
use std::fmt::Debug;
|
||||
use std::str::FromStr;
|
||||
|
||||
@@ -208,6 +209,59 @@ pub(crate) fn compare_property_list_of_quoted_string<
|
||||
Ok(ComparePropertiesResult::NoChange)
|
||||
}
|
||||
|
||||
pub(crate) fn compare_property_set_of_quoted_string<
|
||||
'a,
|
||||
'b,
|
||||
's,
|
||||
'x,
|
||||
R,
|
||||
RV: AsRef<str> + std::fmt::Debug + Ord + 'a + ?Sized,
|
||||
RI: Iterator<Item = &'a RV>,
|
||||
RG: Fn(R) -> Option<RI>,
|
||||
>(
|
||||
_source: &'s str,
|
||||
emacs: &'b Token<'s>,
|
||||
rust_node: R,
|
||||
emacs_field: &'x str,
|
||||
rust_value_getter: RG,
|
||||
) -> Result<ComparePropertiesResult<'b, 's>, Box<dyn std::error::Error>> {
|
||||
let value = get_property(emacs, emacs_field)?
|
||||
.map(Token::as_list)
|
||||
.map_or(Ok(None), |r| r.map(Some))?;
|
||||
let empty = Vec::new();
|
||||
let value = value.unwrap_or(&empty);
|
||||
let rust_value = rust_value_getter(rust_node);
|
||||
let rust_value = if let Some(rust_value) = rust_value {
|
||||
let slices: BTreeSet<&str> = rust_value.map(|rv| rv.as_ref()).collect();
|
||||
slices
|
||||
} else {
|
||||
BTreeSet::new()
|
||||
};
|
||||
let value: Vec<&str> = value
|
||||
.iter()
|
||||
.map(|e| e.as_atom())
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
let value: Vec<String> = value
|
||||
.into_iter()
|
||||
.map(unquote)
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
let value: BTreeSet<&str> = value.iter().map(|e| e.as_str()).collect();
|
||||
let mismatched: Vec<_> = value
|
||||
.symmetric_difference(&rust_value)
|
||||
.map(|val| *val)
|
||||
.collect();
|
||||
if !mismatched.is_empty() {
|
||||
let this_status = DiffStatus::Bad;
|
||||
let message = Some(format!(
|
||||
"{} mismatch. Mismatched values: {}",
|
||||
emacs_field,
|
||||
mismatched.join(", ")
|
||||
));
|
||||
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
|
||||
}
|
||||
Ok(ComparePropertiesResult::NoChange)
|
||||
}
|
||||
|
||||
pub(crate) fn compare_property_boolean<'b, 's, 'x, R, RG: Fn(R) -> bool>(
|
||||
_source: &'s str,
|
||||
emacs: &'b Token<'s>,
|
||||
|
||||
Reference in New Issue
Block a user