Switch to a formatted print of the wasm compare status.
Some checks failed
clippy Build clippy has failed
rust-build Build rust-build has succeeded
rust-foreign-document-test Build rust-foreign-document-test has succeeded
rust-test Build rust-test has succeeded

This commit is contained in:
Tom Alexander 2023-12-27 18:39:10 -05:00
parent d552ef6569
commit 90d4b11922
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
2 changed files with 67 additions and 57 deletions

View File

@ -6,6 +6,8 @@ use crate::compare::get_property_quoted_string;
use crate::compare::ElispFact;
use crate::compare::EmacsField;
use crate::compare::Token;
use crate::util::foreground_color;
use crate::util::reset_color;
use crate::wasm::AdditionalProperties;
use crate::wasm::AdditionalPropertyValue;
use crate::wasm::WasmAstNode;
@ -37,14 +39,6 @@ pub(crate) enum WasmDiffStatus {
}
impl<'s> WasmDiffResult<'s> {
// fn apply(
// &self,
// status: &mut WasmDiffStatus,
// children: &mut Vec<WasmDiffEntry<'s>>,
// ) -> Result<WasmDiffEntry<'s>, Box<dyn std::error::Error>> {
// todo!()
// }
fn extend(
&mut self,
other: WasmDiffResult<'s>,
@ -58,14 +52,72 @@ impl<'s> WasmDiffResult<'s> {
}
pub fn is_bad(&self) -> bool {
todo!()
// self.is_immediately_bad() || self.has_bad_children()
self.is_self_bad() || self.has_bad_children()
}
pub fn is_self_bad(&self) -> bool {
self.status
.iter()
.any(|status| matches!(status, WasmDiffStatus::Bad(_)))
}
pub fn has_bad_children(&self) -> bool {
self.children.iter().any(WasmDiffResult::is_bad)
}
pub fn print(&self, original_document: &str) -> Result<(), Box<dyn std::error::Error>> {
// self.print_indented(0, original_document)
println!("{:#?}", self);
todo!()
self.print_indented(0, original_document)
// println!("{:#?}", self);
// todo!()
}
fn print_indented(
&self,
indentation: usize,
original_document: &str,
) -> Result<(), Box<dyn std::error::Error>> {
let status_text = {
if self.is_bad() {
format!(
"{color}BAD{reset}",
color = foreground_color(255, 0, 0),
reset = reset_color(),
)
} else if self.has_bad_children() {
format!(
"{color}BADCHILD{reset}",
color = foreground_color(255, 255, 0),
reset = reset_color(),
)
} else {
format!(
"{color}GOOD{reset}",
color = foreground_color(0, 255, 0),
reset = reset_color(),
)
}
};
let message = self
.status
.iter()
.filter_map(|status| match status {
WasmDiffStatus::Good => None,
WasmDiffStatus::Bad(message) => Some(message),
})
.next();
println!(
"{indentation}{status_text} {name} {message}",
indentation = " ".repeat(indentation),
status_text = status_text,
name = self.name,
message = message.unwrap_or(&Cow::Borrowed(""))
);
for child in self.children.iter() {
child.print_indented(indentation + 1, original_document)?;
}
Ok(())
}
}
@ -79,49 +131,6 @@ impl<'s> Default for WasmDiffResult<'s> {
}
}
// impl<'s> WasmDiffEntry<'s> {
// // fn has_bad_children(&self) -> bool {
// // match self {
// // DiffEntry::DiffResult(diff) => &diff.children,
// // DiffEntry::DiffLayer(diff) => &diff.children,
// // }
// // .iter()
// // .any(|child| child.is_immediately_bad() || child.has_bad_children())
// // }
// // fn is_immediately_bad(&self) -> bool {
// // match self {
// // DiffEntry::DiffResult(diff) => matches!(diff.status, DiffStatus::Bad),
// // DiffEntry::DiffLayer(_) => false,
// // }
// // }
// pub fn is_bad(&self) -> bool {
// todo!()
// // self.is_immediately_bad() || self.has_bad_children()
// }
// pub fn print(&self, original_document: &str) -> Result<(), Box<dyn std::error::Error>> {
// self.print_indented(0, original_document)
// }
// fn print_indented(
// &self,
// indentation: usize,
// original_document: &str,
// ) -> Result<(), Box<dyn std::error::Error>> {
// todo!()
// // match self {
// // WasmDiffEntry::WasmDiffResult(diff) => {
// // diff.print_indented(indentation, original_document)
// // }
// // WasmDiffEntry::WasmDiffLayer(diff) => {
// // diff.print_indented(indentation, original_document)
// // }
// // }
// }
// }
fn wasm_compare_list<'b, 's: 'b, 'p, EI, WI, WC>(
source: &'s str,
emacs: EI,

View File

@ -6,7 +6,8 @@ macro_rules! wasm_compare {
let emacs_name = emacs_list_iter
.next()
.ok_or("Should have an attributes child.")?
.as_atom()?;
.as_atom()?;
result.name = emacs_name.into();
let emacs_attributes_map = emacs_list_iter
.next()
.ok_or("Should have an attributes child.")?