diff --git a/Makefile b/Makefile index 634fa0d..ffd67e9 100644 --- a/Makefile +++ b/Makefile @@ -36,7 +36,7 @@ wasm: .PHONY: run_wasm run_wasm: -> cargo run --profile wasm --bin wasm_test --features wasm_test | jq +> cat /tmp/test.org | cargo run --profile wasm --bin wasm_test --features wasm_test | jq .PHONY: clean clean: diff --git a/src/bin_wasm_test.rs b/src/bin_wasm_test.rs index 25239e0..9db94ec 100644 --- a/src/bin_wasm_test.rs +++ b/src/bin_wasm_test.rs @@ -1,6 +1,7 @@ #![feature(exact_size_is_empty)] use std::io::Read; +use organic::settings::GlobalSettings; use wasm::wasm_parse_org; mod error; @@ -10,6 +11,7 @@ mod wasm; use crate::init_tracing::init_telemetry; #[cfg(feature = "tracing")] use crate::init_tracing::shutdown_telemetry; +use crate::wasm::compare::wasm_run_anonymous_compare_with_settings; #[cfg(feature = "tracing")] mod init_tracing; @@ -40,10 +42,12 @@ async fn main_body() -> Result<(), Box> { let org_contents = read_stdin_to_string()?; let wasm_result = wasm_parse_org(org_contents.as_str()); println!("{}", serde_json::to_string(&wasm_result)?); - // if run_anonymous_compare(org_contents).await? { - // } else { - // Err("Diff results do not match.")?; - // } + if wasm_run_anonymous_compare_with_settings(org_contents, &GlobalSettings::default(), false) + .await? + { + } else { + Err("Diff results do not match.")?; + } Ok(()) } else { todo!() diff --git a/src/compare/mod.rs b/src/compare/mod.rs index 5a2c30e..a19cd3c 100644 --- a/src/compare/mod.rs +++ b/src/compare/mod.rs @@ -7,6 +7,7 @@ mod macros; mod parse; mod sexp; mod util; +pub(crate) use compare::print_versions; pub use compare::run_anonymous_compare; pub use compare::run_anonymous_compare_with_settings; pub use compare::run_compare_on_file; diff --git a/src/wasm/compare/mod.rs b/src/wasm/compare/mod.rs index 1335899..c66863d 100644 --- a/src/wasm/compare/mod.rs +++ b/src/wasm/compare/mod.rs @@ -1 +1,3 @@ mod runner; + +pub(crate) use runner::wasm_run_anonymous_compare_with_settings; diff --git a/src/wasm/compare/runner.rs b/src/wasm/compare/runner.rs index 2989fee..41a0b24 100644 --- a/src/wasm/compare/runner.rs +++ b/src/wasm/compare/runner.rs @@ -1,7 +1,42 @@ -// pub async fn run_anonymous_compare_with_settings<'g, 's, P: AsRef>( -// org_contents: P, -// global_settings: &GlobalSettings<'g, 's>, -// silent: bool, -// ) -> Result> { -// todo!() -// } +use organic::parser::parse_with_settings; +use organic::settings::GlobalSettings; + +pub async fn wasm_run_anonymous_compare_with_settings<'g, 's, P: AsRef>( + org_contents: P, + global_settings: &GlobalSettings<'g, 's>, + silent: bool, +) -> Result> { + // TODO: This is a work-around to pretend that dos line endings do not exist. It would be better to handle the difference in line endings. + let org_contents = org_contents.as_ref().replace("\r\n", "\n"); + let org_contents = org_contents.as_str(); + // if !silent { + // print_versions().await?; + // } + let rust_parsed = parse_with_settings(org_contents, global_settings)?; + // let org_sexp = emacs_parse_anonymous_org_document(org_contents, global_settings).await?; + // let (_remaining, parsed_sexp) = sexp(org_sexp.as_str()).map_err(|e| e.to_string())?; + + if !silent { + println!("{}\n\n\n", org_contents); + // println!("{}", org_sexp); + println!("{:#?}", rust_parsed); + } + + // We do the diffing after printing out both parsed forms in case the diffing panics + // let diff_result = compare_document(&parsed_sexp, &rust_parsed)?; + // 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(), + // ); + // } + + Ok(true) +} diff --git a/src/wasm/mod.rs b/src/wasm/mod.rs index c56a717..f6443db 100644 --- a/src/wasm/mod.rs +++ b/src/wasm/mod.rs @@ -10,7 +10,7 @@ mod code; mod comment; mod comment_block; #[cfg(feature = "wasm_test")] -mod compare; +pub(crate) mod compare; mod diary_sexp; mod document; mod drawer;