Progress on comparing properties in the wasm_compare macro.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
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;
|
||||
@@ -245,10 +246,39 @@ impl<'s, 'p> WasmElispCompare<'s, 'p> for WasmDocument<'s, 'p> {
|
||||
(
|
||||
EmacsField::Required(":path"),
|
||||
|w| w.path.as_ref().and_then(|p| p.to_str()),
|
||||
|| true
|
||||
wasm_compare_property_quoted_string
|
||||
)
|
||||
);
|
||||
// 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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user