diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-10-04 10:29:30 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-10-04 10:29:30 +0200 |
commit | 9d90e35d51555d9f853f2eccfa771f47d71a6bc1 (patch) | |
tree | afaa271b06215981a137868f652431ef9ab293f7 /tests/xxx_document.rs | |
parent | 3a1fd1918f65c0a751a872d66e2d5bb01c64830c (diff) | |
download | markdown-rs-9d90e35d51555d9f853f2eccfa771f47d71a6bc1.tar.gz markdown-rs-9d90e35d51555d9f853f2eccfa771f47d71a6bc1.tar.bz2 markdown-rs-9d90e35d51555d9f853f2eccfa771f47d71a6bc1.zip |
Refactor to share a test utility
Diffstat (limited to 'tests/xxx_document.rs')
-rw-r--r-- | tests/xxx_document.rs | 30 |
1 files changed, 3 insertions, 27 deletions
diff --git a/tests/xxx_document.rs b/tests/xxx_document.rs index 2d89f16..dcbb56b 100644 --- a/tests/xxx_document.rs +++ b/tests/xxx_document.rs @@ -5,37 +5,13 @@ extern crate swc_ecma_codegen; mod test_utils; use micromark::{micromark_to_mdast, Constructs, Options}; use pretty_assertions::assert_eq; -use swc_common::{sync::Lrc, FilePathMapping, SourceMap}; -use swc_ecma_codegen::{text_writer::JsWriter, Emitter}; use test_utils::{ - swc::{parse_esm, parse_expression}, + swc::{parse_esm, parse_expression, serialize}, to_document::{to_document, Options as DocumentOptions}, to_hast::to_hast, - to_swc::{to_swc, Program}, + to_swc::to_swc, }; -// To do: share with `xxx_swc`. -fn serialize(program: &Program) -> String { - let mut buf = vec![]; - let cm = Lrc::new(SourceMap::new(FilePathMapping::empty())); - // let comm = &program.comments as &dyn swc_common::comments::Comments; - { - let mut emitter = Emitter { - cfg: swc_ecma_codegen::Config { - ..Default::default() - }, - cm: cm.clone(), - // To do: figure out how to pass them. - comments: None, - wr: JsWriter::new(cm, "\n", &mut buf, None), - }; - - emitter.emit_module(&program.module).unwrap(); - } - - String::from_utf8_lossy(&buf).to_string() -} - fn from_markdown(value: &str) -> Result<String, String> { let mdast = micromark_to_mdast( value, @@ -48,7 +24,7 @@ fn from_markdown(value: &str) -> Result<String, String> { )?; let hast = to_hast(&mdast); let program = to_document(to_swc(&hast)?, &DocumentOptions::default())?; - let value = serialize(&program); + let value = serialize(&program.module); Ok(value) } |