organic/src/compare/compare_field.rs

28 lines
826 B
Rust
Raw Normal View History

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)
}
}