Implement the comparison.
This commit is contained in:
parent
d06e4de7b0
commit
1b603f3a05
@ -425,6 +425,24 @@ fn compare_ast_node<'b, 's>(
|
|||||||
Ok(compare_result.into())
|
Ok(compare_result.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn compare_property_quoted_string_required_value<'b, 's, 'x>(
|
||||||
|
emacs: &'b Token<'s>,
|
||||||
|
emacs_field: &'x str,
|
||||||
|
rust_value: &'s str,
|
||||||
|
) -> Result<Option<(DiffStatus, Option<String>)>, Box<dyn std::error::Error>> {
|
||||||
|
let value = get_property_quoted_string(emacs, emacs_field)?;
|
||||||
|
if value.as_ref().map(String::as_str) != Some(rust_value) {
|
||||||
|
let this_status = DiffStatus::Bad;
|
||||||
|
let message = Some(format!(
|
||||||
|
"{} mismatch (emacs != rust) {:?} != {:?}",
|
||||||
|
emacs_field, value, rust_value
|
||||||
|
));
|
||||||
|
Ok(Some((this_status, message)))
|
||||||
|
} else {
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn compare_document<'b, 's>(
|
pub fn compare_document<'b, 's>(
|
||||||
emacs: &'b Token<'s>,
|
emacs: &'b Token<'s>,
|
||||||
rust: &'b Document<'s>,
|
rust: &'b Document<'s>,
|
||||||
@ -2690,8 +2708,15 @@ fn compare_code<'b, 's>(
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let foo: Result<Option<(DiffStatus, Option<String>)>, Box<dyn std::error::Error>> =
|
if let Some((new_status, new_message)) = compare_properties!(
|
||||||
compare_properties!(emacs, EmacsField::Required(":value"));
|
emacs,
|
||||||
|
EmacsField::Required(":value"),
|
||||||
|
rust.contents,
|
||||||
|
compare_property_quoted_string_required_value
|
||||||
|
)? {
|
||||||
|
this_status = new_status;
|
||||||
|
message = new_message;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(DiffResult {
|
Ok(DiffResult {
|
||||||
status: this_status,
|
status: this_status,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/// Create iterators for ast nodes where it only has to iterate over children
|
/// Create iterators for ast nodes where it only has to iterate over children
|
||||||
macro_rules! compare_properties {
|
macro_rules! compare_properties {
|
||||||
($emacs:expr, $($emacs_field:expr),+) => {
|
($emacs:expr, $($emacs_field:expr, $rust_value:expr, $compare_fn: ident),+) => {
|
||||||
{
|
{
|
||||||
let mut this_status = DiffStatus::Good;
|
let mut this_status = DiffStatus::Good;
|
||||||
let mut message: Option<String> = None;
|
let mut message: Option<String> = None;
|
||||||
@ -41,12 +41,29 @@ macro_rules! compare_properties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$(
|
$(
|
||||||
println!("{:?}", $emacs_field);
|
let emacs_name = match $emacs_field {
|
||||||
|
EmacsField::Required(name) => {
|
||||||
|
name
|
||||||
|
},
|
||||||
|
EmacsField::Optional(name) => {
|
||||||
|
name
|
||||||
|
},
|
||||||
|
};
|
||||||
|
let result = $compare_fn($emacs, emacs_name, $rust_value)?;
|
||||||
|
match result {
|
||||||
|
Some((DiffStatus::Good, _)) => unreachable!("No comparison functions should return Some() when DiffStatus is good."),
|
||||||
|
Some((status, msg)) => {
|
||||||
|
this_status = status;
|
||||||
|
message = msg;
|
||||||
|
},
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
),+
|
),+
|
||||||
|
|
||||||
match this_status {
|
match this_status {
|
||||||
DiffStatus::Good => {
|
DiffStatus::Good => {
|
||||||
Ok(None)
|
let result: Result<_, Box<dyn std::error::Error>> = Ok(None);
|
||||||
|
result
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
Ok(Some((this_status, message)))
|
Ok(Some((this_status, message)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user