Handle orgifying text in regular link path and raw-link.
This commit is contained in:
@@ -2,7 +2,9 @@ use std::fmt::Debug;
|
||||
|
||||
use super::diff::DiffStatus;
|
||||
use super::sexp::Token;
|
||||
use super::util::get_property;
|
||||
use super::util::get_property_quoted_string;
|
||||
use super::util::get_property_unquoted_atom;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) enum EmacsField<'s> {
|
||||
@@ -32,6 +34,28 @@ pub(crate) fn compare_identity() -> () {
|
||||
()
|
||||
}
|
||||
|
||||
/// Assert that the emacs value is always nil or absent.
|
||||
///
|
||||
/// This is usually used for fields which, in my testing, are always nil. Using this compare function instead of simply doing a compare_noop will enable us to be alerted when we finally come across an org-mode document that has a value other than nil for the property.
|
||||
pub(crate) fn compare_property_always_nil<'b, 's, 'x, R, RG>(
|
||||
emacs: &'b Token<'s>,
|
||||
_rust_node: R,
|
||||
emacs_field: &'x str,
|
||||
_rust_value_getter: RG,
|
||||
) -> Result<Option<(DiffStatus, Option<String>)>, Box<dyn std::error::Error>> {
|
||||
let value = get_property(emacs, emacs_field)?;
|
||||
if value.is_some() {
|
||||
let this_status = DiffStatus::Bad;
|
||||
let message = Some(format!(
|
||||
"{} was expected to always be nil: {:?}",
|
||||
emacs_field, value
|
||||
));
|
||||
Ok(Some((this_status, message)))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn compare_property_quoted_string<'b, 's, 'x, R, RG: Fn(R) -> Option<&'s str>>(
|
||||
emacs: &'b Token<'s>,
|
||||
rust_node: R,
|
||||
@@ -40,7 +64,47 @@ pub(crate) fn compare_property_quoted_string<'b, 's, 'x, R, RG: Fn(R) -> Option<
|
||||
) -> Result<Option<(DiffStatus, Option<String>)>, Box<dyn std::error::Error>> {
|
||||
let value = get_property_quoted_string(emacs, emacs_field)?;
|
||||
let rust_value = rust_value_getter(rust_node);
|
||||
if !rust_value.eq(&value.as_ref().map(String::as_str)) {
|
||||
if rust_value != value.as_ref().map(String::as_str) {
|
||||
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(crate) fn compare_property_quoted_string_owned<'b, 's, 'x, R, RG: Fn(R) -> Option<String>>(
|
||||
emacs: &'b Token<'s>,
|
||||
rust_node: R,
|
||||
emacs_field: &'x str,
|
||||
rust_value_getter: RG,
|
||||
) -> Result<Option<(DiffStatus, Option<String>)>, Box<dyn std::error::Error>> {
|
||||
let value = get_property_quoted_string(emacs, emacs_field)?;
|
||||
let rust_value = rust_value_getter(rust_node);
|
||||
if rust_value != 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(crate) fn compare_property_unquoted_atom<'b, 's, 'x, R, RG: Fn(R) -> Option<&'s str>>(
|
||||
emacs: &'b Token<'s>,
|
||||
rust_node: R,
|
||||
emacs_field: &'x str,
|
||||
rust_value_getter: RG,
|
||||
) -> Result<Option<(DiffStatus, Option<String>)>, Box<dyn std::error::Error>> {
|
||||
let value = get_property_unquoted_atom(emacs, emacs_field)?;
|
||||
let rust_value = rust_value_getter(rust_node);
|
||||
if rust_value != value {
|
||||
let this_status = DiffStatus::Bad;
|
||||
let message = Some(format!(
|
||||
"{} mismatch (emacs != rust) {:?} != {:?}",
|
||||
|
||||
@@ -4,8 +4,10 @@ use std::collections::BTreeSet;
|
||||
use std::collections::HashSet;
|
||||
|
||||
use super::compare_field::compare_identity;
|
||||
use super::compare_field::compare_noop;
|
||||
use super::compare_field::compare_property_always_nil;
|
||||
use super::compare_field::compare_property_quoted_string;
|
||||
use super::compare_field::compare_property_quoted_string_owned;
|
||||
use super::compare_field::compare_property_unquoted_atom;
|
||||
use super::elisp_fact::ElispFact;
|
||||
use super::elisp_fact::GetElispFact;
|
||||
use super::sexp::unquote;
|
||||
@@ -2783,28 +2785,28 @@ fn compare_regular_link<'b, 's>(
|
||||
),
|
||||
(
|
||||
EmacsField::Required(":path"),
|
||||
|r| Some(r.path),
|
||||
compare_property_quoted_string
|
||||
|r| Some(r.get_path()),
|
||||
compare_property_quoted_string_owned
|
||||
),
|
||||
(
|
||||
EmacsField::Required(":format"),
|
||||
compare_identity,
|
||||
compare_noop
|
||||
|_| Some("bracket"),
|
||||
compare_property_unquoted_atom
|
||||
),
|
||||
(
|
||||
EmacsField::Required(":raw-link"),
|
||||
|r| Some(r.raw_link),
|
||||
compare_property_quoted_string
|
||||
|r| Some(r.get_raw_link()),
|
||||
compare_property_quoted_string_owned
|
||||
),
|
||||
(
|
||||
EmacsField::Required(":application"),
|
||||
compare_identity,
|
||||
compare_noop
|
||||
compare_property_always_nil
|
||||
),
|
||||
(
|
||||
EmacsField::Required(":search-option"),
|
||||
compare_identity,
|
||||
compare_noop
|
||||
compare_property_always_nil
|
||||
)
|
||||
)? {
|
||||
this_status = new_status;
|
||||
|
||||
Reference in New Issue
Block a user