Remove dependency on files for running compare.
The tests still use files since they get the test name from a file but compare does the same action via stdin so it can operator on any org source.
This commit is contained in:
27
src/main.rs
27
src/main.rs
@@ -1,5 +1,6 @@
|
||||
#![feature(round_char_boundary)]
|
||||
use std::path::Path;
|
||||
#[cfg(feature = "compare")]
|
||||
use std::io::Read;
|
||||
|
||||
#[cfg(feature = "compare")]
|
||||
use ::organic::parser::document;
|
||||
@@ -36,22 +37,26 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
fn main_body() -> Result<(), Box<dyn std::error::Error>> {
|
||||
run_compare(
|
||||
std::env::args()
|
||||
.nth(1)
|
||||
.ok_or("Pass a single file into this script.")?,
|
||||
)
|
||||
let org_contents = read_stdin_to_string()?;
|
||||
run_compare(org_contents)
|
||||
}
|
||||
|
||||
fn read_stdin_to_string() -> Result<String, Box<dyn std::error::Error>> {
|
||||
let mut stdin_contents = String::new();
|
||||
std::io::stdin()
|
||||
.lock()
|
||||
.read_to_string(&mut stdin_contents)?;
|
||||
Ok(stdin_contents)
|
||||
}
|
||||
|
||||
#[cfg(feature = "compare")]
|
||||
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())?;
|
||||
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())?;
|
||||
fn run_compare<P: AsRef<str>>(org_contents: P) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let (remaining, rust_parsed) = document(org_contents.as_ref()).expect("Org Parse failure");
|
||||
let org_sexp = emacs_parse_org_document(org_contents.as_ref())?;
|
||||
let (_remaining, parsed_sexp) =
|
||||
sexp_with_padding(org_sexp.as_str()).expect("Sexp Parse failure");
|
||||
|
||||
println!("{}\n\n\n", org_contents.as_str());
|
||||
println!("{}\n\n\n", org_contents.as_ref());
|
||||
println!("{}", org_sexp);
|
||||
println!("{:#?}", rust_parsed);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user