Assume :standard-properties is an expected field.
This commit is contained in:
parent
7af18e2312
commit
45dd38ac2d
27
src/compare/compare_field.rs
Normal file
27
src/compare/compare_field.rs
Normal file
@ -0,0 +1,27 @@
|
||||
use super::diff::DiffStatus;
|
||||
use super::sexp::Token;
|
||||
use super::util::get_property_quoted_string;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum EmacsField<'s> {
|
||||
Required(&'s str),
|
||||
Optional(&'s str),
|
||||
}
|
||||
|
||||
pub(crate) 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)
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ use std::borrow::Cow;
|
||||
use std::collections::BTreeSet;
|
||||
use std::collections::HashSet;
|
||||
|
||||
use super::compare_field::compare_property_quoted_string_required_value;
|
||||
use super::elisp_fact::ElispFact;
|
||||
use super::elisp_fact::GetElispFact;
|
||||
use super::sexp::unquote;
|
||||
@ -13,8 +14,8 @@ use super::util::get_property_boolean;
|
||||
use super::util::get_property_numeric;
|
||||
use super::util::get_property_quoted_string;
|
||||
use super::util::get_property_unquoted_atom;
|
||||
use crate::compare::compare_field::EmacsField;
|
||||
use crate::compare::macros::compare_properties;
|
||||
use crate::compare::macros::EmacsField;
|
||||
use crate::types::AngleLink;
|
||||
use crate::types::AstNode;
|
||||
use crate::types::BabelCall;
|
||||
@ -126,7 +127,7 @@ pub struct DiffResult<'b, 's> {
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
enum DiffStatus {
|
||||
pub(crate) enum DiffStatus {
|
||||
Good,
|
||||
Bad,
|
||||
}
|
||||
@ -425,24 +426,6 @@ fn compare_ast_node<'b, 's>(
|
||||
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>(
|
||||
emacs: &'b Token<'s>,
|
||||
rust: &'b Document<'s>,
|
||||
@ -2669,14 +2652,14 @@ fn compare_verbatim<'b, 's>(
|
||||
let mut this_status = DiffStatus::Good;
|
||||
let mut message = None;
|
||||
|
||||
// Compare value
|
||||
let value = get_property_quoted_string(emacs, ":value")?;
|
||||
if value.as_ref().map(String::as_str) != Some(rust.contents) {
|
||||
this_status = DiffStatus::Bad;
|
||||
message = Some(format!(
|
||||
"Value mismatch (emacs != rust) {:?} != {:?}",
|
||||
value, rust.contents
|
||||
));
|
||||
if let Some((new_status, new_message)) = compare_properties!(
|
||||
emacs,
|
||||
EmacsField::Required(":value"),
|
||||
rust.contents,
|
||||
compare_property_quoted_string_required_value
|
||||
)? {
|
||||
this_status = new_status;
|
||||
message = new_message;
|
||||
}
|
||||
|
||||
Ok(DiffResult {
|
||||
@ -2698,16 +2681,6 @@ fn compare_code<'b, 's>(
|
||||
let mut this_status = DiffStatus::Good;
|
||||
let mut message = None;
|
||||
|
||||
// Compare value
|
||||
let value = get_property_quoted_string(emacs, ":value")?;
|
||||
if value.as_ref().map(String::as_str) != Some(rust.contents) {
|
||||
this_status = DiffStatus::Bad;
|
||||
message = Some(format!(
|
||||
"Value mismatch (emacs != rust) {:?} != {:?}",
|
||||
value, rust.contents
|
||||
));
|
||||
}
|
||||
|
||||
if let Some((new_status, new_message)) = compare_properties!(
|
||||
emacs,
|
||||
EmacsField::Required(":value"),
|
||||
|
@ -1,9 +1,3 @@
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum EmacsField<'s> {
|
||||
Required(&'s str),
|
||||
Optional(&'s str),
|
||||
}
|
||||
|
||||
/// Create iterators for ast nodes where it only has to iterate over children
|
||||
macro_rules! compare_properties {
|
||||
($emacs:expr, $($emacs_field:expr, $rust_value:expr, $compare_fn: ident),+) => {
|
||||
@ -16,7 +10,7 @@ macro_rules! compare_properties {
|
||||
.nth(1)
|
||||
.ok_or("Should have an attributes child.")?;
|
||||
let attributes_map = attributes_child.as_map()?;
|
||||
let mut emacs_keys: BTreeSet<&str> = attributes_map.keys().map(|s| *s).collect();
|
||||
let mut emacs_keys: BTreeSet<&str> = attributes_map.keys().map(|s| *s).filter(|s| *s != ":standard-properties").collect();
|
||||
$(
|
||||
match $emacs_field {
|
||||
EmacsField::Required(name) if emacs_keys.contains(name) => {
|
||||
|
@ -1,4 +1,5 @@
|
||||
mod compare;
|
||||
mod compare_field;
|
||||
mod diff;
|
||||
mod elisp_fact;
|
||||
mod macros;
|
||||
|
Loading…
x
Reference in New Issue
Block a user