Compare table formulas.

This commit is contained in:
Tom Alexander
2023-09-08 23:05:04 -04:00
parent 84d2babda9
commit 80f7098f9b
3 changed files with 42 additions and 4 deletions

View File

@@ -1,3 +1,4 @@
use std::collections::BTreeSet;
use std::collections::HashSet;
use super::util::assert_bounds;
@@ -491,7 +492,7 @@ fn compare_heading<'s>(
if rust.stars.to_string() != level {
this_status = DiffStatus::Bad;
message = Some(format!(
"Headline level do not much (emacs != rust): {} != {}",
"Headline level do not match (emacs != rust): {} != {}",
level, rust.stars
))
}
@@ -1075,9 +1076,43 @@ fn compare_table<'s>(
Ok(_) => {}
};
// TODO: Compare :type :tblfm :value
// Compare formulas
//
// :tblfm is a list () filled with quoted strings containing the value for any tblfm keywords at the end of the table.
// :tblfm is either nil or a list () filled with quoted strings containing the value for any tblfm keywords at the end of the table.
let emacs_formulas = get_property(emacs, ":tblfm")?;
if let Some(emacs_formulas) = emacs_formulas {
let emacs_formulas = emacs_formulas.as_list()?;
if emacs_formulas.len() != rust.formulas.len() {
this_status = DiffStatus::Bad;
message = Some(format!(
"Formulas do not match (emacs != rust): {:?} != {:?}",
emacs_formulas, rust.formulas
))
} else {
let atoms = emacs_formulas
.into_iter()
.map(Token::as_atom)
.collect::<Result<Vec<_>, _>>()?;
let unquoted = atoms
.into_iter()
.map(unquote)
.collect::<Result<BTreeSet<_>, _>>()?;
for kw in &rust.formulas {
if !unquoted.contains(kw.value) {
this_status = DiffStatus::Bad;
message = Some(format!("Could not find formula in emacs: {}", kw.value))
}
}
}
} else {
if !rust.formulas.is_empty() {
this_status = DiffStatus::Bad;
message = Some(format!(
"Formulas do not match (emacs != rust): {:?} != {:?}",
emacs_formulas, rust.formulas
))
}
}
for (emacs_child, rust_child) in children.iter().skip(2).zip(rust.children.iter()) {
child_status.push(compare_table_row(source, emacs_child, rust_child)?);