aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-10-11 16:27:38 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-10-11 16:27:38 +0200
commite484d1ecc5e405259767c0fd84072226fee40b71 (patch)
tree71d2a2f67870052aa026d0087dfb06cb96c40e17 /tests
parent73d8609565b808ac73df5ac34e6d4f7f23c25ad6 (diff)
downloadmarkdown-rs-e484d1ecc5e405259767c0fd84072226fee40b71.tar.gz
markdown-rs-e484d1ecc5e405259767c0fd84072226fee40b71.tar.bz2
markdown-rs-e484d1ecc5e405259767c0fd84072226fee40b71.zip
Refactor test utilities to improve names
Diffstat (limited to 'tests')
-rw-r--r--tests/test_utils/hast.rs7
-rw-r--r--tests/test_utils/hast_util_to_swc.rs (renamed from tests/test_utils/to_swc.rs)33
-rw-r--r--tests/test_utils/mdast_util_to_hast.rs (renamed from tests/test_utils/to_hast.rs)30
-rw-r--r--tests/test_utils/mdx_plugin_recma_document.rs (renamed from tests/test_utils/to_document.rs)11
-rw-r--r--tests/test_utils/mdx_plugin_recma_jsx_rewrite.rs (renamed from tests/test_utils/jsx_rewrite.rs)11
-rw-r--r--tests/test_utils/micromark_swc_utils.rs134
-rw-r--r--tests/test_utils/mod.rs9
-rw-r--r--tests/test_utils/swc.rs5
-rw-r--r--tests/test_utils/swc_utils.rs138
-rw-r--r--tests/xxx_hast_util_to_swc.rs (renamed from tests/xxx_swc.rs)48
-rw-r--r--tests/xxx_mdast_util_to_hast.rs (renamed from tests/xxx_hast.rs)86
-rw-r--r--tests/xxx_mdx_plugin_recma_document.rs (renamed from tests/xxx_document.rs)14
-rw-r--r--tests/xxx_mdx_plugin_recma_jsx_rewrite.rs (renamed from tests/xxx_jsx_rewrite.rs)18
13 files changed, 304 insertions, 240 deletions
diff --git a/tests/test_utils/hast.rs b/tests/test_utils/hast.rs
index db5326c..bc8f472 100644
--- a/tests/test_utils/hast.rs
+++ b/tests/test_utils/hast.rs
@@ -1,6 +1,9 @@
-#![allow(dead_code)]
+//! HTML syntax tree: [hast][].
+//!
+//! [hast]: https://github.com/syntax-tree/hast
-// ^-- To do: fix later
+#![allow(dead_code)]
+// ^-- To do: externalize.
extern crate alloc;
extern crate micromark;
diff --git a/tests/test_utils/to_swc.rs b/tests/test_utils/hast_util_to_swc.rs
index 02de514..a4bb9b9 100644
--- a/tests/test_utils/to_swc.rs
+++ b/tests/test_utils/hast_util_to_swc.rs
@@ -1,10 +1,37 @@
+//! Turn an HTML AST into a JavaScript AST.
+//!
+//! Port of <https://github.com/syntax-tree/hast-util-to-estree>, by the same
+//! author:
+//!
+//! (The MIT License)
+//!
+//! Copyright (c) 2016 Titus Wormer <tituswormer@gmail.com>
+//!
+//! Permission is hereby granted, free of charge, to any person obtaining
+//! a copy of this software and associated documentation files (the
+//! 'Software'), to deal in the Software without restriction, including
+//! without limitation the rights to use, copy, modify, merge, publish,
+//! distribute, sublicense, and/or sell copies of the Software, and to
+//! permit persons to whom the Software is furnished to do so, subject to
+//! the following conditions:
+//!
+//! The above copyright notice and this permission notice shall be
+//! included in all copies or substantial portions of the Software.
+//!
+//! THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+//! EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+//! MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+//! IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+//! CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+//! TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+//! SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
extern crate swc_common;
extern crate swc_ecma_ast;
use crate::test_utils::{
hast,
- micromark_swc_utils::position_to_span,
swc::{parse_esm_to_tree, parse_expression_to_tree},
- swc_utils::create_ident,
+ swc_utils::{create_ident, position_to_span},
};
use core::str;
use micromark::{Location, MdxExpressionKind};
@@ -41,7 +68,7 @@ struct Context<'a> {
}
#[allow(dead_code)]
-pub fn to_swc(
+pub fn hast_util_to_swc(
tree: &hast::Node,
path: Option<String>,
location: Option<&Location>,
diff --git a/tests/test_utils/to_hast.rs b/tests/test_utils/mdast_util_to_hast.rs
index 1ba8d35..c07d15b 100644
--- a/tests/test_utils/to_hast.rs
+++ b/tests/test_utils/mdast_util_to_hast.rs
@@ -1,3 +1,31 @@
+//! Turn a markdown AST into an HTML AST.
+//!
+//! Port of <https://github.com/syntax-tree/mdast-util-to-hast>, by the same
+//! author:
+//!
+//! (The MIT License)
+//!
+//! Copyright (c) 2016 Titus Wormer <tituswormer@gmail.com>
+//!
+//! Permission is hereby granted, free of charge, to any person obtaining
+//! a copy of this software and associated documentation files (the
+//! 'Software'), to deal in the Software without restriction, including
+//! without limitation the rights to use, copy, modify, merge, publish,
+//! distribute, sublicense, and/or sell copies of the Software, and to
+//! permit persons to whom the Software is furnished to do so, subject to
+//! the following conditions:
+//!
+//! The above copyright notice and this permission notice shall be
+//! included in all copies or substantial portions of the Software.
+//!
+//! THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+//! EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+//! MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+//! IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+//! CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+//! TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+//! SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
use crate::test_utils::hast;
use micromark::{mdast, sanitize, unist::Position};
@@ -34,7 +62,7 @@ enum Result {
}
#[allow(dead_code)]
-pub fn to_hast(mdast: &mdast::Node) -> hast::Node {
+pub fn mdast_util_to_hast(mdast: &mdast::Node) -> hast::Node {
let mut definitions = vec![];
// Collect definitions.
diff --git a/tests/test_utils/to_document.rs b/tests/test_utils/mdx_plugin_recma_document.rs
index 938df1b..a62862c 100644
--- a/tests/test_utils/to_document.rs
+++ b/tests/test_utils/mdx_plugin_recma_document.rs
@@ -1,7 +1,12 @@
+//! Turn a JavaScript AST, coming from MD(X), into a component.
+//!
+//! Port of <https://github.com/mdx-js/mdx/blob/main/packages/mdx/lib/plugin/recma-document.js>,
+//! by the same author.
+
extern crate swc_ecma_ast;
use crate::test_utils::{
- micromark_swc_utils::{bytepos_to_point, prefix_error_with_point, span_to_position},
- to_swc::Program,
+ hast_util_to_swc::Program,
+ swc_utils::{bytepos_to_point, prefix_error_with_point, span_to_position},
};
use micromark::{
unist::{Point, Position},
@@ -66,7 +71,7 @@ impl Default for Options {
}
#[allow(dead_code)]
-pub fn to_document(
+pub fn mdx_plugin_recma_document(
mut program: Program,
options: &Options,
location: Option<&Location>,
diff --git a/tests/test_utils/jsx_rewrite.rs b/tests/test_utils/mdx_plugin_recma_jsx_rewrite.rs
index 33879b0..6a4d451 100644
--- a/tests/test_utils/jsx_rewrite.rs
+++ b/tests/test_utils/mdx_plugin_recma_jsx_rewrite.rs
@@ -1,11 +1,16 @@
+//! Rewrite JSX tags to accept them from props and an optional provider.
+//!
+//! Port of <https://github.com/mdx-js/mdx/blob/main/packages/mdx/lib/plugin/recma-jsx-rewrite.js>,
+//! by the same author.
+
extern crate swc_common;
extern crate swc_ecma_ast;
use crate::test_utils::{
- micromark_swc_utils::{position_to_string, span_to_position},
+ hast_util_to_swc::Program,
swc_utils::{
create_binary_expression, create_ident, create_ident_expression, create_member_expression,
+ position_to_string, span_to_position,
},
- to_swc::Program,
};
use micromark::{id_cont, id_start, unist::Position, Location};
use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith};
@@ -25,7 +30,7 @@ pub struct Options {
/// Rewrite JSX in an MDX file so that components can be passed in and provided.
#[allow(dead_code)]
-pub fn jsx_rewrite(
+pub fn mdx_plugin_recma_jsx_rewrite(
mut program: Program,
options: &Options,
location: Option<&Location>,
diff --git a/tests/test_utils/micromark_swc_utils.rs b/tests/test_utils/micromark_swc_utils.rs
deleted file mode 100644
index 13678d5..0000000
--- a/tests/test_utils/micromark_swc_utils.rs
+++ /dev/null
@@ -1,134 +0,0 @@
-extern crate swc_common;
-use micromark::{
- mdast::Stop,
- unist::{Point, Position},
- Location,
-};
-use swc_common::{BytePos, Span, SyntaxContext, DUMMY_SP};
-use swc_ecma_visit::{noop_visit_mut_type, VisitMut};
-
-/// Turn a unist position, into an SWC span, of two byte positions.
-///
-/// > 👉 **Note**: SWC byte positions are offset by one: they are `0` when they
-/// > are missing or incremented by `1` when valid.
-pub fn position_to_span(position: Option<&Position>) -> Span {
- position.map_or(DUMMY_SP, |d| Span {
- lo: point_to_bytepos(&d.start),
- hi: point_to_bytepos(&d.end),
- ctxt: SyntaxContext::empty(),
- })
-}
-
-/// Turn an SWC span, of two byte positions, into a unist position.
-///
-/// This assumes the span comes from a fixed tree, or is a dummy.
-///
-/// > 👉 **Note**: SWC byte positions are offset by one: they are `0` when they
-/// > are missing or incremented by `1` when valid.
-pub fn span_to_position(span: &Span, location: Option<&Location>) -> Option<Position> {
- let lo = span.lo.0 as usize;
- let hi = span.hi.0 as usize;
-
- if lo > 0 && hi > 0 {
- if let Some(location) = location {
- if let Some(start) = location.to_point(lo - 1) {
- if let Some(end) = location.to_point(hi - 1) {
- return Some(Position { start, end });
- }
- }
- }
- }
-
- None
-}
-
-/// Turn a unist point into an SWC byte position.
-///
-/// > 👉 **Note**: SWC byte positions are offset by one: they are `0` when they
-/// > are missing or incremented by `1` when valid.
-pub fn point_to_bytepos(point: &Point) -> BytePos {
- BytePos(point.offset as u32 + 1)
-}
-
-/// Turn an SWC byte position into a unist point.
-///
-/// This assumes the byte position comes from a fixed tree, or is a dummy.
-///
-/// > 👉 **Note**: SWC byte positions are offset by one: they are `0` when they
-/// > are missing or incremented by `1` when valid.
-pub fn bytepos_to_point(bytepos: &BytePos, location: Option<&Location>) -> Option<Point> {
- let pos = bytepos.0 as usize;
-
- if pos > 0 {
- if let Some(location) = location {
- return location.to_point(pos - 1);
- }
- }
-
- None
-}
-
-/// Prefix an error message with an optional point.
-pub fn prefix_error_with_point(reason: String, point: Option<&Point>) -> String {
- if let Some(point) = point {
- format!("{}: {}", point_to_string(point), reason)
- } else {
- reason
- }
-}
-
-/// Serialize a unist position for humans.
-pub fn position_to_string(position: &Position) -> String {
- format!(
- "{}-{}",
- point_to_string(&position.start),
- point_to_string(&position.end)
- )
-}
-
-/// Serialize a unist point for humans.
-pub fn point_to_string(point: &Point) -> String {
- format!("{}:{}", point.line, point.column)
-}
-
-/// Visitor to fix SWC byte positions.
-///
-/// This assumes the byte position comes from an **unfixed** tree.
-///
-/// > 👉 **Note**: SWC byte positions are offset by one: they are `0` when they
-/// > are missing or incremented by `1` when valid.
-#[derive(Debug, Default, Clone)]
-pub struct RewriteContext<'a> {
- pub prefix_len: usize,
- pub stops: &'a [Stop],
- pub location: Option<&'a Location>,
-}
-
-impl<'a> VisitMut for RewriteContext<'a> {
- noop_visit_mut_type!();
-
- // Rewrite spans.
- fn visit_mut_span(&mut self, span: &mut Span) {
- let mut result = DUMMY_SP;
- let lo_rel = span.lo.0 as usize;
- let hi_rel = span.hi.0 as usize;
-
- if lo_rel > self.prefix_len && hi_rel > self.prefix_len {
- if let Some(lo_abs) =
- Location::relative_to_absolute(self.stops, lo_rel - 1 - self.prefix_len)
- {
- if let Some(hi_abs) =
- Location::relative_to_absolute(self.stops, hi_rel - 1 - self.prefix_len)
- {
- result = Span {
- lo: BytePos(lo_abs as u32 + 1),
- hi: BytePos(hi_abs as u32 + 1),
- ctxt: SyntaxContext::empty(),
- };
- }
- }
- }
-
- *span = result;
- }
-}
diff --git a/tests/test_utils/mod.rs b/tests/test_utils/mod.rs
index 99ded2f..8d1f144 100644
--- a/tests/test_utils/mod.rs
+++ b/tests/test_utils/mod.rs
@@ -1,8 +1,7 @@
pub mod hast;
-pub mod jsx_rewrite;
-pub mod micromark_swc_utils;
+pub mod hast_util_to_swc;
+pub mod mdast_util_to_hast;
+pub mod mdx_plugin_recma_document;
+pub mod mdx_plugin_recma_jsx_rewrite;
pub mod swc;
pub mod swc_utils;
-pub mod to_document;
-pub mod to_hast;
-pub mod to_swc;
diff --git a/tests/test_utils/swc.rs b/tests/test_utils/swc.rs
index 7e44898..3c97d28 100644
--- a/tests/test_utils/swc.rs
+++ b/tests/test_utils/swc.rs
@@ -1,10 +1,9 @@
+//! Bridge between `micromark` and SWC.
extern crate micromark;
extern crate swc_common;
extern crate swc_ecma_ast;
extern crate swc_ecma_parser;
-use crate::test_utils::micromark_swc_utils::{
- bytepos_to_point, prefix_error_with_point, RewriteContext,
-};
+use crate::test_utils::swc_utils::{bytepos_to_point, prefix_error_with_point, RewriteContext};
use micromark::{mdast::Stop, unist::Point, Location, MdxExpressionKind, MdxSignal};
use swc_common::{
source_map::Pos, sync::Lrc, BytePos, FileName, FilePathMapping, SourceFile, SourceMap, Spanned,
diff --git a/tests/test_utils/swc_utils.rs b/tests/test_utils/swc_utils.rs
index 1e1a526..5a45af6 100644
--- a/tests/test_utils/swc_utils.rs
+++ b/tests/test_utils/swc_utils.rs
@@ -1,8 +1,140 @@
-extern crate swc_common;
-extern crate swc_ecma_ast;
+//! Lots of helpers for dealing with SWC, particularly from unist.
-use swc_common::DUMMY_SP;
+use micromark::{
+ mdast::Stop,
+ unist::{Point, Position},
+ Location,
+};
+
+use swc_common::{BytePos, Span, SyntaxContext, DUMMY_SP};
use swc_ecma_ast::{BinExpr, BinaryOp, Expr, Ident, MemberExpr, MemberProp};
+use swc_ecma_visit::{noop_visit_mut_type, VisitMut};
+
+/// Turn a unist position, into an SWC span, of two byte positions.
+///
+/// > 👉 **Note**: SWC byte positions are offset by one: they are `0` when they
+/// > are missing or incremented by `1` when valid.
+pub fn position_to_span(position: Option<&Position>) -> Span {
+ position.map_or(DUMMY_SP, |d| Span {
+ lo: point_to_bytepos(&d.start),
+ hi: point_to_bytepos(&d.end),
+ ctxt: SyntaxContext::empty(),
+ })
+}
+
+/// Turn an SWC span, of two byte positions, into a unist position.
+///
+/// This assumes the span comes from a fixed tree, or is a dummy.
+///
+/// > 👉 **Note**: SWC byte positions are offset by one: they are `0` when they
+/// > are missing or incremented by `1` when valid.
+pub fn span_to_position(span: &Span, location: Option<&Location>) -> Option<Position> {
+ let lo = span.lo.0 as usize;
+ let hi = span.hi.0 as usize;
+
+ if lo > 0 && hi > 0 {
+ if let Some(location) = location {
+ if let Some(start) = location.to_point(lo - 1) {
+ if let Some(end) = location.to_point(hi - 1) {
+ return Some(Position { start, end });
+ }
+ }
+ }
+ }
+
+ None
+}
+
+/// Turn a unist point into an SWC byte position.
+///
+/// > 👉 **Note**: SWC byte positions are offset by one: they are `0` when they
+/// > are missing or incremented by `1` when valid.
+pub fn point_to_bytepos(point: &Point) -> BytePos {
+ BytePos(point.offset as u32 + 1)
+}
+
+/// Turn an SWC byte position into a unist point.
+///
+/// This assumes the byte position comes from a fixed tree, or is a dummy.
+///
+/// > 👉 **Note**: SWC byte positions are offset by one: they are `0` when they
+/// > are missing or incremented by `1` when valid.
+pub fn bytepos_to_point(bytepos: &BytePos, location: Option<&Location>) -> Option<Point> {
+ let pos = bytepos.0 as usize;
+
+ if pos > 0 {
+ if let Some(location) = location {
+ return location.to_point(pos - 1);
+ }
+ }
+
+ None
+}
+
+/// Prefix an error message with an optional point.
+pub fn prefix_error_with_point(reason: String, point: Option<&Point>) -> String {
+ if let Some(point) = point {
+ format!("{}: {}", point_to_string(point), reason)
+ } else {
+ reason
+ }
+}
+
+/// Serialize a unist position for humans.
+pub fn position_to_string(position: &Position) -> String {
+ format!(
+ "{}-{}",
+ point_to_string(&position.start),
+ point_to_string(&position.end)
+ )
+}
+
+/// Serialize a unist point for humans.
+pub fn point_to_string(point: &Point) -> String {
+ format!("{}:{}", point.line, point.column)
+}
+
+/// Visitor to fix SWC byte positions.
+///
+/// This assumes the byte position comes from an **unfixed** tree.
+///
+/// > 👉 **Note**: SWC byte positions are offset by one: they are `0` when they
+/// > are missing or incremented by `1` when valid.
+#[derive(Debug, Default, Clone)]
+pub struct RewriteContext<'a> {
+ pub prefix_len: usize,
+ pub stops: &'a [Stop],
+ pub location: Option<&'a Location>,
+}
+
+impl<'a> VisitMut for RewriteContext<'a> {
+ noop_visit_mut_type!();
+
+ // Rewrite spans.
+ fn visit_mut_span(&mut self, span: &mut Span) {
+ let mut result = DUMMY_SP;
+ let lo_rel = span.lo.0 as usize;
+ let hi_rel = span.hi.0 as usize;
+
+ if lo_rel > self.prefix_len && hi_rel > self.prefix_len {
+ if let Some(lo_abs) =
+ Location::relative_to_absolute(self.stops, lo_rel - 1 - self.prefix_len)
+ {
+ if let Some(hi_abs) =
+ Location::relative_to_absolute(self.stops, hi_rel - 1 - self.prefix_len)
+ {
+ result = Span {
+ lo: BytePos(lo_abs as u32 + 1),
+ hi: BytePos(hi_abs as u32 + 1),
+ ctxt: SyntaxContext::empty(),
+ };
+ }
+ }
+ }
+
+ *span = result;
+ }
+}
/// Generate an ident.
///
diff --git a/tests/xxx_swc.rs b/tests/xxx_hast_util_to_swc.rs
index 68a141d..a169811 100644
--- a/tests/xxx_swc.rs
+++ b/tests/xxx_hast_util_to_swc.rs
@@ -6,13 +6,13 @@ mod test_utils;
use pretty_assertions::assert_eq;
use test_utils::{
hast,
+ hast_util_to_swc::{hast_util_to_swc, Program},
swc::serialize,
- to_swc::{to_swc, Program},
};
#[test]
-fn swc() -> Result<(), String> {
- let comment_ast = to_swc(
+fn hast_util_to_swc_test() -> Result<(), String> {
+ let comment_ast = hast_util_to_swc(
&hast::Node::Comment(hast::Comment {
value: "a".into(),
position: None,
@@ -71,7 +71,7 @@ fn swc() -> Result<(), String> {
"should support a `Comment` (serialize)",
);
- let element_ast = to_swc(
+ let element_ast = hast_util_to_swc(
&hast::Node::Element(hast::Element {
tag_name: "a".into(),
properties: vec![(
@@ -149,7 +149,7 @@ fn swc() -> Result<(), String> {
assert_eq!(
serialize(
- &to_swc(
+ &hast_util_to_swc(
&hast::Node::Element(hast::Element {
tag_name: "a".into(),
properties: vec![],
@@ -170,7 +170,7 @@ fn swc() -> Result<(), String> {
assert_eq!(
serialize(
- &to_swc(
+ &hast_util_to_swc(
&hast::Node::Element(hast::Element {
tag_name: "a".into(),
properties: vec![("b".into(), hast::PropertyValue::String("c".into()),)],
@@ -188,7 +188,7 @@ fn swc() -> Result<(), String> {
assert_eq!(
serialize(
- &to_swc(
+ &hast_util_to_swc(
&hast::Node::Element(hast::Element {
tag_name: "a".into(),
properties: vec![("b".into(), hast::PropertyValue::Boolean(true),)],
@@ -206,7 +206,7 @@ fn swc() -> Result<(), String> {
assert_eq!(
serialize(
- &to_swc(
+ &hast_util_to_swc(
&hast::Node::Element(hast::Element {
tag_name: "a".into(),
properties: vec![("b".into(), hast::PropertyValue::Boolean(false),)],
@@ -224,7 +224,7 @@ fn swc() -> Result<(), String> {
assert_eq!(
serialize(
- &to_swc(
+ &hast_util_to_swc(
&hast::Node::Element(hast::Element {
tag_name: "a".into(),
properties: vec![(
@@ -245,7 +245,7 @@ fn swc() -> Result<(), String> {
assert_eq!(
serialize(
- &to_swc(
+ &hast_util_to_swc(
&hast::Node::Element(hast::Element {
tag_name: "a".into(),
properties: vec![
@@ -267,7 +267,7 @@ fn swc() -> Result<(), String> {
assert_eq!(
serialize(
- &to_swc(
+ &hast_util_to_swc(
&hast::Node::Element(hast::Element {
tag_name: "a".into(),
properties: vec![
@@ -287,7 +287,7 @@ fn swc() -> Result<(), String> {
"should support an `Element` w/ aria attributes",
);
- let mdx_element_ast = to_swc(
+ let mdx_element_ast = hast_util_to_swc(
&hast::Node::MdxJsxElement(hast::MdxJsxElement {
name: None,
attributes: vec![],
@@ -336,7 +336,7 @@ fn swc() -> Result<(), String> {
assert_eq!(
serialize(
- &to_swc(
+ &hast_util_to_swc(
&hast::Node::MdxJsxElement(hast::MdxJsxElement {
name: Some("a".into()),
attributes: vec![],
@@ -354,7 +354,7 @@ fn swc() -> Result<(), String> {
assert_eq!(
serialize(
- &to_swc(
+ &hast_util_to_swc(
&hast::Node::MdxJsxElement(hast::MdxJsxElement {
name: Some("a:b".into()),
attributes: vec![],
@@ -372,7 +372,7 @@ fn swc() -> Result<(), String> {
assert_eq!(
serialize(
- &to_swc(
+ &hast_util_to_swc(
&hast::Node::MdxJsxElement(hast::MdxJsxElement {
name: Some("a.b.c".into()),
attributes: vec![],
@@ -390,7 +390,7 @@ fn swc() -> Result<(), String> {
assert_eq!(
serialize(
- &to_swc(
+ &hast_util_to_swc(
&hast::Node::MdxJsxElement(hast::MdxJsxElement {
name: Some("a".into()),
attributes: vec![],
@@ -411,7 +411,7 @@ fn swc() -> Result<(), String> {
assert_eq!(
serialize(
- &to_swc(
+ &hast_util_to_swc(
&hast::Node::MdxJsxElement(hast::MdxJsxElement {
name: Some("a".into()),
attributes: vec![hast::AttributeContent::Property(hast::MdxJsxAttribute {
@@ -432,7 +432,7 @@ fn swc() -> Result<(), String> {
assert_eq!(
serialize(
- &to_swc(
+ &hast_util_to_swc(
&hast::Node::MdxJsxElement(hast::MdxJsxElement {
name: Some("a".into()),
attributes: vec![hast::AttributeContent::Property(hast::MdxJsxAttribute {
@@ -453,7 +453,7 @@ fn swc() -> Result<(), String> {
assert_eq!(
serialize(
- &to_swc(
+ &hast_util_to_swc(
&hast::Node::MdxJsxElement(hast::MdxJsxElement {
name: Some("a".into()),
attributes: vec![hast::AttributeContent::Property(hast::MdxJsxAttribute {
@@ -474,7 +474,7 @@ fn swc() -> Result<(), String> {
assert_eq!(
serialize(
- &to_swc(
+ &hast_util_to_swc(
&hast::Node::MdxJsxElement(hast::MdxJsxElement {
name: Some("a".into()),
attributes: vec![hast::AttributeContent::Expression("...c".into(), vec![])],
@@ -490,7 +490,7 @@ fn swc() -> Result<(), String> {
"should support an `MdxElement` (element, expression attribute)",
);
- let mdx_expression_ast = to_swc(
+ let mdx_expression_ast = hast_util_to_swc(
&hast::Node::MdxExpression(hast::MdxExpression {
value: "a".into(),
position: None,
@@ -547,7 +547,7 @@ fn swc() -> Result<(), String> {
"should support an `MdxExpression` (serialize)",
);
- let mdxjs_esm_ast = to_swc(
+ let mdxjs_esm_ast = hast_util_to_swc(
&hast::Node::MdxjsEsm(hast::MdxjsEsm {
value: "import a from 'b'".into(),
position: None,
@@ -598,7 +598,7 @@ fn swc() -> Result<(), String> {
"should support an `MdxjsEsm` (serialize)",
);
- let root_ast = to_swc(
+ let root_ast = hast_util_to_swc(
&hast::Node::Root(hast::Root {
children: vec![hast::Node::Text(hast::Text {
value: "a".into(),
@@ -659,7 +659,7 @@ fn swc() -> Result<(), String> {
"should support a `Root` (serialize)",
);
- let text_ast = to_swc(
+ let text_ast = hast_util_to_swc(
&hast::Node::Text(hast::Text {
value: "a".into(),
position: None,
diff --git a/tests/xxx_hast.rs b/tests/xxx_mdast_util_to_hast.rs
index b0856a2..f46f980 100644
--- a/tests/xxx_hast.rs
+++ b/tests/xxx_mdast_util_to_hast.rs
@@ -2,12 +2,12 @@ extern crate micromark;
mod test_utils;
use micromark::mdast;
use pretty_assertions::assert_eq;
-use test_utils::{hast, to_hast::to_hast};
+use test_utils::{hast, mdast_util_to_hast::mdast_util_to_hast};
#[test]
-fn hast() {
+fn mdast_util_to_hast_test() {
assert_eq!(
- to_hast(&mdast::Node::BlockQuote(mdast::BlockQuote {
+ mdast_util_to_hast(&mdast::Node::BlockQuote(mdast::BlockQuote {
children: vec![],
position: None,
})),
@@ -24,7 +24,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::Break(mdast::Break { position: None })),
+ mdast_util_to_hast(&mdast::Node::Break(mdast::Break { position: None })),
hast::Node::Root(hast::Root {
children: vec![
hast::Node::Element(hast::Element {
@@ -44,7 +44,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::Code(mdast::Code {
+ mdast_util_to_hast(&mdast::Node::Code(mdast::Code {
lang: Some("b".into()),
meta: None,
value: "a".into(),
@@ -71,7 +71,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::Definition(mdast::Definition {
+ mdast_util_to_hast(&mdast::Node::Definition(mdast::Definition {
url: "b".into(),
title: None,
identifier: "a".into(),
@@ -86,7 +86,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::Delete(mdast::Delete {
+ mdast_util_to_hast(&mdast::Node::Delete(mdast::Delete {
children: vec![mdast::Node::Text(mdast::Text {
value: "a".into(),
position: None
@@ -106,7 +106,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::Emphasis(mdast::Emphasis {
+ mdast_util_to_hast(&mdast::Node::Emphasis(mdast::Emphasis {
children: vec![mdast::Node::Text(mdast::Text {
value: "a".into(),
position: None
@@ -126,7 +126,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::FootnoteDefinition(
+ mdast_util_to_hast(&mdast::Node::FootnoteDefinition(
mdast::FootnoteDefinition {
identifier: "a".into(),
label: None,
@@ -142,7 +142,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::Root(mdast::Root {
+ mdast_util_to_hast(&mdast::Node::Root(mdast::Root {
children: vec![
mdast::Node::FootnoteDefinition(mdast::FootnoteDefinition {
children: vec![mdast::Node::Paragraph(mdast::Paragraph {
@@ -328,7 +328,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::Root(mdast::Root {
+ mdast_util_to_hast(&mdast::Node::Root(mdast::Root {
children: vec![
mdast::Node::FootnoteDefinition(mdast::FootnoteDefinition {
children: vec![mdast::Node::Paragraph(mdast::Paragraph {
@@ -594,7 +594,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::Heading(mdast::Heading {
+ mdast_util_to_hast(&mdast::Node::Heading(mdast::Heading {
depth: 1,
children: vec![mdast::Node::Text(mdast::Text {
value: "a".into(),
@@ -615,7 +615,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::Html(mdast::Html {
+ mdast_util_to_hast(&mdast::Node::Html(mdast::Html {
value: "<div>".into(),
position: None,
})),
@@ -627,7 +627,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::Image(mdast::Image {
+ mdast_util_to_hast(&mdast::Node::Image(mdast::Image {
url: "a".into(),
alt: "b".into(),
title: None,
@@ -646,7 +646,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::Root(mdast::Root {
+ mdast_util_to_hast(&mdast::Node::Root(mdast::Root {
children: vec![
mdast::Node::Definition(mdast::Definition {
url: "b".into(),
@@ -689,7 +689,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::InlineCode(mdast::InlineCode {
+ mdast_util_to_hast(&mdast::Node::InlineCode(mdast::InlineCode {
value: "a\nb".into(),
position: None,
})),
@@ -706,7 +706,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::InlineMath(mdast::InlineMath {
+ mdast_util_to_hast(&mdast::Node::InlineMath(mdast::InlineMath {
value: "a\nb".into(),
position: None,
})),
@@ -729,7 +729,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::Link(mdast::Link {
+ mdast_util_to_hast(&mdast::Node::Link(mdast::Link {
url: "a".into(),
title: None,
children: vec![mdast::Node::Text(mdast::Text {
@@ -751,7 +751,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::Root(mdast::Root {
+ mdast_util_to_hast(&mdast::Node::Root(mdast::Root {
children: vec![
mdast::Node::Definition(mdast::Definition {
url: "b".into(),
@@ -797,7 +797,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::Root(mdast::Root {
+ mdast_util_to_hast(&mdast::Node::Root(mdast::Root {
children: vec![mdast::Node::ListItem(mdast::ListItem {
spread: false,
checked: None,
@@ -828,7 +828,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::Root(mdast::Root {
+ mdast_util_to_hast(&mdast::Node::Root(mdast::Root {
children: vec![mdast::Node::ListItem(mdast::ListItem {
spread: true,
checked: None,
@@ -874,7 +874,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::Root(mdast::Root {
+ mdast_util_to_hast(&mdast::Node::Root(mdast::Root {
children: vec![mdast::Node::ListItem(mdast::ListItem {
spread: false,
checked: Some(true),
@@ -911,7 +911,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::Root(mdast::Root {
+ mdast_util_to_hast(&mdast::Node::Root(mdast::Root {
children: vec![mdast::Node::ListItem(mdast::ListItem {
spread: false,
checked: Some(false),
@@ -964,7 +964,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::List(mdast::List {
+ mdast_util_to_hast(&mdast::Node::List(mdast::List {
ordered: true,
start: Some(1),
spread: false,
@@ -1010,7 +1010,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::List(mdast::List {
+ mdast_util_to_hast(&mdast::Node::List(mdast::List {
ordered: true,
start: Some(123),
spread: false,
@@ -1030,7 +1030,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::List(mdast::List {
+ mdast_util_to_hast(&mdast::Node::List(mdast::List {
ordered: false,
start: None,
spread: false,
@@ -1050,7 +1050,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::List(mdast::List {
+ mdast_util_to_hast(&mdast::Node::List(mdast::List {
ordered: false,
start: None,
spread: false,
@@ -1105,7 +1105,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::Math(mdast::Math {
+ mdast_util_to_hast(&mdast::Node::Math(mdast::Math {
meta: None,
value: "a".into(),
position: None,
@@ -1134,7 +1134,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::MdxFlowExpression(mdast::MdxFlowExpression {
+ mdast_util_to_hast(&mdast::Node::MdxFlowExpression(mdast::MdxFlowExpression {
value: "a".into(),
position: None,
stops: vec![]
@@ -1148,7 +1148,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::MdxTextExpression(mdast::MdxTextExpression {
+ mdast_util_to_hast(&mdast::Node::MdxTextExpression(mdast::MdxTextExpression {
value: "a".into(),
position: None,
stops: vec![]
@@ -1162,7 +1162,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::MdxJsxFlowElement(mdast::MdxJsxFlowElement {
+ mdast_util_to_hast(&mdast::Node::MdxJsxFlowElement(mdast::MdxJsxFlowElement {
name: None,
attributes: vec![],
children: vec![],
@@ -1178,7 +1178,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::MdxJsxTextElement(mdast::MdxJsxTextElement {
+ mdast_util_to_hast(&mdast::Node::MdxJsxTextElement(mdast::MdxJsxTextElement {
name: None,
attributes: vec![],
children: vec![],
@@ -1194,7 +1194,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::MdxjsEsm(mdast::MdxjsEsm {
+ mdast_util_to_hast(&mdast::Node::MdxjsEsm(mdast::MdxjsEsm {
value: "a".into(),
position: None,
stops: vec![]
@@ -1208,7 +1208,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::Paragraph(mdast::Paragraph {
+ mdast_util_to_hast(&mdast::Node::Paragraph(mdast::Paragraph {
children: vec![mdast::Node::Text(mdast::Text {
value: "a".into(),
position: None
@@ -1228,7 +1228,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::Root(mdast::Root {
+ mdast_util_to_hast(&mdast::Node::Root(mdast::Root {
children: vec![],
position: None,
})),
@@ -1240,7 +1240,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::Strong(mdast::Strong {
+ mdast_util_to_hast(&mdast::Node::Strong(mdast::Strong {
children: vec![mdast::Node::Text(mdast::Text {
value: "a".into(),
position: None
@@ -1260,7 +1260,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::TableCell(mdast::TableCell {
+ mdast_util_to_hast(&mdast::Node::TableCell(mdast::TableCell {
children: vec![mdast::Node::Text(mdast::Text {
value: "a".into(),
position: None
@@ -1280,7 +1280,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::TableRow(mdast::TableRow {
+ mdast_util_to_hast(&mdast::Node::TableRow(mdast::TableRow {
children: vec![
mdast::Node::TableCell(mdast::TableCell {
children: vec![mdast::Node::Text(mdast::Text {
@@ -1340,7 +1340,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::Table(mdast::Table {
+ mdast_util_to_hast(&mdast::Node::Table(mdast::Table {
align: vec![mdast::AlignKind::Left, mdast::AlignKind::None],
children: vec![
mdast::Node::TableRow(mdast::TableRow {
@@ -1517,7 +1517,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::Text(mdast::Text {
+ mdast_util_to_hast(&mdast::Node::Text(mdast::Text {
value: "a".into(),
position: None,
})),
@@ -1529,7 +1529,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::ThematicBreak(mdast::ThematicBreak {
+ mdast_util_to_hast(&mdast::Node::ThematicBreak(mdast::ThematicBreak {
position: None
})),
hast::Node::Element(hast::Element {
@@ -1542,7 +1542,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::Yaml(mdast::Yaml {
+ mdast_util_to_hast(&mdast::Node::Yaml(mdast::Yaml {
value: "a".into(),
position: None
})),
@@ -1554,7 +1554,7 @@ fn hast() {
);
assert_eq!(
- to_hast(&mdast::Node::Toml(mdast::Toml {
+ mdast_util_to_hast(&mdast::Node::Toml(mdast::Toml {
value: "a".into(),
position: None
})),
diff --git a/tests/xxx_document.rs b/tests/xxx_mdx_plugin_recma_document.rs
index 7e43b1c..1cb91fe 100644
--- a/tests/xxx_document.rs
+++ b/tests/xxx_mdx_plugin_recma_document.rs
@@ -6,10 +6,10 @@ mod test_utils;
use micromark::{micromark_to_mdast, Constructs, Location, ParseOptions};
use pretty_assertions::assert_eq;
use test_utils::{
+ hast_util_to_swc::hast_util_to_swc,
+ mdast_util_to_hast::mdast_util_to_hast,
+ mdx_plugin_recma_document::{mdx_plugin_recma_document, Options as DocumentOptions},
swc::{parse_esm, parse_expression, serialize},
- to_document::{to_document, Options as DocumentOptions},
- to_hast::to_hast,
- to_swc::to_swc,
};
fn from_markdown(value: &str) -> Result<String, String> {
@@ -23,15 +23,15 @@ fn from_markdown(value: &str) -> Result<String, String> {
..ParseOptions::default()
},
)?;
- let hast = to_hast(&mdast);
- let swc_tree = to_swc(&hast, None, Some(&location))?;
- let program = to_document(swc_tree, &DocumentOptions::default(), Some(&location))?;
+ let hast = mdast_util_to_hast(&mdast);
+ let program = hast_util_to_swc(&hast, None, Some(&location))?;
+ let program = mdx_plugin_recma_document(program, &DocumentOptions::default(), Some(&location))?;
let value = serialize(&program.module);
Ok(value)
}
#[test]
-fn document() -> Result<(), String> {
+fn mdx_plugin_recma_document_test() -> Result<(), String> {
assert_eq!(
from_markdown("# hi\n\nAlpha *bravo* **charlie**.")?,
"function _createMdxContent(props) {
diff --git a/tests/xxx_jsx_rewrite.rs b/tests/xxx_mdx_plugin_recma_jsx_rewrite.rs
index c383f13..497155f 100644
--- a/tests/xxx_jsx_rewrite.rs
+++ b/tests/xxx_mdx_plugin_recma_jsx_rewrite.rs
@@ -6,11 +6,11 @@ mod test_utils;
use micromark::{micromark_to_mdast, Constructs, Location, ParseOptions};
use pretty_assertions::assert_eq;
use test_utils::{
- jsx_rewrite::{jsx_rewrite, Options as RewriteOptions},
+ hast_util_to_swc::hast_util_to_swc,
+ mdast_util_to_hast::mdast_util_to_hast,
+ mdx_plugin_recma_document::{mdx_plugin_recma_document, Options as DocumentOptions},
+ mdx_plugin_recma_jsx_rewrite::{mdx_plugin_recma_jsx_rewrite, Options as RewriteOptions},
swc::{parse_esm, parse_expression, serialize},
- to_document::{to_document, Options as DocumentOptions},
- to_hast::to_hast,
- to_swc::to_swc,
};
fn from_markdown(value: &str, options: &RewriteOptions) -> Result<String, String> {
@@ -24,16 +24,16 @@ fn from_markdown(value: &str, options: &RewriteOptions) -> Result<String, String
..ParseOptions::default()
},
)?;
- let hast = to_hast(&mdast);
- let swc_tree = to_swc(&hast, Some("example.mdx".into()), Some(&location))?;
- let program = to_document(swc_tree, &DocumentOptions::default(), Some(&location))?;
- let program = jsx_rewrite(program, options, Some(&location));
+ let hast = mdast_util_to_hast(&mdast);
+ let program = hast_util_to_swc(&hast, Some("example.mdx".into()), Some(&location))?;
+ let program = mdx_plugin_recma_document(program, &DocumentOptions::default(), Some(&location))?;
+ let program = mdx_plugin_recma_jsx_rewrite(program, options, Some(&location));
let value = serialize(&program.module);
Ok(value)
}
#[test]
-fn rewrite() -> Result<(), String> {
+fn mdx_plugin_recma_jsx_rewrite_test() -> Result<(), String> {
assert_eq!(
from_markdown("", &Default::default())?,
"function _createMdxContent(props) {