Outline for the wasm compare function.

This commit is contained in:
Tom Alexander 2023-12-26 18:55:28 -05:00
parent 9a13cb72c6
commit 68ccff74fa
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
6 changed files with 55 additions and 13 deletions

View File

@ -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:

View File

@ -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<dyn std::error::Error>> {
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!()

View File

@ -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;

View File

@ -1 +1,3 @@
mod runner;
pub(crate) use runner::wasm_run_anonymous_compare_with_settings;

View File

@ -1,7 +1,42 @@
// pub async fn run_anonymous_compare_with_settings<'g, 's, P: AsRef<str>>(
// org_contents: P,
// global_settings: &GlobalSettings<'g, 's>,
// silent: bool,
// ) -> Result<bool, Box<dyn std::error::Error>> {
// todo!()
// }
use organic::parser::parse_with_settings;
use organic::settings::GlobalSettings;
pub async fn wasm_run_anonymous_compare_with_settings<'g, 's, P: AsRef<str>>(
org_contents: P,
global_settings: &GlobalSettings<'g, 's>,
silent: bool,
) -> Result<bool, Box<dyn std::error::Error>> {
// 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)
}

View File

@ -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;