aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-09-26 16:12:25 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-09-26 16:12:25 +0200
commita0c84c505d733be2e987a333a34244c1befb56cb (patch)
tree0545a747b6f2f627a71bd31949ad622bbc56c176 /tests
parent9cb9e37c33173c16cbafd345f43e43b5a550537d (diff)
downloadmarkdown-rs-a0c84c505d733be2e987a333a34244c1befb56cb.tar.gz
markdown-rs-a0c84c505d733be2e987a333a34244c1befb56cb.tar.bz2
markdown-rs-a0c84c505d733be2e987a333a34244c1befb56cb.zip
Add support for compiling to mdast
See: <https://github.com/syntax-tree/mdast>.
Diffstat (limited to 'tests')
-rw-r--r--tests/attention.rs44
-rw-r--r--tests/autolink.rs51
-rw-r--r--tests/block_quote.rs23
-rw-r--r--tests/character_escape.rs20
-rw-r--r--tests/character_reference.rs29
-rw-r--r--tests/code_fenced.rs36
-rw-r--r--tests/code_indented.rs22
-rw-r--r--tests/code_text.rs30
-rw-r--r--tests/commonmark.rs2
-rw-r--r--tests/definition.rs20
-rw-r--r--tests/frontmatter.rs29
-rw-r--r--tests/gfm_autolink_literal.rs90
-rw-r--r--tests/gfm_footnote.rs45
-rw-r--r--tests/gfm_strikethrough.rs33
-rw-r--r--tests/gfm_table.rs132
-rw-r--r--tests/gfm_task_list_item.rs57
-rw-r--r--tests/hard_break_escape.rs29
-rw-r--r--tests/hard_break_trailing.rs29
-rw-r--r--tests/heading_atx.rs21
-rw-r--r--tests/heading_setext.rs21
-rw-r--r--tests/html_flow.rs17
-rw-r--r--tests/html_text.rs38
-rw-r--r--tests/image.rs108
-rw-r--r--tests/link_reference.rs73
-rw-r--r--tests/link_resource.rs51
-rw-r--r--tests/list.rs106
-rw-r--r--tests/math_flow.rs18
-rw-r--r--tests/math_text.rs30
-rw-r--r--tests/mdx_esm.rs17
-rw-r--r--tests/mdx_expression_flow.rs17
-rw-r--r--tests/mdx_expression_text.rs30
-rw-r--r--tests/mdx_jsx_flow.rs36
-rw-r--r--tests/mdx_jsx_text.rs274
-rw-r--r--tests/thematic_break.rs16
34 files changed, 1556 insertions, 38 deletions
diff --git a/tests/attention.rs b/tests/attention.rs
index 93c3a50..607af58 100644
--- a/tests/attention.rs
+++ b/tests/attention.rs
@@ -1,5 +1,8 @@
extern crate micromark;
-use micromark::{micromark, micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{Emphasis, Node, Paragraph, Position, Root, Strong, Text},
+ micromark, micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
#[test]
@@ -827,5 +830,44 @@ fn attention() -> Result<(), String> {
"should support turning off attention"
);
+ assert_eq!(
+ micromark_to_mdast("a *alpha* b **bravo** c.", &Options::default())?,
+ Node::Root(Root {
+ children: vec![Node::Paragraph(Paragraph {
+ children: vec![
+ Node::Text(Text {
+ value: "a ".to_string(),
+ position: Some(Position::new(1, 1, 0, 1, 3, 2))
+ }),
+ Node::Emphasis(Emphasis {
+ children: vec![Node::Text(Text {
+ value: "alpha".to_string(),
+ position: Some(Position::new(1, 4, 3, 1, 9, 8))
+ }),],
+ position: Some(Position::new(1, 3, 2, 1, 10, 9))
+ }),
+ Node::Text(Text {
+ value: " b ".to_string(),
+ position: Some(Position::new(1, 10, 9, 1, 13, 12))
+ }),
+ Node::Strong(Strong {
+ children: vec![Node::Text(Text {
+ value: "bravo".to_string(),
+ position: Some(Position::new(1, 15, 14, 1, 20, 19))
+ }),],
+ position: Some(Position::new(1, 13, 12, 1, 22, 21))
+ }),
+ Node::Text(Text {
+ value: " c.".to_string(),
+ position: Some(Position::new(1, 22, 21, 1, 25, 24))
+ })
+ ],
+ position: Some(Position::new(1, 1, 0, 1, 25, 24))
+ })],
+ position: Some(Position::new(1, 1, 0, 1, 25, 24))
+ }),
+ "should support attention as `Emphasis`, `Strong`s in mdast"
+ );
+
Ok(())
}
diff --git a/tests/autolink.rs b/tests/autolink.rs
index 4cf357a..cc30512 100644
--- a/tests/autolink.rs
+++ b/tests/autolink.rs
@@ -1,5 +1,8 @@
extern crate micromark;
-use micromark::{micromark, micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{Link, Node, Paragraph, Position, Root, Text},
+ micromark, micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
#[test]
@@ -259,5 +262,51 @@ fn autolink() -> Result<(), String> {
"should support turning off autolinks"
);
+ assert_eq!(
+ micromark_to_mdast(
+ "a <https://alpha.com> b <bravo@charlie.com> c.",
+ &Options::default()
+ )?,
+ Node::Root(Root {
+ children: vec![Node::Paragraph(Paragraph {
+ children: vec![
+ Node::Text(Text {
+ value: "a ".to_string(),
+ position: Some(Position::new(1, 1, 0, 1, 3, 2))
+ }),
+ Node::Link(Link {
+ url: "https://alpha.com".to_string(),
+ title: None,
+ children: vec![Node::Text(Text {
+ value: "https://alpha.com".to_string(),
+ position: Some(Position::new(1, 4, 3, 1, 21, 20))
+ }),],
+ position: Some(Position::new(1, 3, 2, 1, 22, 21))
+ }),
+ Node::Text(Text {
+ value: " b ".to_string(),
+ position: Some(Position::new(1, 22, 21, 1, 25, 24))
+ }),
+ Node::Link(Link {
+ url: "mailto:bravo@charlie.com".to_string(),
+ title: None,
+ children: vec![Node::Text(Text {
+ value: "bravo@charlie.com".to_string(),
+ position: Some(Position::new(1, 26, 25, 1, 43, 42))
+ }),],
+ position: Some(Position::new(1, 25, 24, 1, 44, 43))
+ }),
+ Node::Text(Text {
+ value: " c.".to_string(),
+ position: Some(Position::new(1, 44, 43, 1, 47, 46))
+ })
+ ],
+ position: Some(Position::new(1, 1, 0, 1, 47, 46))
+ })],
+ position: Some(Position::new(1, 1, 0, 1, 47, 46))
+ }),
+ "should support autolinks as `Link`s in mdast"
+ );
+
Ok(())
}
diff --git a/tests/block_quote.rs b/tests/block_quote.rs
index 6947ef3..9cd7d46 100644
--- a/tests/block_quote.rs
+++ b/tests/block_quote.rs
@@ -1,5 +1,8 @@
extern crate micromark;
-use micromark::{micromark, micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{BlockQuote, Node, Paragraph, Position, Root, Text},
+ micromark, micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
#[test]
@@ -211,5 +214,23 @@ fn block_quote() -> Result<(), String> {
"should support turning off block quotes"
);
+ assert_eq!(
+ micromark_to_mdast("> a", &Options::default())?,
+ Node::Root(Root {
+ children: vec![Node::BlockQuote(BlockQuote {
+ children: vec![Node::Paragraph(Paragraph {
+ children: vec![Node::Text(Text {
+ value: "a".to_string(),
+ position: Some(Position::new(1, 3, 2, 1, 4, 3))
+ }),],
+ position: Some(Position::new(1, 3, 2, 1, 4, 3))
+ })],
+ position: Some(Position::new(1, 1, 0, 1, 4, 3))
+ })],
+ position: Some(Position::new(1, 1, 0, 1, 4, 3))
+ }),
+ "should support block quotes as `BlockQuote`s in mdast"
+ );
+
Ok(())
}
diff --git a/tests/character_escape.rs b/tests/character_escape.rs
index e76e3e9..e0a3ed3 100644
--- a/tests/character_escape.rs
+++ b/tests/character_escape.rs
@@ -1,5 +1,8 @@
extern crate micromark;
-use micromark::{micromark, micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{Node, Paragraph, Position, Root, Text},
+ micromark, micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
#[test]
@@ -93,5 +96,20 @@ fn character_escape() -> Result<(), String> {
"should support turning off character escapes"
);
+ assert_eq!(
+ micromark_to_mdast("a \\* b", &Options::default())?,
+ Node::Root(Root {
+ children: vec![Node::Paragraph(Paragraph {
+ children: vec![Node::Text(Text {
+ value: "a * b".to_string(),
+ position: Some(Position::new(1, 1, 0, 1, 7, 6))
+ }),],
+ position: Some(Position::new(1, 1, 0, 1, 7, 6))
+ })],
+ position: Some(Position::new(1, 1, 0, 1, 7, 6))
+ }),
+ "should support character escapes as `Text`s in mdast"
+ );
+
Ok(())
}
diff --git a/tests/character_reference.rs b/tests/character_reference.rs
index a08c3f9..7385734 100644
--- a/tests/character_reference.rs
+++ b/tests/character_reference.rs
@@ -1,14 +1,18 @@
extern crate micromark;
-use micromark::{micromark, micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{Node, Paragraph, Position, Root, Text},
+ micromark, micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
#[test]
fn character_reference() -> Result<(), String> {
assert_eq!(
- micromark(
- "&nbsp; &amp; &copy; &AElig; &Dcaron;\n&frac34; &HilbertSpace; &DifferentialD;\n&ClockwiseContourIntegral; &ngE;"),
- "<p>\u{a0} &amp; © Æ Ď\n¾ ℋ ⅆ\n∲ ≧̸</p>",
- "should support named character references"
+ micromark(
+ "&nbsp; &amp; &copy; &AElig; &Dcaron;\n&frac34; &HilbertSpace; &DifferentialD;\n&ClockwiseContourIntegral; &ngE;"
+ ),
+ "<p>\u{a0} &amp; © Æ Ď\n¾ ℋ ⅆ\n∲ ≧̸</p>",
+ "should support named character references"
);
assert_eq!(
@@ -202,5 +206,20 @@ fn character_reference() -> Result<(), String> {
"should support turning off character references"
);
+ assert_eq!(
+ micromark_to_mdast("&nbsp; &amp; &copy; &AElig; &Dcaron;\n&frac34; &HilbertSpace; &DifferentialD;\n&ClockwiseContourIntegral; &ngE;", &Options::default())?,
+ Node::Root(Root {
+ children: vec![Node::Paragraph(Paragraph {
+ children: vec![Node::Text(Text {
+ value: "\u{a0} & © Æ Ď\n¾ ℋ ⅆ\n∲ ≧̸".to_string(),
+ position: Some(Position::new(1, 1, 0, 3, 33, 109))
+ }),],
+ position: Some(Position::new(1, 1, 0, 3, 33, 109))
+ })],
+ position: Some(Position::new(1, 1, 0, 3, 33, 109))
+ }),
+ "should support character references as `Text`s in mdast"
+ );
+
Ok(())
}
diff --git a/tests/code_fenced.rs b/tests/code_fenced.rs
index 850bd1b..2f770ce 100644
--- a/tests/code_fenced.rs
+++ b/tests/code_fenced.rs
@@ -1,5 +1,8 @@
extern crate micromark;
-use micromark::{micromark, micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{Code, Node, Position, Root},
+ micromark, micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
#[test]
@@ -272,5 +275,36 @@ fn code_fenced() -> Result<(), String> {
"should support turning off code (fenced)"
);
+ assert_eq!(
+ micromark_to_mdast(
+ "```js extra\nconsole.log(1)\nconsole.log(2)\n```",
+ &Options::default()
+ )?,
+ Node::Root(Root {
+ children: vec![Node::Code(Code {
+ lang: Some("js".to_string()),
+ meta: Some("extra".to_string()),
+ value: "console.log(1)\nconsole.log(2)".to_string(),
+ position: Some(Position::new(1, 1, 0, 4, 4, 45))
+ })],
+ position: Some(Position::new(1, 1, 0, 4, 4, 45))
+ }),
+ "should support code (fenced) as `Code`s in mdast"
+ );
+
+ assert_eq!(
+ micromark_to_mdast("```\nasd", &Options::default())?,
+ Node::Root(Root {
+ children: vec![Node::Code(Code {
+ lang: None,
+ meta: None,
+ value: "asd".to_string(),
+ position: Some(Position::new(1, 1, 0, 2, 4, 7))
+ })],
+ position: Some(Position::new(1, 1, 0, 2, 4, 7))
+ }),
+ "should support code (fenced) w/o closing fence in mdast"
+ );
+
Ok(())
}
diff --git a/tests/code_indented.rs b/tests/code_indented.rs
index bf39fa3..8a15693 100644
--- a/tests/code_indented.rs
+++ b/tests/code_indented.rs
@@ -1,5 +1,8 @@
extern crate micromark;
-use micromark::{micromark, micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{Code, Node, Position, Root},
+ micromark, micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
#[test]
@@ -190,5 +193,22 @@ fn code_indented() -> Result<(), String> {
"should support turning off code (indented, 9)"
);
+ assert_eq!(
+ micromark_to_mdast(
+ "\tconsole.log(1)\n console.log(2)\n",
+ &Options::default()
+ )?,
+ Node::Root(Root {
+ children: vec![Node::Code(Code {
+ lang: None,
+ meta: None,
+ value: "console.log(1)\nconsole.log(2)".to_string(),
+ position: Some(Position::new(1, 1, 0, 2, 19, 34))
+ })],
+ position: Some(Position::new(1, 1, 0, 3, 1, 35))
+ }),
+ "should support code (indented) as `Code`s in mdast"
+ );
+
Ok(())
}
diff --git a/tests/code_text.rs b/tests/code_text.rs
index a0ed13e..c1ba861 100644
--- a/tests/code_text.rs
+++ b/tests/code_text.rs
@@ -1,5 +1,8 @@
extern crate micromark;
-use micromark::{micromark, micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{InlineCode, Node, Paragraph, Position, Root, Text},
+ micromark, micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
#[test]
@@ -170,5 +173,30 @@ fn code_text() -> Result<(), String> {
"should support turning off code (text)"
);
+ assert_eq!(
+ micromark_to_mdast("a `alpha` b.", &Options::default())?,
+ Node::Root(Root {
+ children: vec![Node::Paragraph(Paragraph {
+ children: vec![
+ Node::Text(Text {
+ value: "a ".to_string(),
+ position: Some(Position::new(1, 1, 0, 1, 3, 2))
+ }),
+ Node::InlineCode(InlineCode {
+ value: "alpha".to_string(),
+ position: Some(Position::new(1, 3, 2, 1, 10, 9))
+ }),
+ Node::Text(Text {
+ value: " b.".to_string(),
+ position: Some(Position::new(1, 10, 9, 1, 13, 12))
+ })
+ ],
+ position: Some(Position::new(1, 1, 0, 1, 13, 12))
+ })],
+ position: Some(Position::new(1, 1, 0, 1, 13, 12))
+ }),
+ "should support code (text) as `InlineCode`s in mdast"
+ );
+
Ok(())
}
diff --git a/tests/commonmark.rs b/tests/commonmark.rs
index b5bb40e..e96623a 100644
--- a/tests/commonmark.rs
+++ b/tests/commonmark.rs
@@ -1,4 +1,4 @@
-//! CommonMark test suite.
+//! `CommonMark` test suite.
// > 👉 **Important**: this module is generated by `build.rs`.
// > It is generate from the latest CommonMark website.
diff --git a/tests/definition.rs b/tests/definition.rs
index 6f680ff..c3bf183 100644
--- a/tests/definition.rs
+++ b/tests/definition.rs
@@ -1,5 +1,8 @@
extern crate micromark;
-use micromark::{micromark, micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{Definition, Node, Position, Root},
+ micromark, micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
#[test]
@@ -491,5 +494,20 @@ fn definition() -> Result<(), String> {
"should support turning off definitions"
);
+ assert_eq!(
+ micromark_to_mdast("[a]: <b> 'c'", &Options::default())?,
+ Node::Root(Root {
+ children: vec![Node::Definition(Definition {
+ url: "b".to_string(),
+ identifier: "a".to_string(),
+ label: Some("a".to_string()),
+ title: Some("c".to_string()),
+ position: Some(Position::new(1, 1, 0, 1, 13, 12))
+ })],
+ position: Some(Position::new(1, 1, 0, 1, 13, 12))
+ }),
+ "should support definitions as `Definition`s in mdast"
+ );
+
Ok(())
}
diff --git a/tests/frontmatter.rs b/tests/frontmatter.rs
index 6195a5a..c5b0d3a 100644
--- a/tests/frontmatter.rs
+++ b/tests/frontmatter.rs
@@ -1,5 +1,8 @@
extern crate micromark;
-use micromark::{micromark, micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{Node, Position, Root, Toml, Yaml},
+ micromark, micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
#[test]
@@ -66,5 +69,29 @@ fn frontmatter() -> Result<(), String> {
"should not support a missing closing fence"
);
+ assert_eq!(
+ micromark_to_mdast("---\na: b\n---", &frontmatter)?,
+ Node::Root(Root {
+ children: vec![Node::Yaml(Yaml {
+ value: "a: b".to_string(),
+ position: Some(Position::new(1, 1, 0, 3, 4, 12))
+ })],
+ position: Some(Position::new(1, 1, 0, 3, 4, 12))
+ }),
+ "should support yaml as `Yaml`s in mdast"
+ );
+
+ assert_eq!(
+ micromark_to_mdast("+++\ntitle = \"Jupyter\"\n+++", &frontmatter)?,
+ Node::Root(Root {
+ children: vec![Node::Toml(Toml {
+ value: "title = \"Jupyter\"".to_string(),
+ position: Some(Position::new(1, 1, 0, 3, 4, 25))
+ })],
+ position: Some(Position::new(1, 1, 0, 3, 4, 25))
+ }),
+ "should support toml as `Toml`s in mdast"
+ );
+
Ok(())
}
diff --git a/tests/gfm_autolink_literal.rs b/tests/gfm_autolink_literal.rs
index bcb0797..bf99071 100644
--- a/tests/gfm_autolink_literal.rs
+++ b/tests/gfm_autolink_literal.rs
@@ -1,5 +1,8 @@
extern crate micromark;
-use micromark::{micromark, micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{Link, Node, Paragraph, Position, Root, Text},
+ micromark, micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
#[test]
@@ -2735,5 +2738,90 @@ www.a/~
"should match www (path start) like GitHub does (except for the bracket bug)"
);
+ assert_eq!(
+ micromark_to_mdast(
+ "a https://alpha.com b bravo@charlie.com c www.delta.com d xmpp:echo@foxtrot.com e mailto:golf@hotel.com f.",
+ &gfm
+ )?,
+ Node::Root(Root {
+ children: vec![Node::Paragraph(Paragraph {
+ children: vec![
+ Node::Text(Text {
+ value: "a ".to_string(),
+ position: Some(Position::new(1, 1, 0, 1, 3, 2))
+ }),
+ Node::Link(Link {
+ url: "https://alpha.com".to_string(),
+ title: None,
+ children: vec![Node::Text(Text {
+ value: "https://alpha.com".to_string(),
+ position: Some(Position::new(1, 3, 2, 1, 20, 19))
+ }),],
+ position: Some(Position::new(1, 3, 2, 1, 20, 19))
+ }),
+ Node::Text(Text {
+ value: " b ".to_string(),
+ position: Some(Position::new(1, 20, 19, 1, 23, 22))
+ }),
+ Node::Link(Link {
+ url: "mailto:bravo@charlie.com".to_string(),
+ title: None,
+ children: vec![Node::Text(Text {
+ value: "bravo@charlie.com".to_string(),
+ position: Some(Position::new(1, 23, 22, 1, 40, 39))
+ }),],
+ position: Some(Position::new(1, 23, 22, 1, 40, 39))
+ }),
+ Node::Text(Text {
+ value: " c ".to_string(),
+ position: Some(Position::new(1, 40, 39, 1, 43, 42))
+ }),
+ Node::Link(Link {
+ url: "http://www.delta.com".to_string(),
+ title: None,
+ children: vec![Node::Text(Text {
+ value: "www.delta.com".to_string(),
+ position: Some(Position::new(1, 43, 42, 1, 56, 55))
+ }),],
+ position: Some(Position::new(1, 43, 42, 1, 56, 55))
+ }),
+ Node::Text(Text {
+ value: " d ".to_string(),
+ position: Some(Position::new(1, 56, 55, 1, 59, 58))
+ }),
+ Node::Link(Link {
+ url: "xmpp:echo@foxtrot.com".to_string(),
+ title: None,
+ children: vec![Node::Text(Text {
+ value: "xmpp:echo@foxtrot.com".to_string(),
+ position: Some(Position::new(1, 59, 58, 1, 80, 79))
+ }),],
+ position: Some(Position::new(1, 59, 58, 1, 80, 79))
+ }),
+ Node::Text(Text {
+ value: " e ".to_string(),
+ position: Some(Position::new(1, 80, 79, 1, 83, 82))
+ }),
+ Node::Link(Link {
+ url: "mailto:golf@hotel.com".to_string(),
+ title: None,
+ children: vec![Node::Text(Text {
+ value: "mailto:golf@hotel.com".to_string(),
+ position: Some(Position::new(1, 83, 82, 1, 104, 103))
+ }),],
+ position: Some(Position::new(1, 83, 82, 1, 104, 103))
+ }),
+ Node::Text(Text {
+ value: " f.".to_string(),
+ position: Some(Position::new(1, 104, 103, 1, 107, 106))
+ })
+ ],
+ position: Some(Position::new(1, 1, 0, 1, 107, 106))
+ })],
+ position: Some(Position::new(1, 1, 0, 1, 107, 106))
+ }),
+ "should support GFM autolink literals as `Link`s in mdast"
+ );
+
Ok(())
}
diff --git a/tests/gfm_footnote.rs b/tests/gfm_footnote.rs
index 42c70d3..8785239 100644
--- a/tests/gfm_footnote.rs
+++ b/tests/gfm_footnote.rs
@@ -1,5 +1,8 @@
extern crate micromark;
-use micromark::{micromark, micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{FootnoteDefinition, FootnoteReference, Node, Paragraph, Position, Root, Text},
+ micromark, micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
#[test]
@@ -1597,5 +1600,45 @@ multi-paragraph list items. <a href="#user-content-fnref-longnote" data-footnote
"should match references and definitions like GitHub"
);
+ assert_eq!(
+ micromark_to_mdast("[^a]: b\n\tc\n\nd [^a] e.", &gfm)?,
+ Node::Root(Root {
+ children: vec![
+ Node::FootnoteDefinition(FootnoteDefinition {
+ children: vec![Node::Paragraph(Paragraph {
+ children: vec![Node::Text(Text {
+ value: "b\nc".to_string(),
+ position: Some(Position::new(1, 7, 6, 2, 6, 10))
+ })],
+ position: Some(Position::new(1, 7, 6, 2, 6, 10))
+ })],
+ identifier: "a".to_string(),
+ label: Some("a".to_string()),
+ position: Some(Position::new(1, 1, 0, 3, 1, 11))
+ }),
+ Node::Paragraph(Paragraph {
+ children: vec![
+ Node::Text(Text {
+ value: "d ".to_string(),
+ position: Some(Position::new(4, 1, 12, 4, 3, 14))
+ }),
+ Node::FootnoteReference(FootnoteReference {
+ identifier: "a".to_string(),
+ label: Some("a".to_string()),
+ position: Some(Position::new(4, 3, 14, 4, 7, 18))
+ }),
+ Node::Text(Text {
+ value: " e.".to_string(),
+ position: Some(Position::new(4, 7, 18, 4, 10, 21))
+ })
+ ],
+ position: Some(Position::new(4, 1, 12, 4, 10, 21))
+ })
+ ],
+ position: Some(Position::new(1, 1, 0, 4, 10, 21))
+ }),
+ "should support GFM footnotes as `FootnoteDefinition`, `FootnoteReference`s in mdast"
+ );
+
Ok(())
}
diff --git a/tests/gfm_strikethrough.rs b/tests/gfm_strikethrough.rs
index b8c3e1f..d669a96 100644
--- a/tests/gfm_strikethrough.rs
+++ b/tests/gfm_strikethrough.rs
@@ -1,5 +1,8 @@
extern crate micromark;
-use micromark::{micromark, micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{Delete, Node, Paragraph, Position, Root, Text},
+ micromark, micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
#[test]
@@ -385,5 +388,33 @@ u ~**xxx**~ zzz
"should support strikethrough w/ one tilde if `singleTilde: true`"
);
+ assert_eq!(
+ micromark_to_mdast("a ~~alpha~~ b.", &gfm)?,
+ Node::Root(Root {
+ children: vec![Node::Paragraph(Paragraph {
+ children: vec![
+ Node::Text(Text {
+ value: "a ".to_string(),
+ position: Some(Position::new(1, 1, 0, 1, 3, 2))
+ }),
+ Node::Delete(Delete {
+ children: vec![Node::Text(Text {
+ value: "alpha".to_string(),
+ position: Some(Position::new(1, 5, 4, 1, 10, 9))
+ }),],
+ position: Some(Position::new(1, 3, 2, 1, 12, 11))
+ }),
+ Node::Text(Text {
+ value: " b.".to_string(),
+ position: Some(Position::new(1, 12, 11, 1, 15, 14))
+ }),
+ ],
+ position: Some(Position::new(1, 1, 0, 1, 15, 14))
+ })],
+ position: Some(Position::new(1, 1, 0, 1, 15, 14))
+ }),
+ "should support GFM strikethrough as `Delete`s in mdast"
+ );
+
Ok(())
}
diff --git a/tests/gfm_table.rs b/tests/gfm_table.rs
index 8c46a30..17b31da 100644
--- a/tests/gfm_table.rs
+++ b/tests/gfm_table.rs
@@ -1,5 +1,8 @@
extern crate micromark;
-use micromark::{micromark, micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{AlignKind, InlineCode, Node, Position, Root, Table, TableCell, TableRow, Text},
+ micromark, micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
#[test]
@@ -1784,5 +1787,132 @@ normal escape: <a href="https://github.com/github/cmark-gfm/issues/277">https://
"should match loose escapes like GitHub"
);
+ assert_eq!(
+ micromark_to_mdast(
+ "| none | left | right | center |\n| - | :- | -: | :-: |\n| a |\n| b | c | d | e | f |",
+ &gfm
+ )?,
+ Node::Root(Root {
+ children: vec![Node::Table(Table {
+ align: vec![
+ AlignKind::None,
+ AlignKind::Left,
+ AlignKind::Right,
+ AlignKind::Center
+ ],
+ children: vec![
+ Node::TableRow(TableRow {
+ children: vec![
+ Node::TableCell(TableCell {
+ children: vec![Node::Text(Text {
+ value: "none".to_string(),
+ position: Some(Position::new(1, 3, 2, 1, 7, 6))
+ }),],
+ position: Some(Position::new(1, 1, 0, 1, 8, 7))
+ }),
+ Node::TableCell(TableCell {
+ children: vec![Node::Text(Text {
+ value: "left".to_string(),
+ position: Some(Position::new(1, 10, 9, 1, 14, 13))
+ }),],
+ position: Some(Position::new(1, 8, 7, 1, 15, 14))
+ }),
+ Node::TableCell(TableCell {
+ children: vec![Node::Text(Text {
+ value: "right".to_string(),
+ position: Some(Position::new(1, 17, 16, 1, 22, 21))
+ }),],
+ position: Some(Position::new(1, 15, 14, 1, 23, 22))
+ }),
+ Node::TableCell(TableCell {
+ children: vec![Node::Text(Text {
+ value: "center".to_string(),
+ position: Some(Position::new(1, 25, 24, 1, 31, 30))
+ }),],
+ position: Some(Position::new(1, 23, 22, 1, 33, 32))
+ }),
+ ],
+ position: Some(Position::new(1, 1, 0, 1, 33, 32))
+ }),
+ Node::TableRow(TableRow {
+ children: vec![Node::TableCell(TableCell {
+ children: vec![Node::Text(Text {
+ value: "a".to_string(),
+ position: Some(Position::new(3, 3, 57, 3, 4, 58))
+ }),],
+ position: Some(Position::new(3, 1, 55, 3, 6, 60))
+ }),],
+ position: Some(Position::new(3, 1, 55, 3, 6, 60))
+ }),
+ Node::TableRow(TableRow {
+ children: vec![
+ Node::TableCell(TableCell {
+ children: vec![Node::Text(Text {
+ value: "b".to_string(),
+ position: Some(Position::new(4, 3, 63, 4, 4, 64))
+ }),],
+ position: Some(Position::new(4, 1, 61, 4, 5, 65))
+ }),
+ Node::TableCell(TableCell {
+ children: vec![Node::Text(Text {
+ value: "c".to_string(),
+ position: Some(Position::new(4, 7, 67, 4, 8, 68))
+ }),],
+ position: Some(Position::new(4, 5, 65, 4, 9, 69))
+ }),
+ Node::TableCell(TableCell {
+ children: vec![Node::Text(Text {
+ value: "d".to_string(),
+ position: Some(Position::new(4, 11, 71, 4, 12, 72))
+ }),],
+ position: Some(Position::new(4, 9, 69, 4, 13, 73))
+ }),
+ Node::TableCell(TableCell {
+ children: vec![Node::Text(Text {
+ value: "e".to_string(),
+ position: Some(Position::new(4, 15, 75, 4, 16, 76))
+ }),],
+ position: Some(Position::new(4, 13, 73, 4, 17, 77))
+ }),
+ Node::TableCell(TableCell {
+ children: vec![Node::Text(Text {
+ value: "f".to_string(),
+ position: Some(Position::new(4, 19, 79, 4, 20, 80))
+ }),],
+ position: Some(Position::new(4, 17, 77, 4, 22, 82))
+ }),
+ ],
+ position: Some(Position::new(4, 1, 61, 4, 22, 82))
+ }),
+ ],
+ position: Some(Position::new(1, 1, 0, 4, 22, 82))
+ })],
+ position: Some(Position::new(1, 1, 0, 4, 22, 82))
+ }),
+ "should support GFM tables as `Table`, `TableRow`, `TableCell`s in mdast"
+ );
+
+ assert_eq!(
+ micromark_to_mdast("| `a\\|b` |\n| - |", &gfm)?,
+ Node::Root(Root {
+ children: vec![Node::Table(Table {
+ align: vec![AlignKind::None,],
+ children: vec![Node::TableRow(TableRow {
+ children: vec![Node::TableCell(TableCell {
+ children: vec![Node::InlineCode(InlineCode {
+ value: "a|b".to_string(),
+ position: Some(Position::new(1, 3, 2, 1, 9, 8))
+ }),],
+ position: Some(Position::new(1, 1, 0, 1, 11, 10))
+ }),],
+ position: Some(Position::new(1, 1, 0, 1, 11, 10))
+ }),],
+ position: Some(Position::new(1, 1, 0, 2, 6, 16))
+ })],
+ position: Some(Position::new(1, 1, 0, 2, 6, 16))
+ }),
+ "should support weird pipe escapes in code in tables"
+ );
+
Ok(())
}
diff --git a/tests/gfm_task_list_item.rs b/tests/gfm_task_list_item.rs
index b824730..ae6c548 100644
--- a/tests/gfm_task_list_item.rs
+++ b/tests/gfm_task_list_item.rs
@@ -1,5 +1,8 @@
extern crate micromark;
-use micromark::{micromark, micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{List, ListItem, Node, Paragraph, Position, Root, Text},
+ micromark, micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
#[test]
@@ -240,5 +243,57 @@ Text.</li>
"should handle things like GitHub"
);
+ assert_eq!(
+ micromark_to_mdast("* [x] a\n* [ ] b\n* c", &gfm)?,
+ Node::Root(Root {
+ children: vec![Node::List(List {
+ ordered: false,
+ spread: false,
+ start: None,
+ children: vec![
+ Node::ListItem(ListItem {
+ checked: Some(true),
+ spread: false,
+ children: vec![Node::Paragraph(Paragraph {
+ children: vec![Node::Text(Text {
+ value: "a".to_string(),
+ position: Some(Position::new(1, 7, 6, 1, 8, 7))
+ }),],
+ position: Some(Position::new(1, 7, 6, 1, 8, 7))
+ })],
+ position: Some(Position::new(1, 1, 0, 1, 8, 7))
+ }),
+ Node::ListItem(ListItem {
+ checked: Some(false),
+ spread: false,
+ children: vec![Node::Paragraph(Paragraph {
+ children: vec![Node::Text(Text {
+ value: "b".to_string(),
+ position: Some(Position::new(2, 7, 14, 2, 8, 15))
+ }),],
+ position: Some(Position::new(2, 7, 14, 2, 8, 15))
+ })],
+ position: Some(Position::new(2, 1, 8, 2, 8, 15))
+ }),
+ Node::ListItem(ListItem {
+ checked: None,
+ spread: false,
+ children: vec![Node::Paragraph(Paragraph {
+ children: vec![Node::Text(Text {
+ value: "c".to_string(),
+ position: Some(Position::new(3, 3, 18, 3, 4, 19))
+ }),],
+ position: Some(Position::new(3, 3, 18, 3, 4, 19))
+ })],
+ position: Some(Position::new(3, 1, 16, 3, 4, 19))
+ }),
+ ],
+ position: Some(Position::new(1, 1, 0, 3, 4, 19))
+ })],
+ position: Some(Position::new(1, 1, 0, 3, 4, 19))
+ }),
+ "should support task list items as `checked` fields on `ListItem`s in mdast"
+ );
+
Ok(())
}
diff --git a/tests/hard_break_escape.rs b/tests/hard_break_escape.rs
index 2510860..ced3b3d 100644
--- a/tests/hard_break_escape.rs
+++ b/tests/hard_break_escape.rs
@@ -1,5 +1,8 @@
extern crate micromark;
-use micromark::{micromark, micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{Break, Node, Paragraph, Position, Root, Text},
+ micromark, micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
#[test]
@@ -55,5 +58,29 @@ fn hard_break_escape() -> Result<(), String> {
"should support turning off hard break (escape)"
);
+ assert_eq!(
+ micromark_to_mdast("a\\\nb.", &Options::default())?,
+ Node::Root(Root {
+ children: vec![Node::Paragraph(Paragraph {
+ children: vec![
+ Node::Text(Text {
+ value: "a".to_string(),
+ position: Some(Position::new(1, 1, 0, 1, 2, 1))
+ }),
+ Node::Break(Break {
+ position: Some(Position::new(1, 2, 1, 2, 1, 3))
+ }),
+ Node::Text(Text {
+ value: "b.".to_string(),
+ position: Some(Position::new(2, 1, 3, 2, 3, 5))
+ }),
+ ],
+ position: Some(Position::new(1, 1, 0, 2, 3, 5))
+ })],
+ position: Some(Position::new(1, 1, 0, 2, 3, 5))
+ }),
+ "should support hard break (escape) as `Break`s in mdast"
+ );
+
Ok(())
}
diff --git a/tests/hard_break_trailing.rs b/tests/hard_break_trailing.rs
index b5577fd..042f8f0 100644
--- a/tests/hard_break_trailing.rs
+++ b/tests/hard_break_trailing.rs
@@ -1,5 +1,8 @@
extern crate micromark;
-use micromark::{micromark, micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{Break, Node, Paragraph, Position, Root, Text},
+ micromark, micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
#[test]
@@ -121,5 +124,29 @@ fn hard_break_trailing() -> Result<(), String> {
"should support turning off hard break (trailing)"
);
+ assert_eq!(
+ micromark_to_mdast("a \nb.", &Options::default())?,
+ Node::Root(Root {
+ children: vec![Node::Paragraph(Paragraph {
+ children: vec![
+ Node::Text(Text {
+ value: "a".to_string(),
+ position: Some(Position::new(1, 1, 0, 1, 2, 1))
+ }),
+ Node::Break(Break {
+ position: Some(Position::new(1, 2, 1, 2, 1, 4))
+ }),
+ Node::Text(Text {
+ value: "b.".to_string(),
+ position: Some(Position::new(2, 1, 4, 2, 3, 6))
+ }),
+ ],
+ position: Some(Position::new(1, 1, 0, 2, 3, 6))
+ })],
+ position: Some(Position::new(1, 1, 0, 2, 3, 6))
+ }),
+ "should support hard break (trailing) as `Break`s in mdast"
+ );
+
Ok(())
}
diff --git a/tests/heading_atx.rs b/tests/heading_atx.rs
index 1bd437c..da83ff5 100644
--- a/tests/heading_atx.rs
+++ b/tests/heading_atx.rs
@@ -1,5 +1,8 @@
extern crate micromark;
-use micromark::{micromark, micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{Heading, Node, Position, Root, Text},
+ micromark, micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
#[test]
@@ -217,5 +220,21 @@ fn heading_atx() -> Result<(), String> {
"should support turning off heading (atx)"
);
+ assert_eq!(
+ micromark_to_mdast("## alpha #", &Options::default())?,
+ Node::Root(Root {
+ children: vec![Node::Heading(Heading {
+ depth: 2,
+ children: vec![Node::Text(Text {
+ value: "alpha".to_string(),
+ position: Some(Position::new(1, 4, 3, 1, 9, 8))
+ }),],
+ position: Some(Position::new(1, 1, 0, 1, 11, 10))
+ })],
+ position: Some(Position::new(1, 1, 0, 1, 11, 10))
+ }),
+ "should support heading (atx) as `Heading`s in mdast"
+ );
+
Ok(())
}
diff --git a/tests/heading_setext.rs b/tests/heading_setext.rs
index b2889f5..4292ed2 100644
--- a/tests/heading_setext.rs
+++ b/tests/heading_setext.rs
@@ -1,5 +1,8 @@
extern crate micromark;
-use micromark::{micromark, micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{Heading, Node, Position, Root, Text},
+ micromark, micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
#[test]
@@ -284,5 +287,21 @@ fn heading_setext() -> Result<(), String> {
"should support turning off setext underlines"
);
+ assert_eq!(
+ micromark_to_mdast("alpha\nbravo\n==", &Options::default())?,
+ Node::Root(Root {
+ children: vec![Node::Heading(Heading {
+ depth: 1,
+ children: vec![Node::Text(Text {
+ value: "alpha\nbravo".to_string(),
+ position: Some(Position::new(1, 1, 0, 2, 6, 11))
+ }),],
+ position: Some(Position::new(1, 1, 0, 3, 3, 14))
+ })],
+ position: Some(Position::new(1, 1, 0, 3, 3, 14))
+ }),
+ "should support heading (atx) as `Heading`s in mdast"
+ );
+
Ok(())
}
diff --git a/tests/html_flow.rs b/tests/html_flow.rs
index c411036..2605105 100644
--- a/tests/html_flow.rs
+++ b/tests/html_flow.rs
@@ -1,5 +1,8 @@
extern crate micromark;
-use micromark::{micromark, micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{Html, Node, Position, Root},
+ micromark, micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
#[test]
@@ -36,6 +39,18 @@ fn html_flow() -> Result<(), String> {
"should support turning off html (flow)"
);
+ assert_eq!(
+ micromark_to_mdast("<div>\nstuff\n</div>", &Options::default())?,
+ Node::Root(Root {
+ children: vec![Node::Html(Html {
+ value: "<div>\nstuff\n</div>".to_string(),
+ position: Some(Position::new(1, 1, 0, 3, 7, 18))
+ })],
+ position: Some(Position::new(1, 1, 0, 3, 7, 18))
+ }),
+ "should support HTML (flow) as `Html`s in mdast"
+ );
+
Ok(())
}
diff --git a/tests/html_text.rs b/tests/html_text.rs
index 8fdbbd2..d35bdba 100644
--- a/tests/html_text.rs
+++ b/tests/html_text.rs
@@ -1,5 +1,8 @@
extern crate micromark;
-use micromark::{micromark, micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{Html, Node, Paragraph, Position, Root, Text},
+ micromark, micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
#[test]
@@ -433,5 +436,38 @@ micromark_with_options("<x> a", &danger)?,
"should support turning off html (text)"
);
+ assert_eq!(
+ micromark_to_mdast("alpha <i>bravo</b> charlie.", &Options::default())?,
+ Node::Root(Root {
+ children: vec![Node::Paragraph(Paragraph {
+ children: vec![
+ Node::Text(Text {
+ value: "alpha ".to_string(),
+ position: Some(Position::new(1, 1, 0, 1, 7, 6))
+ }),
+ Node::Html(Html {
+ value: "<i>".to_string(),
+ position: Some(Position::new(1, 7, 6, 1, 10, 9))
+ }),
+ Node::Text(Text {
+ value: "bravo".to_string(),
+ position: Some(Position::new(1, 10, 9, 1, 15, 14))
+ }),
+ Node::Html(Html {
+ value: "</b>".to_string(),
+ position: Some(Position::new(1, 15, 14, 1, 19, 18))
+ }),
+ Node::Text(Text {
+ value: " charlie.".to_string(),
+ position: Some(Position::new(1, 19, 18, 1, 28, 27))
+ })
+ ],
+ position: Some(Position::new(1, 1, 0, 1, 28, 27))
+ })],
+ position: Some(Position::new(1, 1, 0, 1, 28, 27))
+ }),
+ "should support HTML (text) as `Html`s in mdast"
+ );
+
Ok(())
}
diff --git a/tests/image.rs b/tests/image.rs
index 966b653..40d1449 100644
--- a/tests/image.rs
+++ b/tests/image.rs
@@ -1,5 +1,10 @@
extern crate micromark;
-use micromark::{micromark, micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{
+ Definition, Image, ImageReference, Node, Paragraph, Position, ReferenceKind, Root, Text,
+ },
+ micromark, micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
#[test]
@@ -225,5 +230,106 @@ fn image() -> Result<(), String> {
"should allow non-http protocols w/ `allowDangerousProtocol`"
);
+ assert_eq!(
+ micromark_to_mdast(
+ "a ![alpha]() b ![bravo](charlie 'delta') c.",
+ &Options::default()
+ )?,
+ Node::Root(Root {
+ children: vec![Node::Paragraph(Paragraph {
+ children: vec![
+ Node::Text(Text {
+ value: "a ".to_string(),
+ position: Some(Position::new(1, 1, 0, 1, 3, 2))
+ }),
+ Node::Image(Image {
+ alt: "alpha".to_string(),
+ url: String::new(),
+ title: None,
+ position: Some(Position::new(1, 3, 2, 1, 13, 12))
+ }),
+ Node::Text(Text {
+ value: " b ".to_string(),
+ position: Some(Position::new(1, 13, 12, 1, 16, 15))
+ }),
+ Node::Image(Image {
+ alt: "bravo".to_string(),
+ url: "charlie".to_string(),
+ title: Some("delta".to_string()),
+ position: Some(Position::new(1, 16, 15, 1, 41, 40))
+ }),
+ Node::Text(Text {
+ value: " c.".to_string(),
+ position: Some(Position::new(1, 41, 40, 1, 44, 43))
+ })
+ ],
+ position: Some(Position::new(1, 1, 0, 1, 44, 43))
+ })],
+ position: Some(Position::new(1, 1, 0, 1, 44, 43))
+ }),
+ "should support image (resource) as `Image`s in mdast"
+ );
+
+ assert_eq!(
+ micromark_to_mdast(
+ "[x]: y\n\na ![x] b ![x][] c ![d][x] e.",
+ &Options::default()
+ )?,
+ Node::Root(Root {
+ children: vec![
+ Node::Definition(Definition {
+ identifier: "x".to_string(),
+ label: Some("x".to_string()),
+ url: "y".to_string(),
+ title: None,
+ position: Some(Position::new(1, 1, 0, 1, 7, 6))
+ }),
+ Node::Paragraph(Paragraph {
+ children: vec![
+ Node::Text(Text {
+ value: "a ".to_string(),
+ position: Some(Position::new(3, 1, 8, 3, 3, 10))
+ }),
+ Node::ImageReference(ImageReference {
+ reference_kind: ReferenceKind::Shortcut,
+ identifier: "x".to_string(),
+ label: Some("x".to_string()),
+ alt: "x".to_string(),
+ position: Some(Position::new(3, 3, 10, 3, 7, 14))
+ }),
+ Node::Text(Text {
+ value: " b ".to_string(),
+ position: Some(Position::new(3, 7, 14, 3, 10, 17))
+ }),
+ Node::ImageReference(ImageReference {
+ reference_kind: ReferenceKind::Collapsed,
+ identifier: "x".to_string(),
+ label: Some("x".to_string()),
+ alt: "x".to_string(),
+ position: Some(Position::new(3, 10, 17, 3, 16, 23))
+ }),
+ Node::Text(Text {
+ value: " c ".to_string(),
+ position: Some(Position::new(3, 16, 23, 3, 19, 26))
+ }),
+ Node::ImageReference(ImageReference {
+ reference_kind: ReferenceKind::Full,
+ identifier: "x".to_string(),
+ label: Some("x".to_string()),
+ alt: "d".to_string(),
+ position: Some(Position::new(3, 19, 26, 3, 26, 33))
+ }),
+ Node::Text(Text {
+ value: " e.".to_string(),
+ position: Some(Position::new(3, 26, 33, 3, 29, 36))
+ }),
+ ],
+ position: Some(Position::new(3, 1, 8, 3, 29, 36))
+ }),
+ ],
+ position: Some(Position::new(1, 1, 0, 3, 29, 36))
+ }),
+ "should support image (reference) as `ImageReference`s in mdast"
+ );
Ok(())
}
diff --git a/tests/link_reference.rs b/tests/link_reference.rs
index 9c853f7..d1d6785 100644
--- a/tests/link_reference.rs
+++ b/tests/link_reference.rs
@@ -1,5 +1,8 @@
extern crate micromark;
-use micromark::{micromark, micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{Definition, LinkReference, Node, Paragraph, Position, ReferenceKind, Root, Text},
+ micromark, micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
#[test]
@@ -414,5 +417,73 @@ fn link_reference() -> Result<(), String> {
"should support turning off label end"
);
+ assert_eq!(
+ micromark_to_mdast("[x]: y\n\na [x] b [x][] c [d][x] e.", &Options::default())?,
+ Node::Root(Root {
+ children: vec![
+ Node::Definition(Definition {
+ identifier: "x".to_string(),
+ label: Some("x".to_string()),
+ url: "y".to_string(),
+ title: None,
+ position: Some(Position::new(1, 1, 0, 1, 7, 6))
+ }),
+ Node::Paragraph(Paragraph {
+ children: vec![
+ Node::Text(Text {
+ value: "a ".to_string(),
+ position: Some(Position::new(3, 1, 8, 3, 3, 10))
+ }),
+ Node::LinkReference(LinkReference {
+ reference_kind: ReferenceKind::Shortcut,
+ identifier: "x".to_string(),
+ label: Some("x".to_string()),
+ children: vec![Node::Text(Text {
+ value: "x".to_string(),
+ position: Some(Position::new(3, 4, 11, 3, 5, 12))
+ }),],
+ position: Some(Position::new(3, 3, 10, 3, 6, 13))
+ }),
+ Node::Text(Text {
+ value: " b ".to_string(),
+ position: Some(Position::new(3, 6, 13, 3, 9, 16))
+ }),
+ Node::LinkReference(LinkReference {
+ reference_kind: ReferenceKind::Collapsed,
+ identifier: "x".to_string(),
+ label: Some("x".to_string()),
+ children: vec![Node::Text(Text {
+ value: "x".to_string(),
+ position: Some(Position::new(3, 10, 17, 3, 11, 18))
+ }),],
+ position: Some(Position::new(3, 9, 16, 3, 14, 21))
+ }),
+ Node::Text(Text {
+ value: " c ".to_string(),
+ position: Some(Position::new(3, 14, 21, 3, 17, 24))
+ }),
+ Node::LinkReference(LinkReference {
+ reference_kind: ReferenceKind::Full,
+ identifier: "x".to_string(),
+ label: Some("x".to_string()),
+ children: vec![Node::Text(Text {
+ value: "d".to_string(),
+ position: Some(Position::new(3, 18, 25, 3, 19, 26))
+ }),],
+ position: Some(Position::new(3, 17, 24, 3, 23, 30))
+ }),
+ Node::Text(Text {
+ value: " e.".to_string(),
+ position: Some(Position::new(3, 23, 30, 3, 26, 33))
+ }),
+ ],
+ position: Some(Position::new(3, 1, 8, 3, 26, 33))
+ }),
+ ],
+ position: Some(Position::new(1, 1, 0, 3, 26, 33))
+ }),
+ "should support link (reference) as `LinkReference`s in mdast"
+ );
+
Ok(())
}
diff --git a/tests/link_resource.rs b/tests/link_resource.rs
index 6bcbb8c..a296410 100644
--- a/tests/link_resource.rs
+++ b/tests/link_resource.rs
@@ -1,5 +1,8 @@
extern crate micromark;
-use micromark::{micromark, micromark_with_options, Options};
+use micromark::{
+ mdast::{Link, Node, Paragraph, Position, Root, Text},
+ micromark, micromark_to_mdast, micromark_with_options, Options,
+};
use pretty_assertions::assert_eq;
#[test]
@@ -458,5 +461,51 @@ fn link_resource() -> Result<(), String> {
"should support a single NUL character as a link resource"
);
+ assert_eq!(
+ micromark_to_mdast(
+ "a [alpha]() b [bravo](charlie 'delta') c.",
+ &Options::default()
+ )?,
+ Node::Root(Root {
+ children: vec![Node::Paragraph(Paragraph {
+ children: vec![
+ Node::Text(Text {
+ value: "a ".to_string(),
+ position: Some(Position::new(1, 1, 0, 1, 3, 2))
+ }),
+ Node::Link(Link {
+ url: String::new(),
+ title: None,
+ children: vec![Node::Text(Text {
+ value: "alpha".to_string(),
+ position: Some(Position::new(1, 4, 3, 1, 9, 8))
+ }),],
+ position: Some(Position::new(1, 3, 2, 1, 12, 11))
+ }),
+ Node::Text(Text {
+ value: " b ".to_string(),
+ position: Some(Position::new(1, 12, 11, 1, 15, 14))
+ }),
+ Node::Link(Link {
+ url: "charlie".to_string(),
+ title: Some("delta".to_string()),
+ children: vec![Node::Text(Text {
+ value: "bravo".to_string(),
+ position: Some(Position::new(1, 16, 15, 1, 21, 20))
+ }),],
+ position: Some(Position::new(1, 15, 14, 1, 39, 38))
+ }),
+ Node::Text(Text {
+ value: " c.".to_string(),
+ position: Some(Position::new(1, 39, 38, 1, 42, 41))
+ })
+ ],
+ position: Some(Position::new(1, 1, 0, 1, 42, 41))
+ })],
+ position: Some(Position::new(1, 1, 0, 1, 42, 41))
+ }),
+ "should support link (resource) as `Link`s in mdast"
+ );
+
Ok(())
}
diff --git a/tests/list.rs b/tests/list.rs
index 4007251..95beeec 100644
--- a/tests/list.rs
+++ b/tests/list.rs
@@ -1,5 +1,8 @@
extern crate micromark;
-use micromark::{micromark, micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{List, ListItem, Node, Paragraph, Position, Root, Text},
+ micromark, micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
#[test]
@@ -578,5 +581,106 @@ fn list() -> Result<(), String> {
"should support turning off lists"
);
+ assert_eq!(
+ micromark_to_mdast("* a", &Options::default())?,
+ Node::Root(Root {
+ children: vec![Node::List(List {
+ ordered: false,
+ spread: false,
+ start: None,
+ children: vec![Node::ListItem(ListItem {
+ checked: None,
+ spread: false,
+ children: vec![Node::Paragraph(Paragraph {
+ children: vec![Node::Text(Text {
+ value: "a".to_string(),
+ position: Some(Position::new(1, 3, 2, 1, 4, 3))
+ }),],
+ position: Some(Position::new(1, 3, 2, 1, 4, 3))
+ })],
+ position: Some(Position::new(1, 1, 0, 1, 4, 3))
+ })],
+ position: Some(Position::new(1, 1, 0, 1, 4, 3))
+ })],
+ position: Some(Position::new(1, 1, 0, 1, 4, 3))
+ }),
+ "should support lists, list items as `List`, `ListItem`s in mdast"
+ );
+
+ assert_eq!(
+ micromark_to_mdast("3. a", &Options::default())?,
+ Node::Root(Root {
+ children: vec![Node::List(List {
+ ordered: true,
+ spread: false,
+ start: Some(3),
+ children: vec![Node::ListItem(ListItem {
+ checked: None,
+ spread: false,
+ children: vec![Node::Paragraph(Paragraph {
+ children: vec![Node::Text(Text {
+ value: "a".to_string(),
+ position: Some(Position::new(1, 4, 3, 1, 5, 4))
+ }),],
+ position: Some(Position::new(1, 4, 3, 1, 5, 4))
+ })],
+ position: Some(Position::new(1, 1, 0, 1, 5, 4))
+ })],
+ position: Some(Position::new(1, 1, 0, 1, 5, 4))
+ })],
+ position: Some(Position::new(1, 1, 0, 1, 5, 4))
+ }),
+ "should support `start` fields on `List` w/ `ordered: true` in mdast"
+ );
+
+ assert_eq!(
+ micromark_to_mdast("* a\n\n b\n* c", &Options::default())?,
+ Node::Root(Root {
+ children: vec![Node::List(List {
+ ordered: false,
+ spread: false,
+ start: None,
+ children: vec![
+ Node::ListItem(ListItem {
+ checked: None,
+ spread: true,
+ children: vec![
+ Node::Paragraph(Paragraph {
+ children: vec![Node::Text(Text {
+ value: "a".to_string(),
+ position: Some(Position::new(1, 3, 2, 1, 4, 3))
+ }),],
+ position: Some(Position::new(1, 3, 2, 1, 4, 3))
+ }),
+ Node::Paragraph(Paragraph {
+ children: vec![Node::Text(Text {
+ value: "b".to_string(),
+ position: Some(Position::new(3, 3, 7, 3, 4, 8))
+ }),],
+ position: Some(Position::new(3, 3, 7, 3, 4, 8))
+ })
+ ],
+ position: Some(Position::new(1, 1, 0, 3, 4, 8))
+ }),
+ Node::ListItem(ListItem {
+ checked: None,
+ spread: false,
+ children: vec![Node::Paragraph(Paragraph {
+ children: vec![Node::Text(Text {
+ value: "c".to_string(),
+ position: Some(Position::new(4, 3, 11, 4, 4, 12))
+ }),],
+ position: Some(Position::new(4, 3, 11, 4, 4, 12))
+ })],
+ position: Some(Position::new(4, 1, 9, 4, 4, 12))
+ })
+ ],
+ position: Some(Position::new(1, 1, 0, 4, 4, 12))
+ })],
+ position: Some(Position::new(1, 1, 0, 4, 4, 12))
+ }),
+ "should support `spread` fields on `List`, `ListItem`s in mdast"
+ );
+
Ok(())
}
diff --git a/tests/math_flow.rs b/tests/math_flow.rs
index c277326..3797e83 100644
--- a/tests/math_flow.rs
+++ b/tests/math_flow.rs
@@ -1,5 +1,8 @@
extern crate micromark;
-use micromark::{micromark, micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{Math, Node, Position, Root},
+ micromark, micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
#[test]
@@ -248,5 +251,18 @@ fn math_flow() -> Result<(), String> {
"should not support lazyness (3)"
);
+ assert_eq!(
+ micromark_to_mdast("$$extra\nabc\ndef\n$$", &math)?,
+ Node::Root(Root {
+ children: vec![Node::Math(Math {
+ meta: Some("extra".to_string()),
+ value: "abc\ndef".to_string(),
+ position: Some(Position::new(1, 1, 0, 4, 3, 18))
+ })],
+ position: Some(Position::new(1, 1, 0, 4, 3, 18))
+ }),
+ "should support math (flow) as `Math`s in mdast"
+ );
+
Ok(())
}
diff --git a/tests/math_text.rs b/tests/math_text.rs
index 7b53268..9e20d6e 100644
--- a/tests/math_text.rs
+++ b/tests/math_text.rs
@@ -1,5 +1,8 @@
extern crate micromark;
-use micromark::{micromark, micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{InlineMath, Node, Paragraph, Position, Root, Text},
+ micromark, micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
#[test]
@@ -192,5 +195,30 @@ fn math_text() -> Result<(), String> {
"should support an escaped initial dollar"
);
+ assert_eq!(
+ micromark_to_mdast("a $alpha$ b.", &math)?,
+ Node::Root(Root {
+ children: vec![Node::Paragraph(Paragraph {
+ children: vec![
+ Node::Text(Text {
+ value: "a ".to_string(),
+ position: Some(Position::new(1, 1, 0, 1, 3, 2))
+ }),
+ Node::InlineMath(InlineMath {
+ value: "alpha".to_string(),
+ position: Some(Position::new(1, 3, 2, 1, 10, 9))
+ }),
+ Node::Text(Text {
+ value: " b.".to_string(),
+ position: Some(Position::new(1, 10, 9, 1, 13, 12))
+ })
+ ],
+ position: Some(Position::new(1, 1, 0, 1, 13, 12))
+ })],
+ position: Some(Position::new(1, 1, 0, 1, 13, 12))
+ }),
+ "should support math (text) as `InlineMath`s in mdast"
+ );
+
Ok(())
}
diff --git a/tests/mdx_esm.rs b/tests/mdx_esm.rs
index f1ea122..0f8888b 100644
--- a/tests/mdx_esm.rs
+++ b/tests/mdx_esm.rs
@@ -1,6 +1,9 @@
extern crate micromark;
mod test_utils;
-use micromark::{micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{MdxjsEsm, Node, Position, Root},
+ micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
use test_utils::{parse_esm, parse_expression};
@@ -237,5 +240,17 @@ fn mdx_esm() -> Result<(), String> {
);
}
+ assert_eq!(
+ micromark_to_mdast("import a from 'b'\nexport {a}", &swc)?,
+ Node::Root(Root {
+ children: vec![Node::MdxjsEsm(MdxjsEsm {
+ value: "import a from 'b'\nexport {a}".to_string(),
+ position: Some(Position::new(1, 1, 0, 2, 11, 28))
+ })],
+ position: Some(Position::new(1, 1, 0, 2, 11, 28))
+ }),
+ "should support mdx esm as `MdxjsEsm`s in mdast"
+ );
+
Ok(())
}
diff --git a/tests/mdx_expression_flow.rs b/tests/mdx_expression_flow.rs
index 81a31a7..1d50468 100644
--- a/tests/mdx_expression_flow.rs
+++ b/tests/mdx_expression_flow.rs
@@ -1,6 +1,9 @@
extern crate micromark;
mod test_utils;
-use micromark::{micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{MdxFlowExpression, Node, Position, Root},
+ micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
use test_utils::{parse_esm, parse_expression};
@@ -81,6 +84,18 @@ fn mdx_expression_flow_agnostic() -> Result<(), String> {
"should not support lazyness (4)"
);
+ assert_eq!(
+ micromark_to_mdast("{alpha +\nbravo}", &mdx)?,
+ Node::Root(Root {
+ children: vec![Node::MdxFlowExpression(MdxFlowExpression {
+ value: "alpha +\nbravo".to_string(),
+ position: Some(Position::new(1, 1, 0, 2, 7, 15))
+ })],
+ position: Some(Position::new(1, 1, 0, 2, 7, 15))
+ }),
+ "should support mdx expressions (flow) as `MdxFlowExpression`s in mdast"
+ );
+
Ok(())
}
diff --git a/tests/mdx_expression_text.rs b/tests/mdx_expression_text.rs
index 3a48965..997e7de 100644
--- a/tests/mdx_expression_text.rs
+++ b/tests/mdx_expression_text.rs
@@ -1,6 +1,9 @@
extern crate micromark;
mod test_utils;
-use micromark::{micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{MdxTextExpression, Node, Paragraph, Position, Root, Text},
+ micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
use test_utils::{parse_esm, parse_expression};
@@ -191,6 +194,31 @@ fn mdx_expression_text_agnostic() -> Result<(), String> {
"should support expressions as the first thing when following by other things"
);
+ assert_eq!(
+ micromark_to_mdast("a {alpha} b.", &mdx)?,
+ Node::Root(Root {
+ children: vec![Node::Paragraph(Paragraph {
+ children: vec![
+ Node::Text(Text {
+ value: "a ".to_string(),
+ position: Some(Position::new(1, 1, 0, 1, 3, 2))
+ }),
+ Node::MdxTextExpression(MdxTextExpression {
+ value: "alpha".to_string(),
+ position: Some(Position::new(1, 3, 2, 1, 10, 9))
+ }),
+ Node::Text(Text {
+ value: " b.".to_string(),
+ position: Some(Position::new(1, 10, 9, 1, 13, 12))
+ })
+ ],
+ position: Some(Position::new(1, 1, 0, 1, 13, 12))
+ })],
+ position: Some(Position::new(1, 1, 0, 1, 13, 12))
+ }),
+ "should support mdx expressions (text) as `MdxTextExpression`s in mdast"
+ );
+
Ok(())
}
diff --git a/tests/mdx_jsx_flow.rs b/tests/mdx_jsx_flow.rs
index 9b0453f..14e14f0 100644
--- a/tests/mdx_jsx_flow.rs
+++ b/tests/mdx_jsx_flow.rs
@@ -1,5 +1,8 @@
extern crate micromark;
-use micromark::{micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{List, ListItem, MdxJsxFlowElement, Node, Paragraph, Position, Root, Text},
+ micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
#[test]
@@ -141,5 +144,36 @@ fn mdx_jsx_flow_essence() -> Result<(), String> {
"should not support lazy flow (7)"
);
+ assert_eq!(
+ micromark_to_mdast("<>\n * a\n</>", &mdx)?,
+ Node::Root(Root {
+ children: vec![Node::MdxJsxFlowElement(MdxJsxFlowElement {
+ name: None,
+ attributes: vec![],
+ children: vec![Node::List(List {
+ ordered: false,
+ spread: false,
+ start: None,
+ children: vec![Node::ListItem(ListItem {
+ checked: None,
+ spread: false,
+ children: vec![Node::Paragraph(Paragraph {
+ children: vec![Node::Text(Text {
+ value: "a".to_string(),
+ position: Some(Position::new(2, 5, 7, 2, 6, 8))
+ }),],
+ position: Some(Position::new(2, 5, 7, 2, 6, 8))
+ })],
+ position: Some(Position::new(2, 1, 3, 2, 6, 8))
+ })],
+ position: Some(Position::new(2, 1, 3, 2, 6, 8))
+ })],
+ position: Some(Position::new(1, 1, 0, 3, 4, 12))
+ })],
+ position: Some(Position::new(1, 1, 0, 3, 4, 12))
+ }),
+ "should support mdx jsx (flow) as `MdxJsxFlowElement`s in mdast"
+ );
+
Ok(())
}
diff --git a/tests/mdx_jsx_text.rs b/tests/mdx_jsx_text.rs
index be76d6f..94e7b0c 100644
--- a/tests/mdx_jsx_text.rs
+++ b/tests/mdx_jsx_text.rs
@@ -1,6 +1,12 @@
extern crate micromark;
mod test_utils;
-use micromark::{micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{
+ AttributeContent, AttributeValue, Emphasis, MdxJsxAttribute, MdxJsxTextElement, Node,
+ Paragraph, Position, Root, Text,
+ },
+ micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
use test_utils::{parse_esm, parse_expression};
@@ -41,6 +47,272 @@ fn mdx_jsx_text_core() -> Result<(), String> {
"should support markdown inside elements"
);
+ assert_eq!(
+ micromark_to_mdast("a <b /> c.", &mdx)?,
+ Node::Root(Root {
+ children: vec![Node::Paragraph(Paragraph {
+ children: vec![
+ Node::Text(Text {
+ value: "a ".to_string(),
+ position: Some(Position::new(1, 1, 0, 1, 3, 2))
+ }),
+ Node::MdxJsxTextElement(MdxJsxTextElement {
+ name: Some("b".to_string()),
+ attributes: vec![],
+ children: vec![],
+ position: Some(Position::new(1, 3, 2, 1, 8, 7))
+ }),
+ Node::Text(Text {
+ value: " c.".to_string(),
+ position: Some(Position::new(1, 8, 7, 1, 11, 10))
+ })
+ ],
+ position: Some(Position::new(1, 1, 0, 1, 11, 10))
+ })],
+ position: Some(Position::new(1, 1, 0, 1, 11, 10))
+ }),
+ "should support mdx jsx (text) as `MdxJsxTextElement`s in mdast (self-closing)"
+ );
+
+ assert_eq!(
+ micromark_to_mdast("a <b>*c*</b> d.", &mdx)?,
+ Node::Root(Root {
+ children: vec![Node::Paragraph(Paragraph {
+ children: vec![
+ Node::Text(Text {
+ value: "a ".to_string(),
+ position: Some(Position::new(1, 1, 0, 1, 3, 2))
+ }),
+ Node::MdxJsxTextElement(MdxJsxTextElement {
+ name: Some("b".to_string()),
+ attributes: vec![],
+ children: vec![
+ Node::Emphasis(Emphasis {
+ children: vec![
+ Node::Text(Text {
+ value: "c".to_string(),
+ position: Some(Position::new(1, 7, 6, 1, 8, 7))
+ }),
+ ],
+ position: Some(Position::new(1, 6, 5, 1, 9, 8))
+ }),
+ ],
+ position: Some(Position::new(1, 3, 2, 1, 13, 12))
+ }),
+ Node::Text(Text {
+ value: " d.".to_string(),
+ position: Some(Position::new(1, 13, 12, 1, 16, 15))
+ })
+ ],
+ position: Some(Position::new(1, 1, 0, 1, 16, 15))
+ })],
+ position: Some(Position::new(1, 1, 0, 1, 16, 15))
+ }),
+ "should support mdx jsx (text) as `MdxJsxTextElement`s in mdast (matched open and close tags)"
+ );
+
+ assert_eq!(
+ micromark_to_mdast("<a:b />.", &mdx)?,
+ Node::Root(Root {
+ children: vec![Node::Paragraph(Paragraph {
+ children: vec![
+ Node::MdxJsxTextElement(MdxJsxTextElement {
+ name: Some("a:b".to_string()),
+ attributes: vec![],
+ children: vec![],
+ position: Some(Position::new(1, 1, 0, 1, 8, 7))
+ }),
+ Node::Text(Text {
+ value: ".".to_string(),
+ position: Some(Position::new(1, 8, 7, 1, 9, 8))
+ })
+ ],
+ position: Some(Position::new(1, 1, 0, 1, 9, 8))
+ })],
+ position: Some(Position::new(1, 1, 0, 1, 9, 8))
+ }),
+ "should support mdx jsx (text) as `MdxJsxTextElement`s in mdast (namespace in tag name)"
+ );
+
+ assert_eq!(
+ micromark_to_mdast("<a.b.c />.", &mdx)?,
+ Node::Root(Root {
+ children: vec![Node::Paragraph(Paragraph {
+ children: vec![
+ Node::MdxJsxTextElement(MdxJsxTextElement {
+ name: Some("a.b.c".to_string()),
+ attributes: vec![],
+ children: vec![],
+ position: Some(Position::new(1, 1, 0, 1, 10, 9))
+ }),
+ Node::Text(Text {
+ value: ".".to_string(),
+ position: Some(Position::new(1, 10, 9, 1, 11, 10))
+ })
+ ],
+ position: Some(Position::new(1, 1, 0, 1, 11, 10))
+ })],
+ position: Some(Position::new(1, 1, 0, 1, 11, 10))
+ }),
+ "should support mdx jsx (text) as `MdxJsxTextElement`s in mdast (members in tag name)"
+ );
+
+ assert_eq!(
+ micromark_to_mdast("<a {...b} />.", &mdx)?,
+ Node::Root(Root {
+ children: vec![Node::Paragraph(Paragraph {
+ children: vec![
+ Node::MdxJsxTextElement(MdxJsxTextElement {
+ name: Some("a".to_string()),
+ attributes: vec![AttributeContent::Expression("...b".to_string())],
+ children: vec![],
+ position: Some(Position::new(1, 1, 0, 1, 13, 12))
+ }),
+ Node::Text(Text {
+ value: ".".to_string(),
+ position: Some(Position::new(1, 13, 12, 1, 14, 13))
+ })
+ ],
+ position: Some(Position::new(1, 1, 0, 1, 14, 13))
+ })],
+ position: Some(Position::new(1, 1, 0, 1, 14, 13))
+ }),
+ "should support mdx jsx (text) as `MdxJsxTextElement`s in mdast (attribute expression)"
+ );
+
+ assert_eq!(
+ micromark_to_mdast("<a b c:d />.", &mdx)?,
+ Node::Root(Root {
+ children: vec![Node::Paragraph(Paragraph {
+ children: vec![
+ Node::MdxJsxTextElement(MdxJsxTextElement {
+ name: Some("a".to_string()),
+ attributes: vec![
+ AttributeContent::Property(MdxJsxAttribute {
+ name: "b".to_string(),
+ value: None,
+ }),
+ AttributeContent::Property(MdxJsxAttribute {
+ name: "c:d".to_string(),
+ value: None,
+ })
+ ],
+ children: vec![],
+ position: Some(Position::new(1, 1, 0, 1, 12, 11))
+ }),
+ Node::Text(Text {
+ value: ".".to_string(),
+ position: Some(Position::new(1, 12, 11, 1, 13, 12))
+ })
+ ],
+ position: Some(Position::new(1, 1, 0, 1, 13, 12))
+ })],
+ position: Some(Position::new(1, 1, 0, 1, 13, 12))
+ }),
+ "should support mdx jsx (text) as `MdxJsxTextElement`s in mdast (property names)"
+ );
+
+ assert_eq!(
+ micromark_to_mdast("<a b='c' d=\"e\" f={g} />.", &mdx)?,
+ Node::Root(Root {
+ children: vec![Node::Paragraph(Paragraph {
+ children: vec![
+ Node::MdxJsxTextElement(MdxJsxTextElement {
+ name: Some("a".to_string()),
+ attributes: vec![
+ AttributeContent::Property(MdxJsxAttribute {
+ name: "b".to_string(),
+ value: Some(AttributeValue::Literal("c".to_string())),
+ }),
+ AttributeContent::Property(MdxJsxAttribute {
+ name: "d".to_string(),
+ value: Some(AttributeValue::Literal("e".to_string())),
+ }),
+ AttributeContent::Property(MdxJsxAttribute {
+ name: "f".to_string(),
+ value: Some(AttributeValue::Expression("g".to_string())),
+ }),
+ ],
+ children: vec![],
+ position: Some(Position::new(1, 1, 0, 1, 24, 23))
+ }),
+ Node::Text(Text {
+ value: ".".to_string(),
+ position: Some(Position::new(1, 24, 23, 1, 25, 24))
+ })
+ ],
+ position: Some(Position::new(1, 1, 0, 1, 25, 24))
+ })],
+ position: Some(Position::new(1, 1, 0, 1, 25, 24))
+ }),
+ "should support mdx jsx (text) as `MdxJsxTextElement`s in mdast (attribute values)"
+ );
+
+ assert_eq!(
+ micromark_to_mdast("a </b> c", &mdx)
+ .err()
+ .unwrap(),
+ "1:4: Unexpected closing slash `/` in tag, expected an open tag first (mdx-jsx:unexpected-closing-slash)",
+ "should crash when building the ast on a closing tag if none is open"
+ );
+
+ assert_eq!(
+ micromark_to_mdast("a <b> c </b/> d", &mdx)
+ .err()
+ .unwrap(),
+ "1:12: Unexpected self-closing slash `/` in closing tag, expected the end of the tag (mdx-jsx:unexpected-self-closing-slash)",
+ "should crash when building the ast on a closing tag with a self-closing slash"
+ );
+
+ assert_eq!(
+ micromark_to_mdast("a <b> c </b d> e", &mdx)
+ .err()
+ .unwrap(),
+ "1:13: Unexpected attribute in closing tag, expected the end of the tag (mdx-jsx:unexpected-attribute)",
+ "should crash when building the ast on a closing tag with an attribute"
+ );
+
+ assert_eq!(
+ micromark_to_mdast("a <>b</c> d", &mdx)
+ .err()
+ .unwrap(),
+ "1:6: Unexpected closing tag `</c>`, expected corresponding closing tag for `<>` (1:3) (mdx-jsx:end-tag-mismatch)",
+ "should crash when building the ast on mismatched tags (1)"
+ );
+
+ assert_eq!(
+ micromark_to_mdast("a <b>c</> d", &mdx)
+ .err()
+ .unwrap(),
+ "1:7: Unexpected closing tag `</>`, expected corresponding closing tag for `<b>` (1:3) (mdx-jsx:end-tag-mismatch)",
+ "should crash when building the ast on mismatched tags (2)"
+ );
+
+ assert_eq!(
+ micromark_to_mdast("*a <b>c* d</b>.", &mdx).err().unwrap(),
+ "1:9: Expected a closing tag for `<b>` (1:4) before the end of `Emphasis` (mdx-jsx:end-tag-mismatch)",
+ "should crash when building the ast on mismatched interleaving (1)"
+ );
+
+ assert_eq!(
+ micromark_to_mdast("<a>b *c</a> d*.", &mdx).err().unwrap(),
+ "1:8: Expected the closing tag `</a>` either before the start of `Emphasis` (1:6), or another opening tag after that start (mdx-jsx:end-tag-mismatch)",
+ "should crash when building the ast on mismatched interleaving (2)"
+ );
+
+ assert_eq!(
+ micromark_to_mdast("a <b>.", &mdx).err().unwrap(),
+ "1:7: Expected a closing tag for `<b>` (1:3) before the end of `Paragraph` (mdx-jsx:end-tag-mismatch)",
+ "should crash when building the ast on mismatched interleaving (3)"
+ );
+
+ // Note: this is flow, not text.
+ assert_eq!(
+ micromark_to_mdast("<a>", &mdx).err().unwrap(),
+ "1:4: Expected a closing tag for `<a>` (1:1) (mdx-jsx:end-tag-mismatch)",
+ "should crash when building the ast on mismatched interleaving (4)"
+ );
+
Ok(())
}
diff --git a/tests/thematic_break.rs b/tests/thematic_break.rs
index f4cb376..85ab37f 100644
--- a/tests/thematic_break.rs
+++ b/tests/thematic_break.rs
@@ -1,5 +1,8 @@
extern crate micromark;
-use micromark::{micromark, micromark_with_options, Constructs, Options};
+use micromark::{
+ mdast::{Node, Position, Root, ThematicBreak},
+ micromark, micromark_to_mdast, micromark_with_options, Constructs, Options,
+};
use pretty_assertions::assert_eq;
#[test]
@@ -181,5 +184,16 @@ fn thematic_break() -> Result<(), String> {
"should support turning off thematic breaks"
);
+ assert_eq!(
+ micromark_to_mdast("***", &Options::default())?,
+ Node::Root(Root {
+ children: vec![Node::ThematicBreak(ThematicBreak {
+ position: Some(Position::new(1, 1, 0, 1, 4, 3))
+ })],
+ position: Some(Position::new(1, 1, 0, 1, 4, 3))
+ }),
+ "should support thematic breaks as `ThematicBreak`s in mdast"
+ );
+
Ok(())
}