Separate out the wasm test into its own feature/binary.

This commit is contained in:
Tom Alexander
2023-12-25 13:10:40 -05:00
parent 67e5829fd9
commit 65abaa332f
8 changed files with 53 additions and 33 deletions

View File

@@ -1,7 +1,10 @@
use serde::Deserialize;
use organic::parser::parse_with_settings;
use organic::settings::GlobalSettings;
use serde::Serialize;
use super::document::WasmDocument;
use super::ToWasm;
use super::ToWasmContext;
#[derive(Debug, Serialize)]
#[serde(tag = "status", content = "content")]
@@ -12,3 +15,18 @@ pub(crate) enum ParseResult<'s> {
#[serde(rename = "error")]
Error(String),
}
pub(crate) fn wasm_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
}