Implement a compare_property_numeric.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use std::fmt::Debug;
|
||||
use std::str::FromStr;
|
||||
|
||||
use super::diff::artificial_diff_scope;
|
||||
use super::diff::compare_ast_node;
|
||||
@@ -7,6 +8,7 @@ use super::diff::DiffStatus;
|
||||
use super::sexp::unquote;
|
||||
use super::sexp::Token;
|
||||
use super::util::get_property;
|
||||
use super::util::get_property_numeric;
|
||||
use super::util::get_property_quoted_string;
|
||||
use super::util::get_property_unquoted_atom;
|
||||
use crate::types::AstNode;
|
||||
@@ -117,6 +119,38 @@ pub(crate) fn compare_property_unquoted_atom<'b, 's, 'x, R, RG: Fn(R) -> Option<
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn compare_property_numeric<
|
||||
'b,
|
||||
's,
|
||||
'x,
|
||||
R,
|
||||
RV: FromStr + PartialEq + Debug,
|
||||
RG: Fn(R) -> Option<RV>,
|
||||
>(
|
||||
_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 + 's>>
|
||||
where
|
||||
<RV as FromStr>::Err: std::error::Error,
|
||||
<RV as FromStr>::Err: 's,
|
||||
{
|
||||
let value = get_property_numeric::<RV>(emacs, emacs_field)?;
|
||||
let rust_value = rust_value_getter(rust_node);
|
||||
if rust_value != value {
|
||||
let this_status = DiffStatus::Bad;
|
||||
let message = Some(format!(
|
||||
"{} mismatch (emacs != rust) {:?} != {:?}",
|
||||
emacs_field, value, rust_value
|
||||
));
|
||||
Ok(ComparePropertiesResult::SelfChange(this_status, message))
|
||||
} else {
|
||||
Ok(ComparePropertiesResult::NoChange)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn compare_property_list_of_quoted_string<
|
||||
'b,
|
||||
's,
|
||||
|
||||
Reference in New Issue
Block a user