Switch the compiled bin to running a diff just like the automated tests.

This is mostly so I can test a variety of org-mode documents without needing to integrate them into the org samples folder.
This commit is contained in:
Tom Alexander 2023-08-10 18:46:19 -04:00
parent 6941825e75
commit 66c71e7e40
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
1 changed files with 39 additions and 5 deletions

View File

@ -1,17 +1,51 @@
#![feature(round_char_boundary)]
use std::path::Path;
use ::organic::parser::document;
use organic::compare_document;
use organic::emacs_parse_org_document;
use organic::parser::sexp::sexp_with_padding;
use crate::init_tracing::init_telemetry;
use crate::init_tracing::shutdown_telemetry;
mod init_tracing;
const TEST_DOC: &'static str = include_str!("../toy_language.txt");
fn main() -> Result<(), Box<dyn std::error::Error>> {
init_telemetry()?;
let parsed = document(TEST_DOC);
println!("{}\n\n\n", TEST_DOC);
println!("{:#?}", parsed);
run_compare(
std::env::args()
.nth(1)
.expect("Pass a single file into this script."),
)?;
shutdown_telemetry()?;
Ok(())
}
fn run_compare<P: AsRef<Path>>(todo_org_path: P) -> Result<(), Box<dyn std::error::Error>> {
let org_contents = std::fs::read_to_string(todo_org_path.as_ref()).expect("Read org file.");
let (remaining, rust_parsed) = document(org_contents.as_str()).expect("Org Parse failure");
let org_sexp =
emacs_parse_org_document(todo_org_path.as_ref()).expect("Use emacs to parse org file.");
let (_remaining, parsed_sexp) =
sexp_with_padding(org_sexp.as_str()).expect("Sexp Parse failure");
println!("{}\n\n\n", org_contents.as_str());
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).expect("Compare parsed documents.");
diff_result
.print()
.expect("Print document parse tree diff.");
if diff_result.is_bad() {
Err("Diff results do not match.")?;
}
if remaining != "" {
Err(format!("There was unparsed text remaining: {}", remaining))?;
}
Ok(())
}