Add code to test the wasm code path without actually dropping into wasm.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#![no_main]
|
||||
// #![no_main]
|
||||
|
||||
use organic::parser::parse_with_settings;
|
||||
use organic::settings::GlobalSettings;
|
||||
@@ -12,6 +12,11 @@ mod wasm;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn parse_org(org_contents: &str) -> wasm_bindgen::JsValue {
|
||||
let rust_parsed = impl_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)
|
||||
@@ -23,5 +28,13 @@ pub fn parse_org(org_contents: &str) -> wasm_bindgen::JsValue {
|
||||
Ok(wasm_document) => wasm_document,
|
||||
Err(err) => ParseResult::Error(format!("{:?}", err)),
|
||||
};
|
||||
serde_wasm_bindgen::to_value(&rust_parsed).unwrap()
|
||||
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