Compare commits

..

No commits in common. "f4eff5ca5631ec0447d8d59c440b978cdd81da5f" and "5f1668702a98472dbf9a358360c81bcc07478e11" have entirely different histories.

4 changed files with 6 additions and 71 deletions

View File

@ -16,4 +16,3 @@ pub(crate) use compare_field::EmacsField;
pub(crate) use elisp_fact::ElispFact;
pub use sexp::sexp;
pub use sexp::Token;
pub(crate) use util::get_property_quoted_string;

View File

@ -6,7 +6,6 @@ use super::ast_node::WasmAstNode;
use super::macros::to_wasm;
use super::standard_properties::WasmStandardProperties;
use super::to_wasm::ToWasm;
#[cfg(feature = "wasm_test")]
use crate::compare::ElispFact;
use crate::types::Document;
use crate::wasm::to_wasm::ToWasmStandardProperties;
@ -19,7 +18,7 @@ pub struct WasmDocument<'s, 'p> {
additional_properties: Vec<(String, &'s str)>,
pub(crate) children: Vec<WasmAstNode<'s, 'p>>,
category: Option<&'p str>,
pub(crate) path: Option<PathBuf>,
path: Option<PathBuf>,
}
to_wasm!(
@ -73,7 +72,6 @@ impl<'s, 'p> Into<WasmAstNode<'s, 'p>> for WasmDocument<'s, 'p> {
}
}
#[cfg(feature = "wasm_test")]
impl<'s, 'p> ElispFact<'s> for WasmDocument<'s, 'p> {
fn get_elisp_name<'b>(&'b self) -> std::borrow::Cow<'s, str> {
"org-data".into()

View File

@ -1,7 +1,6 @@
use std::borrow::Cow;
use super::elisp_compare::WasmElispCompare;
use crate::compare::get_property_quoted_string;
use crate::compare::ElispFact;
use crate::compare::EmacsField;
use crate::compare::Token;
@ -246,39 +245,10 @@ impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmDocument<'s, 'p> {
(
EmacsField::Required(":path"),
|w| w.path.as_ref().and_then(|p| p.to_str()),
wasm_compare_property_quoted_string
|| true
)
);
// todo: compare the rest
Ok(result)
}
}
fn wasm_compare_property_quoted_string<
'b,
's,
W,
WV: AsRef<str> + std::fmt::Debug,
WG: Fn(W) -> Option<WV>,
>(
_source: &'s str,
emacs: &'b Token<'s>,
wasm_node: W,
emacs_field: &str,
wasm_value_getter: WG,
) -> Result<WasmDiffResult<'s>, Box<dyn std::error::Error>> {
let mut result = WasmDiffResult::default();
let emacs_value = get_property_quoted_string(emacs, emacs_field)?;
let wasm_value = wasm_value_getter(wasm_node);
if wasm_value.as_ref().map(|s| s.as_ref()) != emacs_value.as_deref() {
result.status.push(WasmDiffStatus::Bad(
format!(
"Property mismatch. Property=({property}) Emacs=({emacs:?}) Wasm=({wasm:?}).",
property = emacs_field,
emacs = emacs_value,
wasm = wasm_value,
)
.into(),
))
}
Ok(result)
}

View File

@ -15,7 +15,7 @@ macro_rules! wasm_compare {
emacs_attributes_map.keys().map(|s| *s).collect();
{
// Compare name.
// Compare name
let wasm_name = $wasm.get_elisp_name();
if emacs_name != wasm_name {
@ -31,7 +31,7 @@ macro_rules! wasm_compare {
}
{
// Compare children.
// Compare children
result.extend(wasm_compare_list(
$source,
emacs_list_iter,
@ -40,7 +40,7 @@ macro_rules! wasm_compare {
}
{
// Check for properties that are missing from the elisp node.
// Compare fields
$(
match $emacs_field {
EmacsField::Required(name) if emacs_keys.contains(name) => {
@ -63,38 +63,6 @@ macro_rules! wasm_compare {
)*
}
{
// Check for elisp properties that were not compared.
if !emacs_keys.is_empty() {
let unexpected_keys: Vec<&str> = emacs_keys.into_iter().collect();
let unexpected_keys = unexpected_keys.join(", ");
result.status.push(WasmDiffStatus::Bad(
format!(
"Emacs node had extra field(s): ({field_names}).",
field_names = unexpected_keys,
)
.into(),
));
}
}
{
// Compare properties.
$(
let emacs_name = match $emacs_field {
EmacsField::Required(name) => {
name
},
EmacsField::Optional(name) => {
name
},
};
let result = $compare_fn($source, $emacs, $wasm, emacs_name, $wasm_value_getter)?;
// TODO: record this result.
)*
}
result
}};
}