aboutsummaryrefslogtreecommitdiffstats
path: root/tests/mdx_jsx_flow.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-09-08 15:46:46 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-09-08 16:30:56 +0200
commitb4256dc2e1352a2b74f29b2650150cc8b57f54ed (patch)
tree67ddb1b3c99be459fd0fa1ea19b5f89565e56b65 /tests/mdx_jsx_flow.rs
parent2d24336c61e88e364e63e36db7b0803bc6532159 (diff)
downloadmarkdown-rs-b4256dc2e1352a2b74f29b2650150cc8b57f54ed.tar.gz
markdown-rs-b4256dc2e1352a2b74f29b2650150cc8b57f54ed.tar.bz2
markdown-rs-b4256dc2e1352a2b74f29b2650150cc8b57f54ed.zip
Add support for mdx jsx (flow)
Diffstat (limited to 'tests/mdx_jsx_flow.rs')
-rw-r--r--tests/mdx_jsx_flow.rs130
1 files changed, 130 insertions, 0 deletions
diff --git a/tests/mdx_jsx_flow.rs b/tests/mdx_jsx_flow.rs
new file mode 100644
index 0000000..c9cd18d
--- /dev/null
+++ b/tests/mdx_jsx_flow.rs
@@ -0,0 +1,130 @@
+extern crate micromark;
+use micromark::{micromark_with_options, Constructs, Options};
+use pretty_assertions::assert_eq;
+
+#[test]
+fn mdx_jsx_flow_agnostic() -> Result<(), String> {
+ let mdx = Options {
+ constructs: Constructs::mdx(),
+ ..Options::default()
+ };
+
+ assert_eq!(
+ micromark_with_options("<a />", &mdx)?,
+ "",
+ "should support a self-closing element"
+ );
+
+ assert_eq!(
+ micromark_with_options("<a></a>", &mdx)?,
+ "",
+ "should support a closed element"
+ );
+
+ assert_eq!(
+ micromark_with_options("<a>\nb\n</a>", &mdx)?,
+ "<p>b</p>\n",
+ "should support an element w/ content"
+ );
+
+ assert_eq!(
+ micromark_with_options("<a>\n- b\n</a>", &mdx)?,
+ "<ul>\n<li>b</li>\n</ul>\n",
+ "should support an element w/ containers as content"
+ );
+
+ // To do: expressions.
+ // assert_eq!(
+ // micromark_with_options("<a b c:d e=\"\" f={/* g */} {...h} />", &mdx)?,
+ // "",
+ // "should support attributes"
+ // );
+
+ Ok(())
+}
+
+// Flow is mostly the same as `text`, so we only test the relevant
+// differences.
+#[test]
+fn mdx_jsx_flow_essence() -> Result<(), String> {
+ let mdx = Options {
+ constructs: Constructs::mdx(),
+ ..Options::default()
+ };
+
+ assert_eq!(
+ micromark_with_options("<a />", &mdx)?,
+ "",
+ "should support an element"
+ );
+
+ assert_eq!(
+ micromark_with_options("<a>\n- b\n</a>", &mdx)?,
+ "<ul>\n<li>b</li>\n</ul>\n",
+ "should support an element around a container"
+ );
+
+ assert_eq!(
+ micromark_with_options("<x\n y\n> \nb\n </x>", &mdx)?,
+ "<p>b</p>\n",
+ "should support a dangling `>` in a tag (not a block quote)"
+ );
+
+ assert_eq!(
+ micromark_with_options("<a> \nb\n </a>", &mdx)?,
+ "<p>b</p>\n",
+ "should support trailing initial and final whitespace around tags"
+ );
+
+ assert_eq!(
+ micromark_with_options("<a> <b>\t\nc\n </b> </a>", &mdx)?,
+ "<p>c</p>\n",
+ "should support tags after tags"
+ );
+
+ assert_eq!(
+ micromark_with_options("> <X\n/>", &mdx).err().unwrap(),
+ "2:1: Unexpected lazy line in container, expected line to be prefixed with `>` when in a block quote, whitespace when in a list, etc",
+ "should not support lazy flow (1)"
+ );
+
+ assert_eq!(
+ micromark_with_options("> a\n> <X\n/>", &mdx)
+ .err()
+ .unwrap(),
+ "3:1: Unexpected lazy line in container, expected line to be prefixed with `>` when in a block quote, whitespace when in a list, etc",
+ "should not support lazy flow (2)"
+ );
+
+ assert_eq!(
+ micromark_with_options("> <a b='\nc'/> d", &mdx)
+ .err()
+ .unwrap(),
+ "2:1: Unexpected lazy line in container, expected line to be prefixed with `>` when in a block quote, whitespace when in a list, etc",
+ "should not support lazy flow (3)"
+ );
+
+ assert_eq!(
+ micromark_with_options("> <a b='c\n'/> d", &mdx)
+ .err()
+ .unwrap(),
+ "2:1: Unexpected lazy line in container, expected line to be prefixed with `>` when in a block quote, whitespace when in a list, etc",
+ "should not support lazy flow (4)"
+ );
+
+ assert_eq!(
+ micromark_with_options("> <a b='c\nd'/> e", &mdx)
+ .err()
+ .unwrap(),
+ "2:1: Unexpected lazy line in container, expected line to be prefixed with `>` when in a block quote, whitespace when in a list, etc",
+ "should not support lazy flow (4)"
+ );
+
+ assert_eq!(
+ micromark_with_options("> a\n<X />", &mdx)?,
+ "<blockquote>\n<p>a</p>\n</blockquote>\n",
+ "should not support lazy flow (5)"
+ );
+
+ Ok(())
+}