From 4bfea412913e3f5597ef079a472a7e7831828460 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Wed, 27 Dec 2023 10:52:59 -0500 Subject: [PATCH] Add more structure to the wasm compare. --- src/wasm_test/compare.rs | 76 +++++++++++++++++++++++++++++++++++++++- src/wasm_test/runner.rs | 24 ++++++------- 2 files changed, 87 insertions(+), 13 deletions(-) diff --git a/src/wasm_test/compare.rs b/src/wasm_test/compare.rs index 392715f..aaca966 100644 --- a/src/wasm_test/compare.rs +++ b/src/wasm_test/compare.rs @@ -1,9 +1,83 @@ +use std::borrow::Cow; + use crate::compare::Token; use crate::wasm::WasmDocument; pub fn wasm_compare_document<'b, 's>( emacs: &'b Token<'s>, wasm: &'b WasmDocument<'s>, -) -> Result<(), Box> { +) -> Result, Box> { todo!() } + +#[derive(Debug)] +pub enum WasmDiffEntry<'b, 's> { + WasmDiffResult(WasmDiffResult<'b, 's>), + WasmDiffLayer(WasmDiffLayer<'b, 's>), +} + +#[derive(Debug)] +pub struct WasmDiffResult<'b, 's> { + status: WasmDiffStatus, + name: Cow<'s, str>, + message: Option, + children: Vec>, + rust_source: &'s str, + #[allow(dead_code)] + emacs_token: &'b Token<'s>, +} + +#[derive(Debug)] +pub(crate) enum WasmDiffStatus { + Good, + Bad, +} + +#[derive(Debug)] +pub struct WasmDiffLayer<'b, 's> { + name: Cow<'s, str>, + children: Vec>, +} + +impl<'b, 's> WasmDiffEntry<'b, '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> { + self.print_indented(0, original_document) + } + + fn print_indented( + &self, + indentation: usize, + original_document: &str, + ) -> Result<(), Box> { + todo!() + // match self { + // WasmDiffEntry::WasmDiffResult(diff) => { + // diff.print_indented(indentation, original_document) + // } + // WasmDiffEntry::WasmDiffLayer(diff) => { + // diff.print_indented(indentation, original_document) + // } + // } + } +} diff --git a/src/wasm_test/runner.rs b/src/wasm_test/runner.rs index 587dd24..f1ce84c 100644 --- a/src/wasm_test/runner.rs +++ b/src/wasm_test/runner.rs @@ -41,19 +41,19 @@ pub async fn wasm_run_anonymous_compare_with_settings<'g, 's, P: AsRef>( // We do the diffing after printing out both parsed forms in case the diffing panics let diff_result = wasm_compare_document(&parsed_sexp, &wasm_parsed)?; - // if !silent { - // diff_result.print(org_contents)?; - // } + if !silent { + diff_result.print(org_contents)?; + } - // if diff_result.is_bad() { - // return Ok(false); - // } else if !silent { - // println!( - // "{color}Entire document passes.{reset}", - // color = DiffResult::foreground_color(0, 255, 0), - // reset = DiffResult::reset_color(), - // ); - // } + if diff_result.is_bad() { + return Ok(false); + } else if !silent { + // println!( + // "{color}Entire document passes.{reset}", + // color = WasmDiffResult::foreground_color(0, 255, 0), + // reset = WasmDiffResult::reset_color(), + // ); + } Ok(true) }