".into(),
- position: None,
- })),
- hast::Node::Root(hast::Root {
- children: vec![],
- position: None
- }),
- "should support an `Html`",
- );
-
- assert_eq!(
- mdast_util_to_hast(&mdast::Node::Image(mdast::Image {
- url: "a".into(),
- alt: "b".into(),
- title: None,
- position: None,
- })),
- hast::Node::Element(hast::Element {
- tag_name: "img".into(),
- properties: vec![
- ("src".into(), hast::PropertyValue::String("a".into()),),
- ("alt".into(), hast::PropertyValue::String("b".into()),)
- ],
- children: vec![],
- position: None
- }),
- "should support an `Image`",
- );
-
- assert_eq!(
- mdast_util_to_hast(&mdast::Node::Root(mdast::Root {
- children: vec![
- mdast::Node::Definition(mdast::Definition {
- url: "b".into(),
- title: None,
- identifier: "a".into(),
- label: None,
- position: None
- }),
- mdast::Node::Paragraph(mdast::Paragraph {
- children: vec![mdast::Node::ImageReference(mdast::ImageReference {
- reference_kind: mdast::ReferenceKind::Full,
- identifier: "a".into(),
- alt: "c".into(),
- label: None,
- position: None,
- })],
- position: None
- }),
- ],
- position: None,
- })),
- hast::Node::Root(hast::Root {
- children: vec![hast::Node::Element(hast::Element {
- tag_name: "p".into(),
- properties: vec![],
- children: vec![hast::Node::Element(hast::Element {
- tag_name: "img".into(),
- properties: vec![
- ("src".into(), hast::PropertyValue::String("b".into()),),
- ("alt".into(), hast::PropertyValue::String("c".into()),)
- ],
- children: vec![],
- position: None
- }),],
- position: None
- }),],
- position: None
- }),
- "should support an `ImageReference`",
- );
-
- assert_eq!(
- mdast_util_to_hast(&mdast::Node::InlineCode(mdast::InlineCode {
- value: "a\nb".into(),
- position: None,
- })),
- hast::Node::Element(hast::Element {
- tag_name: "code".into(),
- properties: vec![],
- children: vec![hast::Node::Text(hast::Text {
- value: "a b".into(),
- position: None
- })],
- position: None
- }),
- "should support an `InlineCode`",
- );
-
- assert_eq!(
- mdast_util_to_hast(&mdast::Node::InlineMath(mdast::InlineMath {
- value: "a\nb".into(),
- position: None,
- })),
- hast::Node::Element(hast::Element {
- tag_name: "code".into(),
- properties: vec![(
- "className".into(),
- hast::PropertyValue::SpaceSeparated(vec![
- "language-math".into(),
- "math-inline".into()
- ]),
- ),],
- children: vec![hast::Node::Text(hast::Text {
- value: "a b".into(),
- position: None
- })],
- position: None
- }),
- "should support an `InlineMath`",
- );
-
- assert_eq!(
- mdast_util_to_hast(&mdast::Node::Link(mdast::Link {
- url: "a".into(),
- title: None,
- children: vec![mdast::Node::Text(mdast::Text {
- value: "b".into(),
- position: None
- })],
- position: None,
- })),
- hast::Node::Element(hast::Element {
- tag_name: "a".into(),
- properties: vec![("href".into(), hast::PropertyValue::String("a".into()),),],
- children: vec![hast::Node::Text(hast::Text {
- value: "b".into(),
- position: None
- })],
- position: None
- }),
- "should support a `Link`",
- );
-
- assert_eq!(
- mdast_util_to_hast(&mdast::Node::Root(mdast::Root {
- children: vec![
- mdast::Node::Definition(mdast::Definition {
- url: "b".into(),
- title: None,
- identifier: "a".into(),
- label: None,
- position: None
- }),
- mdast::Node::Paragraph(mdast::Paragraph {
- children: vec![mdast::Node::LinkReference(mdast::LinkReference {
- reference_kind: mdast::ReferenceKind::Full,
- identifier: "a".into(),
- label: None,
- children: vec![mdast::Node::Text(mdast::Text {
- value: "c".into(),
- position: None
- })],
- position: None,
- })],
- position: None
- }),
- ],
- position: None,
- })),
- hast::Node::Root(hast::Root {
- children: vec![hast::Node::Element(hast::Element {
- tag_name: "p".into(),
- properties: vec![],
- children: vec![hast::Node::Element(hast::Element {
- tag_name: "a".into(),
- properties: vec![("href".into(), hast::PropertyValue::String("b".into()),),],
- children: vec![hast::Node::Text(hast::Text {
- value: "c".into(),
- position: None
- })],
- position: None
- }),],
- position: None
- }),],
- position: None
- }),
- "should support a `LinkReference`",
- );
-
- assert_eq!(
- mdast_util_to_hast(&mdast::Node::Root(mdast::Root {
- children: vec![mdast::Node::ListItem(mdast::ListItem {
- spread: false,
- checked: None,
- children: vec![mdast::Node::Paragraph(mdast::Paragraph {
- children: vec![mdast::Node::Text(mdast::Text {
- value: "a".into(),
- position: None
- })],
- position: None
- }),],
- position: None
- }),],
- position: None,
- })),
- hast::Node::Root(hast::Root {
- children: vec![hast::Node::Element(hast::Element {
- tag_name: "li".into(),
- properties: vec![],
- children: vec![hast::Node::Text(hast::Text {
- value: "a".into(),
- position: None
- }),],
- position: None
- }),],
- position: None
- }),
- "should support a `ListItem`",
- );
-
- assert_eq!(
- mdast_util_to_hast(&mdast::Node::Root(mdast::Root {
- children: vec![mdast::Node::ListItem(mdast::ListItem {
- spread: true,
- checked: None,
- children: vec![mdast::Node::Paragraph(mdast::Paragraph {
- children: vec![mdast::Node::Text(mdast::Text {
- value: "a".into(),
- position: None
- })],
- position: None
- }),],
- position: None
- }),],
- position: None,
- })),
- hast::Node::Root(hast::Root {
- children: vec![hast::Node::Element(hast::Element {
- tag_name: "li".into(),
- properties: vec![],
- children: vec![
- hast::Node::Text(hast::Text {
- value: "\n".into(),
- position: None
- }),
- hast::Node::Element(hast::Element {
- tag_name: "p".into(),
- properties: vec![],
- children: vec![hast::Node::Text(hast::Text {
- value: "a".into(),
- position: None
- }),],
- position: None
- }),
- hast::Node::Text(hast::Text {
- value: "\n".into(),
- position: None
- }),
- ],
- position: None
- }),],
- position: None
- }),
- "should support a `ListItem` (spread: true)",
- );
-
- assert_eq!(
- mdast_util_to_hast(&mdast::Node::Root(mdast::Root {
- children: vec![mdast::Node::ListItem(mdast::ListItem {
- spread: false,
- checked: Some(true),
- children: vec![],
- position: None
- }),],
- position: None,
- })),
- hast::Node::Root(hast::Root {
- children: vec![hast::Node::Element(hast::Element {
- tag_name: "li".into(),
- properties: vec![(
- "className".into(),
- hast::PropertyValue::SpaceSeparated(vec!["task-list-item".into()])
- )],
- children: vec![hast::Node::Element(hast::Element {
- tag_name: "input".into(),
- properties: vec![
- (
- "type".into(),
- hast::PropertyValue::String("checkbox".into()),
- ),
- ("checked".into(), hast::PropertyValue::Boolean(true)),
- ("disabled".into(), hast::PropertyValue::Boolean(true)),
- ],
- children: vec![],
- position: None
- }),],
- position: None
- }),],
- position: None
- }),
- "should support a `ListItem` (checked, w/o paragraph)",
- );
-
- assert_eq!(
- mdast_util_to_hast(&mdast::Node::Root(mdast::Root {
- children: vec![mdast::Node::ListItem(mdast::ListItem {
- spread: false,
- checked: Some(false),
- children: vec![mdast::Node::Paragraph(mdast::Paragraph {
- children: vec![mdast::Node::Text(mdast::Text {
- value: "a".into(),
- position: None
- })],
- position: None
- }),],
- position: None
- }),],
- position: None,
- })),
- hast::Node::Root(hast::Root {
- children: vec![hast::Node::Element(hast::Element {
- tag_name: "li".into(),
- properties: vec![(
- "className".into(),
- hast::PropertyValue::SpaceSeparated(vec!["task-list-item".into()])
- )],
- children: vec![
- hast::Node::Element(hast::Element {
- tag_name: "input".into(),
- properties: vec![
- (
- "type".into(),
- hast::PropertyValue::String("checkbox".into()),
- ),
- ("checked".into(), hast::PropertyValue::Boolean(false)),
- ("disabled".into(), hast::PropertyValue::Boolean(true)),
- ],
- children: vec![],
- position: None
- }),
- hast::Node::Text(hast::Text {
- value: " ".into(),
- position: None
- }),
- hast::Node::Text(hast::Text {
- value: "a".into(),
- position: None
- }),
- ],
- position: None
- }),],
- position: None
- }),
- "should support a `ListItem` (unchecked, w/ paragraph)",
- );
-
- assert_eq!(
- mdast_util_to_hast(&mdast::Node::List(mdast::List {
- ordered: true,
- start: Some(1),
- spread: false,
- children: vec![mdast::Node::ListItem(mdast::ListItem {
- spread: false,
- checked: None,
- children: vec![mdast::Node::Paragraph(mdast::Paragraph {
- children: vec![mdast::Node::Text(mdast::Text {
- value: "a".into(),
- position: None
- })],
- position: None
- }),],
- position: None
- }),],
- position: None,
- })),
- hast::Node::Element(hast::Element {
- tag_name: "ol".into(),
- properties: vec![],
- children: vec![
- hast::Node::Text(hast::Text {
- value: "\n".into(),
- position: None
- }),
- hast::Node::Element(hast::Element {
- tag_name: "li".into(),
- properties: vec![],
- children: vec![hast::Node::Text(hast::Text {
- value: "a".into(),
- position: None
- }),],
- position: None
- }),
- hast::Node::Text(hast::Text {
- value: "\n".into(),
- position: None
- }),
- ],
- position: None
- }),
- "should support a `List` (ordered, start: 1)",
- );
-
- assert_eq!(
- mdast_util_to_hast(&mdast::Node::List(mdast::List {
- ordered: true,
- start: Some(123),
- spread: false,
- children: vec![],
- position: None,
- })),
- hast::Node::Element(hast::Element {
- tag_name: "ol".into(),
- properties: vec![("start".into(), hast::PropertyValue::String("123".into()),),],
- children: vec![hast::Node::Text(hast::Text {
- value: "\n".into(),
- position: None
- })],
- position: None
- }),
- "should support a `List` (ordered, start: 123)",
- );
-
- assert_eq!(
- mdast_util_to_hast(&mdast::Node::List(mdast::List {
- ordered: false,
- start: None,
- spread: false,
- children: vec![],
- position: None,
- })),
- hast::Node::Element(hast::Element {
- tag_name: "ul".into(),
- properties: vec![],
- children: vec![hast::Node::Text(hast::Text {
- value: "\n".into(),
- position: None
- })],
- position: None
- }),
- "should support a `List` (unordered)",
- );
-
- assert_eq!(
- mdast_util_to_hast(&mdast::Node::List(mdast::List {
- ordered: false,
- start: None,
- spread: false,
- children: vec![mdast::Node::ListItem(mdast::ListItem {
- spread: false,
- checked: Some(true),
- children: vec![],
- position: None
- }),],
- position: None,
- })),
- hast::Node::Element(hast::Element {
- tag_name: "ul".into(),
- properties: vec![(
- "className".into(),
- hast::PropertyValue::SpaceSeparated(vec!["contains-task-list".into()])
- )],
- children: vec![
- hast::Node::Text(hast::Text {
- value: "\n".into(),
- position: None
- }),
- hast::Node::Element(hast::Element {
- tag_name: "li".into(),
- properties: vec![(
- "className".into(),
- hast::PropertyValue::SpaceSeparated(vec!["task-list-item".into()])
- )],
- children: vec![hast::Node::Element(hast::Element {
- tag_name: "input".into(),
- properties: vec![
- (
- "type".into(),
- hast::PropertyValue::String("checkbox".into()),
- ),
- ("checked".into(), hast::PropertyValue::Boolean(true)),
- ("disabled".into(), hast::PropertyValue::Boolean(true)),
- ],
- children: vec![],
- position: None
- }),],
- position: None
- }),
- hast::Node::Text(hast::Text {
- value: "\n".into(),
- position: None
- }),
- ],
- position: None
- }),
- "should support a `List` (w/ checked item)",
- );
-
- assert_eq!(
- mdast_util_to_hast(&mdast::Node::Math(mdast::Math {
- meta: None,
- value: "a".into(),
- position: None,
- })),
- hast::Node::Element(hast::Element {
- tag_name: "pre".into(),
- properties: vec![],
- children: vec![hast::Node::Element(hast::Element {
- tag_name: "code".into(),
- properties: vec![(
- "className".into(),
- hast::PropertyValue::SpaceSeparated(vec![
- "language-math".into(),
- "math-display".into()
- ]),
- ),],
- children: vec![hast::Node::Text(hast::Text {
- value: "a\n".into(),
- position: None
- })],
- position: None
- })],
- position: None
- }),
- "should support a `Math`",
- );
-
- assert_eq!(
- mdast_util_to_hast(&mdast::Node::MdxFlowExpression(mdast::MdxFlowExpression {
- value: "a".into(),
- position: None,
- stops: vec![]
- })),
- hast::Node::MdxExpression(hast::MdxExpression {
- value: "a".into(),
- position: None,
- stops: vec![]
- }),
- "should support an `MdxFlowExpression`",
- );
-
- assert_eq!(
- mdast_util_to_hast(&mdast::Node::MdxTextExpression(mdast::MdxTextExpression {
- value: "a".into(),
- position: None,
- stops: vec![]
- })),
- hast::Node::MdxExpression(hast::MdxExpression {
- value: "a".into(),
- position: None,
- stops: vec![]
- }),
- "should support an `MdxTextExpression`",
- );
-
- assert_eq!(
- mdast_util_to_hast(&mdast::Node::MdxJsxFlowElement(mdast::MdxJsxFlowElement {
- name: None,
- attributes: vec![],
- children: vec![],
- position: None,
- })),
- hast::Node::MdxJsxElement(hast::MdxJsxElement {
- name: None,
- attributes: vec![],
- children: vec![],
- position: None,
- }),
- "should support an `MdxJsxFlowElement`",
- );
-
- assert_eq!(
- mdast_util_to_hast(&mdast::Node::MdxJsxTextElement(mdast::MdxJsxTextElement {
- name: None,
- attributes: vec![],
- children: vec![],
- position: None,
- })),
- hast::Node::MdxJsxElement(hast::MdxJsxElement {
- name: None,
- attributes: vec![],
- children: vec![],
- position: None,
- }),
- "should support an `MdxJsxTextElement`",
- );
-
- assert_eq!(
- mdast_util_to_hast(&mdast::Node::MdxjsEsm(mdast::MdxjsEsm {
- value: "a".into(),
- position: None,
- stops: vec![]
- })),
- hast::Node::MdxjsEsm(hast::MdxjsEsm {
- value: "a".into(),
- position: None,
- stops: vec![]
- }),
- "should support an `MdxjsEsm`",
- );
-
- assert_eq!(
- mdast_util_to_hast(&mdast::Node::Paragraph(mdast::Paragraph {
- children: vec![mdast::Node::Text(mdast::Text {
- value: "a".into(),
- position: None
- })],
- position: None,
- })),
- hast::Node::Element(hast::Element {
- tag_name: "p".into(),
- properties: vec![],
- children: vec![hast::Node::Text(hast::Text {
- value: "a".into(),
- position: None
- })],
- position: None
- }),
- "should support a `Paragraph`",
- );
-
- assert_eq!(
- mdast_util_to_hast(&mdast::Node::Root(mdast::Root {
- children: vec![],
- position: None,
- })),
- hast::Node::Root(hast::Root {
- children: vec![],
- position: None
- }),
- "should support a `Root`",
- );
-
- assert_eq!(
- mdast_util_to_hast(&mdast::Node::Strong(mdast::Strong {
- children: vec![mdast::Node::Text(mdast::Text {
- value: "a".into(),
- position: None
- })],
- position: None,
- })),
- hast::Node::Element(hast::Element {
- tag_name: "strong".into(),
- properties: vec![],
- children: vec![hast::Node::Text(hast::Text {
- value: "a".into(),
- position: None
- })],
- position: None
- }),
- "should support a `Strong`",
- );
-
- assert_eq!(
- mdast_util_to_hast(&mdast::Node::TableCell(mdast::TableCell {
- children: vec![mdast::Node::Text(mdast::Text {
- value: "a".into(),
- position: None
- })],
- position: None,
- })),
- hast::Node::Element(hast::Element {
- tag_name: "td".into(),
- properties: vec![],
- children: vec![hast::Node::Text(hast::Text {
- value: "a".into(),
- position: None
- })],
- position: None
- }),
- "should support a `TableCell`",
- );
-
- assert_eq!(
- mdast_util_to_hast(&mdast::Node::TableRow(mdast::TableRow {
- children: vec![
- mdast::Node::TableCell(mdast::TableCell {
- children: vec![mdast::Node::Text(mdast::Text {
- value: "a".into(),
- position: None
- })],
- position: None,
- }),
- mdast::Node::TableCell(mdast::TableCell {
- children: vec![mdast::Node::Text(mdast::Text {
- value: "b".into(),
- position: None
- })],
- position: None,
- })
- ],
- position: None,
- })),
- hast::Node::Element(hast::Element {
- tag_name: "tr".into(),
- properties: vec![],
- children: vec![
- hast::Node::Text(hast::Text {
- value: "\n".into(),
- position: None
- }),
- hast::Node::Element(hast::Element {
- tag_name: "td".into(),
- properties: vec![],
- children: vec![hast::Node::Text(hast::Text {
- value: "a".into(),
- position: None
- })],
- position: None
- }),
- hast::Node::Text(hast::Text {
- value: "\n".into(),
- position: None
- }),
- hast::Node::Element(hast::Element {
- tag_name: "td".into(),
- properties: vec![],
- children: vec![hast::Node::Text(hast::Text {
- value: "b".into(),
- position: None
- })],
- position: None
- }),
- hast::Node::Text(hast::Text {
- value: "\n".into(),
- position: None
- }),
- ],
- position: None
- }),
- "should support a `TableRow`",
- );
-
- assert_eq!(
- mdast_util_to_hast(&mdast::Node::Table(mdast::Table {
- align: vec![mdast::AlignKind::Left, mdast::AlignKind::None],
- children: vec![
- mdast::Node::TableRow(mdast::TableRow {
- children: vec![
- mdast::Node::TableCell(mdast::TableCell {
- children: vec![mdast::Node::Text(mdast::Text {
- value: "a".into(),
- position: None
- })],
- position: None,
- }),
- mdast::Node::TableCell(mdast::TableCell {
- children: vec![mdast::Node::Text(mdast::Text {
- value: "b".into(),
- position: None
- })],
- position: None,
- })
- ],
- position: None,
- }),
- mdast::Node::TableRow(mdast::TableRow {
- children: vec![
- mdast::Node::TableCell(mdast::TableCell {
- children: vec![mdast::Node::Text(mdast::Text {
- value: "c".into(),
- position: None
- })],
- position: None,
- }),
- mdast::Node::TableCell(mdast::TableCell {
- children: vec![mdast::Node::Text(mdast::Text {
- value: "d".into(),
- position: None
- })],
- position: None,
- })
- ],
- position: None,
- })
- ],
- position: None,
- })),
- hast::Node::Element(hast::Element {
- tag_name: "table".into(),
- properties: vec![],
- children: vec![
- hast::Node::Text(hast::Text {
- value: "\n".into(),
- position: None
- }),
- hast::Node::Element(hast::Element {
- tag_name: "thead".into(),
- properties: vec![],
- children: vec![
- hast::Node::Text(hast::Text {
- value: "\n".into(),
- position: None
- }),
- hast::Node::Element(hast::Element {
- tag_name: "tr".into(),
- properties: vec![],
- children: vec![
- hast::Node::Text(hast::Text {
- value: "\n".into(),
- position: None
- }),
- hast::Node::Element(hast::Element {
- tag_name: "th".into(),
- properties: vec![(
- "align".into(),
- hast::PropertyValue::String("left".into()),
- ),],
- children: vec![hast::Node::Text(hast::Text {
- value: "a".into(),
- position: None
- })],
- position: None
- }),
- hast::Node::Text(hast::Text {
- value: "\n".into(),
- position: None
- }),
- hast::Node::Element(hast::Element {
- tag_name: "th".into(),
- properties: vec![],
- children: vec![hast::Node::Text(hast::Text {
- value: "b".into(),
- position: None
- })],
- position: None
- }),
- hast::Node::Text(hast::Text {
- value: "\n".into(),
- position: None
- }),
- ],
- position: None
- }),
- hast::Node::Text(hast::Text {
- value: "\n".into(),
- position: None
- }),
- ],
- position: None
- }),
- hast::Node::Text(hast::Text {
- value: "\n".into(),
- position: None
- }),
- hast::Node::Element(hast::Element {
- tag_name: "tbody".into(),
- properties: vec![],
- children: vec![
- hast::Node::Text(hast::Text {
- value: "\n".into(),
- position: None
- }),
- hast::Node::Element(hast::Element {
- tag_name: "tr".into(),
- properties: vec![],
- children: vec![
- hast::Node::Text(hast::Text {
- value: "\n".into(),
- position: None
- }),
- hast::Node::Element(hast::Element {
- tag_name: "td".into(),
- properties: vec![(
- "align".into(),
- hast::PropertyValue::String("left".into()),
- ),],
- children: vec![hast::Node::Text(hast::Text {
- value: "c".into(),
- position: None
- })],
- position: None
- }),
- hast::Node::Text(hast::Text {
- value: "\n".into(),
- position: None
- }),
- hast::Node::Element(hast::Element {
- tag_name: "td".into(),
- properties: vec![],
- children: vec![hast::Node::Text(hast::Text {
- value: "d".into(),
- position: None
- })],
- position: None
- }),
- hast::Node::Text(hast::Text {
- value: "\n".into(),
- position: None
- }),
- ],
- position: None
- }),
- hast::Node::Text(hast::Text {
- value: "\n".into(),
- position: None
- }),
- ],
- position: None
- }),
- hast::Node::Text(hast::Text {
- value: "\n".into(),
- position: None
- }),
- ],
- position: None
- }),
- "should support a `Table`",
- );
-
- assert_eq!(
- mdast_util_to_hast(&mdast::Node::Text(mdast::Text {
- value: "a".into(),
- position: None,
- })),
- hast::Node::Text(hast::Text {
- value: "a".into(),
- position: None
- }),
- "should support a `Text`",
- );
-
- assert_eq!(
- mdast_util_to_hast(&mdast::Node::ThematicBreak(mdast::ThematicBreak {
- position: None
- })),
- hast::Node::Element(hast::Element {
- tag_name: "hr".into(),
- properties: vec![],
- children: vec![],
- position: None
- }),
- "should support a `Thematicbreak`",
- );
-
- assert_eq!(
- mdast_util_to_hast(&mdast::Node::Yaml(mdast::Yaml {
- value: "a".into(),
- position: None
- })),
- hast::Node::Root(hast::Root {
- children: vec![],
- position: None
- }),
- "should support a `Yaml`",
- );
-
- assert_eq!(
- mdast_util_to_hast(&mdast::Node::Toml(mdast::Toml {
- value: "a".into(),
- position: None
- })),
- hast::Node::Root(hast::Root {
- children: vec![],
- position: None
- }),
- "should support a `Toml`",
- );
-}
diff --git a/tests/xxx_mdx.rs b/tests/xxx_mdx.rs
deleted file mode 100644
index eb8a211..0000000
--- a/tests/xxx_mdx.rs
+++ /dev/null
@@ -1,150 +0,0 @@
-mod test_utils;
-use pretty_assertions::assert_eq;
-use test_utils::mdx::{mdx, JsxRuntime, Options};
-
-#[test]
-fn mdx_test() -> Result<(), String> {
- // To do: JSX should be compiled away.
- assert_eq!(
- mdx("", Some("example.mdx".into()), &Options::default())?,
- "function _createMdxContent(props) {
- return <>>;
-}
-function MDXContent(props = {}) {
- const { wrapper: MDXLayout } = props.components || {};
- return MDXLayout ?
<_createMdxContent {...props}/> : _createMdxContent(props);
-}
-export default MDXContent;
-",
- "should work",
- );
-
- // To do: JSX should be compiled away.
- assert_eq!(
- mdx("
", Some("example.mdx".into()), &Options {
- development: true,
- ..Default::default()
- })?,
- "function _createMdxContent(props) {
- const { A } = props.components || {};
- if (!A) _missingMdxReference(\"A\", true, \"1:1-1:6\");
- return
;
-}
-function MDXContent(props = {}) {
- const { wrapper: MDXLayout } = props.components || {};
- return MDXLayout ?
<_createMdxContent {...props}/> : _createMdxContent(props);
-}
-export default MDXContent;
-function _missingMdxReference(id, component, place) {
- throw new Error(\"Expected \" + (component ? \"component\" : \"object\") + \" `\" + id + \"` to be defined: you likely forgot to import, pass, or provide it.\" + (place ? \"\\nIt’s referenced in your code at `\" + place + \"` in `example.mdx`\" : \"\"));
-}
-",
- "should support `options.development: true`",
- );
-
- // To do: JSX should be compiled away.
- assert_eq!(
- mdx("
", Some("example.mdx".into()), &Options {
- provider_import_source: Some("@mdx-js/react".into()),
- ..Default::default()
- })?,
- "import { useMDXComponents as _provideComponents } from \"@mdx-js/react\";
-function _createMdxContent(props) {
- const { A } = Object.assign({}, _provideComponents(), props.components);
- if (!A) _missingMdxReference(\"A\", true);
- return
;
-}
-function MDXContent(props = {}) {
- const { wrapper: MDXLayout } = Object.assign({}, _provideComponents(), props.components);
- return MDXLayout ?
<_createMdxContent {...props}/> : _createMdxContent(props);
-}
-export default MDXContent;
-function _missingMdxReference(id, component) {
- throw new Error(\"Expected \" + (component ? \"component\" : \"object\") + \" `\" + id + \"` to be defined: you likely forgot to import, pass, or provide it.\");
-}
-",
- "should support `options.provider_import_source`",
- );
-
- assert_eq!(
- mdx("", Some("example.mdx".into()), &Options {
- jsx: true,
- ..Default::default()
- })?,
- "function _createMdxContent(props) {
- return <>>;
-}
-function MDXContent(props = {}) {
- const { wrapper: MDXLayout } = props.components || {};
- return MDXLayout ?
<_createMdxContent {...props}/> : _createMdxContent(props);
-}
-export default MDXContent;
-",
- "should support `options.jsx: true`",
- );
-
- // To do: JSX should be compiled away.
- // To do: should use calls of `React.createElement` / `React.Fragment`.
- assert_eq!(
- mdx("", Some("example.mdx".into()), &Options {
- jsx_runtime: Some(JsxRuntime::Classic),
- ..Default::default()
- })?,
- "import { React } from \"react\";
-function _createMdxContent(props) {
- return <>>;
-}
-function MDXContent(props = {}) {
- const { wrapper: MDXLayout } = props.components || {};
- return MDXLayout ?
<_createMdxContent {...props}/> : _createMdxContent(props);
-}
-export default MDXContent;
-",
- "should support `options.jsx_runtime: JsxRuntime::Classic`",
- );
-
- // To do: JSX should be compiled away.
- // To do: should import `_jsx` and such.
- // To do: should use calls of `_jsx`, etc.
- assert_eq!(
- mdx("", Some("example.mdx".into()), &Options {
- jsx_import_source: Some("preact".into()),
- ..Default::default()
- })?,
- "function _createMdxContent(props) {
- return <>>;
-}
-function MDXContent(props = {}) {
- const { wrapper: MDXLayout } = props.components || {};
- return MDXLayout ?
<_createMdxContent {...props}/> : _createMdxContent(props);
-}
-export default MDXContent;
-",
- "should support `options.jsx_import_source: Some(\"preact\".into())`",
- );
-
- // To do: JSX should be compiled away.
- // To do: should use calls of `a.b`, symbol of `a.c`.
- assert_eq!(
- mdx("", Some("example.mdx".into()), &Options {
- jsx_runtime: Some(JsxRuntime::Classic),
- pragma: Some("a.b".into()),
- pragma_frag: Some("a.c".into()),
- pragma_import_source: Some("d".into()),
- ..Default::default()
- })?,
- "import { a } from \"d\";
-function _createMdxContent(props) {
- return <>>;
-}
-function MDXContent(props = {}) {
- const { wrapper: MDXLayout } = props.components || {};
- return MDXLayout ?
<_createMdxContent {...props}/> : _createMdxContent(props);
-}
-export default MDXContent;
-",
- "should support `options.pragma`, `options.pragma_frag`, `options.pragma_import_source`",
- );
-
- Ok(())
-}
diff --git a/tests/xxx_mdx_plugin_recma_document.rs b/tests/xxx_mdx_plugin_recma_document.rs
deleted file mode 100644
index c534d58..0000000
--- a/tests/xxx_mdx_plugin_recma_document.rs
+++ /dev/null
@@ -1,207 +0,0 @@
-mod test_utils;
-use markdown::{to_mdast, 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},
-};
-
-fn from_markdown(value: &str) -> Result
{
- let location = Location::new(value.as_bytes());
- let mdast = to_mdast(
- value,
- &ParseOptions {
- mdx_esm_parse: Some(Box::new(parse_esm)),
- mdx_expression_parse: Some(Box::new(parse_expression)),
- ..ParseOptions::mdx()
- },
- )?;
- let hast = mdast_util_to_hast(&mdast);
- let mut program = hast_util_to_swc(&hast, None, Some(&location))?;
- mdx_plugin_recma_document(&mut program, &DocumentOptions::default(), Some(&location))?;
- Ok(serialize(&program.module))
-}
-
-#[test]
-fn mdx_plugin_recma_document_test() -> Result<(), String> {
- assert_eq!(
- from_markdown("# hi\n\nAlpha *bravo* **charlie**.")?,
- "function _createMdxContent(props) {
- return <>{\"hi\"}
{\"\\n\"}{\"Alpha \"}{\"bravo\"}{\" \"}{\"charlie\"}{\".\"}
>;
-}
-function MDXContent(props = {}) {
- return MDXLayout ? <_createMdxContent {...props}/> : _createMdxContent(props);
-}
-export default MDXContent;
-",
- "should support a small program",
- );
-
- assert_eq!(
- from_markdown("import a from 'b'\n\n# {a}")?,
- "import a from 'b';
-function _createMdxContent(props) {
- return {a}
;
-}
-function MDXContent(props = {}) {
- return MDXLayout ? <_createMdxContent {...props}/> : _createMdxContent(props);
-}
-export default MDXContent;
-",
- "should support an import",
- );
-
- assert_eq!(
- from_markdown("export * from 'a'\n\n# b")?,
- "export * from 'a';
-function _createMdxContent(props) {
- return {\"b\"}
;
-}
-function MDXContent(props = {}) {
- return MDXLayout ? <_createMdxContent {...props}/> : _createMdxContent(props);
-}
-export default MDXContent;
-",
- "should support an export all",
- );
-
- assert_eq!(
- from_markdown("export function a() {}")?,
- "export function a() {}
-function _createMdxContent(props) {
- return <>>;
-}
-function MDXContent(props = {}) {
- return MDXLayout ? <_createMdxContent {...props}/> : _createMdxContent(props);
-}
-export default MDXContent;
-",
- "should support an export declaration",
- );
-
- assert_eq!(
- from_markdown("export default a")?,
- "const MDXLayout = a;
-function _createMdxContent(props) {
- return <>>;
-}
-function MDXContent(props = {}) {
- return <_createMdxContent {...props}/>;
-}
-export default MDXContent;
-",
- "should support an export default expression",
- );
-
- assert_eq!(
- from_markdown("export default function () {}")?,
- "const MDXLayout = function() {};
-function _createMdxContent(props) {
- return <>>;
-}
-function MDXContent(props = {}) {
- return <_createMdxContent {...props}/>;
-}
-export default MDXContent;
-",
- "should support an export default declaration",
- );
-
- assert_eq!(
- from_markdown("export {a, b as default}")?,
- "export { a };
-const MDXLayout = b;
-function _createMdxContent(props) {
- return <>>;
-}
-function MDXContent(props = {}) {
- return <_createMdxContent {...props}/>;
-}
-export default MDXContent;
-",
- "should support a named export w/o source, w/ a default specifier",
- );
-
- assert_eq!(
- from_markdown("export {a}")?,
- "export { a };
-function _createMdxContent(props) {
- return <>>;
-}
-function MDXContent(props = {}) {
- return MDXLayout ? <_createMdxContent {...props}/> : _createMdxContent(props);
-}
-export default MDXContent;
-",
- "should support a named export w/o source, w/o a default specifier",
- );
-
- assert_eq!(
- from_markdown("export {}")?,
- "export { };
-function _createMdxContent(props) {
- return <>>;
-}
-function MDXContent(props = {}) {
- return MDXLayout ? <_createMdxContent {...props}/> : _createMdxContent(props);
-}
-export default MDXContent;
-",
- "should support a named export w/o source, w/o a specifiers",
- );
-
- assert_eq!(
- from_markdown("export {a, b as default} from 'c'")?,
- "export { a } from 'c';
-import { b as MDXLayout } from 'c';
-function _createMdxContent(props) {
- return <>>;
-}
-function MDXContent(props = {}) {
- return <_createMdxContent {...props}/>;
-}
-export default MDXContent;
-",
- "should support a named export w/ source, w/ a default specifier",
- );
-
- assert_eq!(
- from_markdown("export {a} from 'b'")?,
- "export { a } from 'b';
-function _createMdxContent(props) {
- return <>>;
-}
-function MDXContent(props = {}) {
- return MDXLayout ? <_createMdxContent {...props}/> : _createMdxContent(props);
-}
-export default MDXContent;
-",
- "should support a named export w/ source, w/o a default specifier",
- );
-
- assert_eq!(
- from_markdown("export {} from 'a'")?,
- "export { } from 'a';
-function _createMdxContent(props) {
- return <>>;
-}
-function MDXContent(props = {}) {
- return MDXLayout ? <_createMdxContent {...props}/> : _createMdxContent(props);
-}
-export default MDXContent;
-",
- "should support a named export w/ source, w/o a specifiers",
- );
-
- assert_eq!(
- from_markdown("export default a = 1\n\nexport default b = 2")
- .err()
- .unwrap(),
- "3:1: Cannot specify multiple layouts (previous: 1:1-1:21 (0-20))",
- "should crash on a comment spread"
- );
-
- Ok(())
-}
diff --git a/tests/xxx_mdx_plugin_recma_jsx_rewrite.rs b/tests/xxx_mdx_plugin_recma_jsx_rewrite.rs
deleted file mode 100644
index 77c794a..0000000
--- a/tests/xxx_mdx_plugin_recma_jsx_rewrite.rs
+++ /dev/null
@@ -1,375 +0,0 @@
-mod test_utils;
-use markdown::{to_mdast, 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},
- mdx_plugin_recma_jsx_rewrite::{mdx_plugin_recma_jsx_rewrite, Options as RewriteOptions},
- swc::{parse_esm, parse_expression, serialize},
-};
-
-fn from_markdown(value: &str, options: &RewriteOptions) -> Result {
- let location = Location::new(value.as_bytes());
- let mdast = to_mdast(
- value,
- &ParseOptions {
- mdx_esm_parse: Some(Box::new(parse_esm)),
- mdx_expression_parse: Some(Box::new(parse_expression)),
- ..ParseOptions::mdx()
- },
- )?;
- let hast = mdast_util_to_hast(&mdast);
- let mut program = hast_util_to_swc(&hast, Some("example.mdx".into()), Some(&location))?;
- mdx_plugin_recma_document(&mut program, &DocumentOptions::default(), Some(&location))?;
- mdx_plugin_recma_jsx_rewrite(&mut program, options, Some(&location));
- Ok(serialize(&program.module))
-}
-
-#[test]
-fn mdx_plugin_recma_jsx_rewrite_test() -> Result<(), String> {
- assert_eq!(
- from_markdown("", &Default::default())?,
- "function _createMdxContent(props) {
- return <>>;
-}
-function MDXContent(props = {}) {
- const { wrapper: MDXLayout } = props.components || {};
- return MDXLayout ? <_createMdxContent {...props}/> : _createMdxContent(props);
-}
-export default MDXContent;
-",
- "should work on an empty file",
- );
-
- assert_eq!(
- from_markdown("# hi", &Default::default())?,
- "function _createMdxContent(props) {
- const _components = Object.assign({
- h1: \"h1\"
- }, props.components);
- return <_components.h1 >{\"hi\"};
-}
-function MDXContent(props = {}) {
- const { wrapper: MDXLayout } = props.components || {};
- return MDXLayout ? <_createMdxContent {...props}/> : _createMdxContent(props);
-}
-export default MDXContent;
-",
- "should support passing in a layout (as `wrapper`) and components for literal tags",
- );
-
- assert_eq!(
- from_markdown(
- "export {MyLayout as default} from './a.js'\n\n# hi",
- &Default::default()
- )?,
- "import { MyLayout as MDXLayout } from './a.js';
-function _createMdxContent(props) {
- const _components = Object.assign({
- h1: \"h1\"
- }, props.components);
- return <_components.h1 >{\"hi\"};
-}
-function MDXContent(props = {}) {
- return <_createMdxContent {...props}/>;
-}
-export default MDXContent;
-",
- "should not support passing in a layout if one is defined locally",
- );
-
- assert_eq!(
- from_markdown("# ", &Default::default())?,
- "function _createMdxContent(props) {
- const _components = Object.assign({
- h1: \"h1\"
- }, props.components), { Hi } = _components;
- if (!Hi) _missingMdxReference(\"Hi\", true);
- return <_components.h1 >;
-}
-function MDXContent(props = {}) {
- const { wrapper: MDXLayout } = props.components || {};
- return MDXLayout ? <_createMdxContent {...props}/> : _createMdxContent(props);
-}
-export default MDXContent;
-function _missingMdxReference(id, component) {
- throw new Error(\"Expected \" + (component ? \"component\" : \"object\") + \" `\" + id + \"` to be defined: you likely forgot to import, pass, or provide it.\");
-}
-",
- "should support passing in a component",
- );
-
- assert_eq!(
- from_markdown(", , ", &Default::default())?,
- "function _createMdxContent(props) {
- const _components = Object.assign({
- p: \"p\"
- }, props.components), { X , Y } = _components;
- if (!X) _missingMdxReference(\"X\", true);
- if (!X.y) _missingMdxReference(\"X.y\", true);
- if (!Y) _missingMdxReference(\"Y\", false);
- if (!Y.Z) _missingMdxReference(\"Y.Z\", true);
- return <_components.p >{\", \"}{\", \"};
-}
-function MDXContent(props = {}) {
- const { wrapper: MDXLayout } = props.components || {};
- return MDXLayout ? <_createMdxContent {...props}/> : _createMdxContent(props);
-}
-export default MDXContent;
-function _missingMdxReference(id, component) {
- throw new Error(\"Expected \" + (component ? \"component\" : \"object\") + \" `\" + id + \"` to be defined: you likely forgot to import, pass, or provide it.\");
-}
-",
- "should support passing in component objects",
- );
-
- assert_eq!(
- from_markdown("import {Hi} from './a.js'\n\n# ", &Default::default())?,
- "import { Hi } from './a.js';
-function _createMdxContent(props) {
- const _components = Object.assign({
- h1: \"h1\"
- }, props.components);
- return <_components.h1 >;
-}
-function MDXContent(props = {}) {
- const { wrapper: MDXLayout } = props.components || {};
- return MDXLayout ? <_createMdxContent {...props}/> : _createMdxContent(props);
-}
-export default MDXContent;
-",
- "should not support passing in a component if one is defined locally",
- );
-
- assert_eq!(
- from_markdown("# ", &Default::default())?,
- "function _createMdxContent(props) {
- const _components = Object.assign({
- h1: \"h1\",
- \"a-b\": \"a-b\"
- }, props.components), _component0 = _components[\"a-b\"];
- return <_components.h1 ><_component0 />;
-}
-function MDXContent(props = {}) {
- const { wrapper: MDXLayout } = props.components || {};
- return MDXLayout ? <_createMdxContent {...props}/> : _createMdxContent(props);
-}
-export default MDXContent;
-",
- "should support passing in a component for a JSX identifier that is not a valid JS identifier",
- );
-
- assert_eq!(
- from_markdown("# ", &RewriteOptions {
- provider_import_source: Some("x".into()),
- ..Default::default()
- })?,
- "import { useMDXComponents as _provideComponents } from \"x\";
-function _createMdxContent(props) {
- const _components = Object.assign({
- h1: \"h1\"
- }, _provideComponents(), props.components), { Hi } = _components;
- if (!Hi) _missingMdxReference(\"Hi\", true);
- return <_components.h1 >;
-}
-function MDXContent(props = {}) {
- const { wrapper: MDXLayout } = Object.assign({}, _provideComponents(), props.components);
- return MDXLayout ? <_createMdxContent {...props}/> : _createMdxContent(props);
-}
-export default MDXContent;
-function _missingMdxReference(id, component) {
- throw new Error(\"Expected \" + (component ? \"component\" : \"object\") + \" `\" + id + \"` to be defined: you likely forgot to import, pass, or provide it.\");
-}
-",
- "should support providing a layout, literal tags, and components",
- );
-
- assert_eq!(
- from_markdown("", &RewriteOptions {
- provider_import_source: Some("x".into()),
- ..Default::default()
- })?,
- "import { useMDXComponents as _provideComponents } from \"x\";
-function _createMdxContent(props) {
- return <>>;
-}
-function MDXContent(props = {}) {
- const { wrapper: MDXLayout } = Object.assign({}, _provideComponents(), props.components);
- return MDXLayout ? <_createMdxContent {...props}/> : _createMdxContent(props);
-}
-export default MDXContent;
-",
- "should support a provider on an empty file",
- );
-
- assert_eq!(
- from_markdown(", , ", &RewriteOptions {
- provider_import_source: Some("x".into()),
- ..Default::default()
- })?,
- "import { useMDXComponents as _provideComponents } from \"x\";
-function _createMdxContent(props) {
- const _components = Object.assign({
- p: \"p\"
- }, _provideComponents(), props.components), { X , Y } = _components;
- if (!X) _missingMdxReference(\"X\", true);
- if (!X.y) _missingMdxReference(\"X.y\", true);
- if (!Y) _missingMdxReference(\"Y\", false);
- if (!Y.Z) _missingMdxReference(\"Y.Z\", true);
- return <_components.p >{\", \"}{\", \"};
-}
-function MDXContent(props = {}) {
- const { wrapper: MDXLayout } = Object.assign({}, _provideComponents(), props.components);
- return MDXLayout ? <_createMdxContent {...props}/> : _createMdxContent(props);
-}
-export default MDXContent;
-function _missingMdxReference(id, component) {
- throw new Error(\"Expected \" + (component ? \"component\" : \"object\") + \" `\" + id + \"` to be defined: you likely forgot to import, pass, or provide it.\");
-}
-",
- "should support providing component objects",
- );
-
- assert_eq!(
- from_markdown("export function A() {
- return
-}
-
-
-", &Default::default())?,
- "export function A() {
- return ;
-}
-function _createMdxContent(props) {
- return ;
-}
-function MDXContent(props = {}) {
- const { wrapper: MDXLayout } = props.components || {};
- return MDXLayout ? <_createMdxContent {...props}/> : _createMdxContent(props);
-}
-export default MDXContent;
-",
- "should not support passing components in locally defined components",
- );
-
- assert_eq!(
- from_markdown("export function A() {
- return
-}
-
-
-", &RewriteOptions {
- provider_import_source: Some("x".into()),
- ..Default::default()
-})?,
- "import { useMDXComponents as _provideComponents } from \"x\";
-export function A() {
- const { B } = _provideComponents();
- if (!B) _missingMdxReference(\"B\", true);
- return ;
-}
-function _createMdxContent(props) {
- return ;
-}
-function MDXContent(props = {}) {
- const { wrapper: MDXLayout } = Object.assign({}, _provideComponents(), props.components);
- return MDXLayout ? <_createMdxContent {...props}/> : _createMdxContent(props);
-}
-export default MDXContent;
-function _missingMdxReference(id, component) {
- throw new Error(\"Expected \" + (component ? \"component\" : \"object\") + \" `\" + id + \"` to be defined: you likely forgot to import, pass, or provide it.\");
-}
-",
- "should support providing components in locally defined components",
- );
-
- assert_eq!(
- from_markdown("export function A() {
- return
-}
-
-
-", &RewriteOptions {
- provider_import_source: Some("x".into()),
- ..Default::default()
-})?,
- "import { useMDXComponents as _provideComponents } from \"x\";
-export function A() {
- const _components = Object.assign({
- \"b-c\": \"b-c\"
- }, _provideComponents()), _component0 = _components[\"b-c\"];
- return <_component0 />;
-}
-function _createMdxContent(props) {
- return ;
-}
-function MDXContent(props = {}) {
- const { wrapper: MDXLayout } = Object.assign({}, _provideComponents(), props.components);
- return MDXLayout ? <_createMdxContent {...props}/> : _createMdxContent(props);
-}
-export default MDXContent;
-",
- "should support providing components with JSX identifiers that are not JS identifiers in locally defined components",
- );
-
- assert_eq!(
- from_markdown("export function A() {
- return , ,
-}
-
-
-", &RewriteOptions {
- provider_import_source: Some("x".into()),
- ..Default::default()
-})?,
- "import { useMDXComponents as _provideComponents } from \"x\";
-export function A() {
- const { X , Y } = _provideComponents();
- if (!X) _missingMdxReference(\"X\", true);
- if (!X.y) _missingMdxReference(\"X.y\", true);
- if (!Y) _missingMdxReference(\"Y\", false);
- if (!Y.Z) _missingMdxReference(\"Y.Z\", true);
- return , , ;
-}
-function _createMdxContent(props) {
- return ;
-}
-function MDXContent(props = {}) {
- const { wrapper: MDXLayout } = Object.assign({}, _provideComponents(), props.components);
- return MDXLayout ? <_createMdxContent {...props}/> : _createMdxContent(props);
-}
-export default MDXContent;
-function _missingMdxReference(id, component) {
- throw new Error(\"Expected \" + (component ? \"component\" : \"object\") + \" `\" + id + \"` to be defined: you likely forgot to import, pass, or provide it.\");
-}
-",
- "should support providing components with JSX identifiers that are not JS identifiers in locally defined components",
- );
-
- assert_eq!(
- from_markdown("# ", &RewriteOptions {
- development: true,
- ..Default::default()
- })?,
- "function _createMdxContent(props) {
- const _components = Object.assign({
- h1: \"h1\"
- }, props.components), { Hi } = _components;
- if (!Hi) _missingMdxReference(\"Hi\", true, \"1:3-1:9\");
- return <_components.h1 >;
-}
-function MDXContent(props = {}) {
- const { wrapper: MDXLayout } = props.components || {};
- return MDXLayout ? <_createMdxContent {...props}/> : _createMdxContent(props);
-}
-export default MDXContent;
-function _missingMdxReference(id, component, place) {
- throw new Error(\"Expected \" + (component ? \"component\" : \"object\") + \" `\" + id + \"` to be defined: you likely forgot to import, pass, or provide it.\" + (place ? \"\\nIt’s referenced in your code at `\" + place + \"` in `example.mdx`\" : \"\"));
-}
-",
- "should create missing reference helpers w/o positional info in `development` mode",
- );
-
- Ok(())
-}