compare_properties latex environment.

This commit is contained in:
Tom Alexander 2023-10-10 01:39:47 -04:00
parent 9f166278f4
commit 1a67aac502
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
1 changed files with 31 additions and 20 deletions

View File

@ -2560,33 +2560,44 @@ fn compare_babel_call<'b, 's>(
}
fn compare_latex_environment<'b, 's>(
_source: &'s str,
source: &'s str,
emacs: &'b Token<'s>,
rust: &'b LatexEnvironment<'s>,
) -> Result<DiffEntry<'b, 's>, Box<dyn std::error::Error>> {
let child_status = Vec::new();
let mut this_status = DiffStatus::Good;
let mut child_status = Vec::new();
let mut message = None;
// TODO: Compare :caption
// Compare name
let name = get_property_quoted_string(emacs, ":name")?;
if name.as_ref().map(String::as_str) != rust.name {
this_status = DiffStatus::Bad;
message = Some(format!(
"Name mismatch (emacs != rust) {:?} != {:?}",
name, rust.name
));
}
assert_no_children(emacs, &mut this_status, &mut message)?;
// Compare value
let value = get_property_quoted_string(emacs, ":value")?;
if value.as_ref().map(String::as_str) != Some(rust.value) {
this_status = DiffStatus::Bad;
message = Some(format!(
"Value mismatch (emacs != rust) {:?} != {:?}",
value, rust.value
));
for diff in compare_properties!(
source,
emacs,
rust,
(
EmacsField::Optional(":name"),
|r| r.name,
compare_property_quoted_string
),
(
EmacsField::Optional(":caption"),
compare_identity,
compare_noop
),
(
EmacsField::Required(":value"),
|r| Some(r.value),
compare_property_quoted_string
)
) {
match diff {
ComparePropertiesResult::NoChange => {}
ComparePropertiesResult::SelfChange(new_status, new_message) => {
this_status = new_status;
message = new_message
}
ComparePropertiesResult::DiffEntry(diff_entry) => child_status.push(diff_entry),
}
}
Ok(DiffResult {