Separate out the wasm test into its own feature/binary.
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
// #![no_main]
|
||||
#![no_main]
|
||||
|
||||
use organic::parser::parse_with_settings;
|
||||
use organic::settings::GlobalSettings;
|
||||
use wasm::ParseResult;
|
||||
use wasm::ToWasm;
|
||||
use wasm::ToWasmContext;
|
||||
use wasm::wasm_parse_org;
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
|
||||
mod error;
|
||||
@@ -12,29 +8,6 @@ mod wasm;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn parse_org(org_contents: &str) -> wasm_bindgen::JsValue {
|
||||
let rust_parsed = impl_parse_org(org_contents);
|
||||
let rust_parsed = wasm_parse_org(org_contents);
|
||||
serde_wasm_bindgen::to_value(&rust_parsed).unwrap()
|
||||
}
|
||||
|
||||
fn impl_parse_org(org_contents: &str) -> ParseResult<'_> {
|
||||
let global_settings = GlobalSettings::default();
|
||||
let to_wasm_context = ToWasmContext::new(org_contents);
|
||||
let rust_parsed = match parse_with_settings(org_contents, &global_settings)
|
||||
.map(|document| document.to_wasm(to_wasm_context))
|
||||
.map(|wasm_document| match wasm_document {
|
||||
Ok(wasm_document) => ParseResult::Success(wasm_document),
|
||||
Err(err) => ParseResult::Error(format!("{:?}", err)),
|
||||
}) {
|
||||
Ok(wasm_document) => wasm_document,
|
||||
Err(err) => ParseResult::Error(format!("{:?}", err)),
|
||||
};
|
||||
rust_parsed
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let body = include_str!("/tmp/test.org");
|
||||
let result = impl_parse_org(body);
|
||||
|
||||
println!("{}", serde_json::to_string(&result)?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user