From b4256dc2e1352a2b74f29b2650150cc8b57f54ed Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 8 Sep 2022 15:46:46 +0200 Subject: Add support for mdx jsx (flow) --- tests/mdx_jsx_flow.rs | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/mdx_jsx_text.rs | 24 ++++++++++ 2 files changed, 154 insertions(+) create mode 100644 tests/mdx_jsx_flow.rs (limited to 'tests') 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("", &mdx)?, + "", + "should support a self-closing element" + ); + + assert_eq!( + micromark_with_options("", &mdx)?, + "", + "should support a closed element" + ); + + assert_eq!( + micromark_with_options("\nb\n", &mdx)?, + "

b

\n", + "should support an element w/ content" + ); + + assert_eq!( + micromark_with_options("\n- b\n", &mdx)?, + "\n", + "should support an element w/ containers as content" + ); + + // To do: expressions. + // assert_eq!( + // micromark_with_options("", &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("", &mdx)?, + "", + "should support an element" + ); + + assert_eq!( + micromark_with_options("\n- b\n", &mdx)?, + "\n", + "should support an element around a container" + ); + + assert_eq!( + micromark_with_options(" \nb\n ", &mdx)?, + "

b

\n", + "should support a dangling `>` in a tag (not a block quote)" + ); + + assert_eq!( + micromark_with_options(" \nb\n ", &mdx)?, + "

b

\n", + "should support trailing initial and final whitespace around tags" + ); + + assert_eq!( + micromark_with_options(" \t\nc\n ", &mdx)?, + "

c

\n", + "should support tags after tags" + ); + + assert_eq!( + micromark_with_options("> ", &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> ", &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("> 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("> 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("> 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", &mdx)?, + "
\n

a

\n
\n", + "should not support lazy flow (5)" + ); + + Ok(()) +} diff --git a/tests/mdx_jsx_text.rs b/tests/mdx_jsx_text.rs index 1890aad..782fb6a 100644 --- a/tests/mdx_jsx_text.rs +++ b/tests/mdx_jsx_text.rs @@ -811,6 +811,30 @@ fn mdx_jsx_text_complete() -> Result<(), String> { // "should support line endings in attribute expressions" // ); + assert_eq!( + micromark_with_options("> a c", &mdx)?, + "
\n

a c

\n
", + "should support lazy text (1)" + ); + + assert_eq!( + micromark_with_options("> a e", &mdx)?, + "
\n

a e

\n
", + "should support lazy text (2)" + ); + + assert_eq!( + micromark_with_options("> a e", &mdx)?, + "
\n

a e

\n
", + "should support lazy text (3)" + ); + + assert_eq!( + micromark_with_options("> a f", &mdx)?, + "
\n

a f

\n
", + "should support lazy text (4)" + ); + assert_eq!( micromark_with_options("1 < 3", &mdx)?, "

1 < 3

", -- cgit