Compare commits

...

4 Commits

Author SHA1 Message Date
Tom Alexander
32d6b3d1ee
Merge branch 'compare_additional_properties'
Some checks failed
rustfmt Build rustfmt has succeeded
rust-build Build rust-build has succeeded
rust-test Build rust-test has succeeded
rust-foreign-document-test Build rust-foreign-document-test has failed
2023-10-10 17:40:40 -04:00
Tom Alexander
7cb71a5a0a
Compare the additional properties on headlines. 2023-10-10 17:40:27 -04:00
Tom Alexander
6b90a9bfa8
Add TODO. 2023-10-10 17:15:51 -04:00
Tom Alexander
83d939bdc0
Update org-mode. 2023-10-10 17:00:13 -04:00
4 changed files with 64 additions and 1 deletions

View File

@ -14,7 +14,7 @@ RUN make DESTDIR="/root/dist" install
FROM build AS build-org-mode
ARG ORG_VERSION=c703541ffcc14965e3567f928de1683a1c1e33f6
ARG ORG_VERSION=f32f5982a76217629dad8b8fd82d53212576aee6
COPY --from=build-emacs /root/dist/ /
RUN mkdir /root/dist
# Savannah does not allow fetching specific revisions, so we're going to have to put unnecessary load on their server by cloning main and then checking out the revision we want.

View File

@ -32,6 +32,26 @@ pub(crate) enum ComparePropertiesResult<'b, 's> {
DiffEntry(DiffEntry<'b, 's>),
}
impl<'b, 's> ComparePropertiesResult<'b, 's> {
pub(crate) fn apply(
self,
child_status: &mut Vec<DiffEntry<'b, 's>>,
this_status: &mut DiffStatus,
message: &mut Option<String>,
) {
match self {
ComparePropertiesResult::NoChange => {}
ComparePropertiesResult::SelfChange(new_status, new_message) => {
*this_status = new_status;
*message = new_message
}
ComparePropertiesResult::DiffEntry(diff_entry) => child_status.push(diff_entry),
}
// foo
}
}
/// Do no comparison.
///
/// This is for when you want to acknowledge that a field exists in the emacs token, but you do not have any validation for it when using the compare_properties!() macro. Ideally, this should be kept to a minimum since this represents untested values.

View File

@ -21,6 +21,7 @@ use super::elisp_fact::GetElispFact;
use super::sexp::unquote;
use super::sexp::Token;
use super::util::assert_no_children;
use super::util::compare_additional_properties;
use super::util::compare_children;
use super::util::compare_children_iter;
use super::util::compare_standard_properties;
@ -542,6 +543,22 @@ fn compare_heading<'b, 's>(
.map(|node_property| format!(":{}", node_property.property_name.to_uppercase()))
.collect();
let additional_properties: Vec<(String, &str)> = rust
.get_additional_properties()
.map(|node_property| {
(
format!(":{}", node_property.property_name.to_uppercase()),
node_property.value.unwrap_or(""),
)
})
.collect();
compare_additional_properties(emacs, additional_properties.into_iter())?.apply(
&mut child_status,
&mut this_status,
&mut message,
);
compare_children(
source,
emacs,

View File

@ -1,5 +1,6 @@
use std::str::FromStr;
use super::compare_field::ComparePropertiesResult;
use super::diff::DiffEntry;
use super::diff::DiffStatus;
use super::elisp_fact::GetElispFact;
@ -311,3 +312,28 @@ pub(crate) fn assert_no_children<'b, 's>(
}
Ok(())
}
pub(crate) fn compare_additional_properties<'b, 's, RK, RV, RI>(
emacs: &'b Token<'s>,
rust_children: RI,
) -> Result<ComparePropertiesResult<'b, 's>, Box<dyn std::error::Error>>
where
RK: AsRef<str>,
RV: AsRef<str>,
RI: Iterator<Item = (RK, RV)> + ExactSizeIterator,
{
for (rust_key, rust_value) in rust_children {
let rust_key = rust_key.as_ref();
let rust_value = rust_value.as_ref();
let emacs_value = get_property_quoted_string(emacs, rust_key)?;
if Some(rust_value) != emacs_value.as_ref().map(String::as_str) {
let this_status = DiffStatus::Bad;
let message = Some(format!(
"{} mismatch (emacs != rust) {:?} != {:?}",
rust_key, emacs_value, rust_value
));
return Ok(ComparePropertiesResult::SelfChange(this_status, message));
}
}
Ok(ComparePropertiesResult::NoChange)
}