Unify the standard properties checks in diff.
Instead of copy+pasting them into each compare function, we now call a shared function from a handful of places.
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
use super::elisp_fact::GetElispFact;
|
||||
use super::sexp::Token;
|
||||
use crate::types::GetStandardProperties;
|
||||
use crate::types::StandardProperties;
|
||||
|
||||
/// Check if the child string slice is a slice of the parent string slice.
|
||||
@@ -24,10 +26,24 @@ fn get_rust_byte_offsets<'s, S: StandardProperties<'s> + ?Sized>(
|
||||
(offset, end)
|
||||
}
|
||||
|
||||
pub(crate) fn assert_name<'s>(
|
||||
pub(crate) fn compare_standard_properties<
|
||||
's,
|
||||
S: GetStandardProperties<'s> + GetElispFact<'s> + ?Sized,
|
||||
>(
|
||||
original_document: &'s str,
|
||||
emacs: &'s Token<'s>,
|
||||
name: &str,
|
||||
rust: &'s S,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
assert_name(emacs, rust.get_elisp_fact().get_elisp_name())?;
|
||||
assert_bounds(original_document, emacs, rust.get_standard_properties())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn assert_name<'s, S: AsRef<str>>(
|
||||
emacs: &'s Token<'s>,
|
||||
name: S,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let name = name.as_ref();
|
||||
let children = emacs.as_list()?;
|
||||
let first_child = children
|
||||
.first()
|
||||
@@ -35,7 +51,7 @@ pub(crate) fn assert_name<'s>(
|
||||
.as_atom()?;
|
||||
if first_child != name {
|
||||
Err(format!(
|
||||
"Expected a {expected} cell, but found a {found} cell.",
|
||||
"AST node name mismatch. Expected a (rust) {expected} cell, but found a (emacs) {found} cell.",
|
||||
expected = name,
|
||||
found = first_child
|
||||
))?;
|
||||
|
||||
Reference in New Issue
Block a user