From 4711b1f0720eb54e458ca5a16cb655013693b628 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Fri, 9 Sep 2022 15:42:07 +0200 Subject: Add support for mdx attribute (value) expressions --- tests/mdx_jsx_text.rs | 302 ++++++++++++++++++++++++-------------------------- 1 file changed, 142 insertions(+), 160 deletions(-) (limited to 'tests/mdx_jsx_text.rs') diff --git a/tests/mdx_jsx_text.rs b/tests/mdx_jsx_text.rs index 782fb6a..1872b05 100644 --- a/tests/mdx_jsx_text.rs +++ b/tests/mdx_jsx_text.rs @@ -67,19 +67,17 @@ fn mdx_jsx_text_agnosic() -> Result<(), String> { "should support an unclosed element" ); - // To do: expressions. - // assert_eq!( - // micromark_with_options("a c", &mdx)?, - // "

a c

", - // "should support an attribute expression" - // ); + assert_eq!( + micromark_with_options("a c", &mdx)?, + "

a c

", + "should support an attribute expression" + ); - // To do: expressions. - // assert_eq!( - // micromark_with_options("a d", &mdx)?, - // "

a d

", - // "should support an attribute value expression" - // ); + assert_eq!( + micromark_with_options("a d", &mdx)?, + "

a d

", + "should support an attribute value expression" + ); Ok(()) } @@ -109,85 +107,79 @@ fn mdx_jsx_text_gnostic() -> Result<(), String> { "should support an unclosed element" ); - // To do: expressions. - // assert_eq!( - // micromark_with_options("a d", &mdx)?, - // "

a d

", - // "should support an attribute expression" - // ); + assert_eq!( + micromark_with_options("a d", &mdx)?, + "

a d

", + "should support an attribute expression" + ); - // To do: expressions. - // assert_eq!( - // micromark_with_options("a f", &mdx)?, - // "

a f

", - // "should support more complex attribute expression (1)" - // ); + assert_eq!( + micromark_with_options("a f", &mdx)?, + "

a f

", + "should support more complex attribute expression (1)" + ); - // To do: expressions. - // assert_eq!( - // micromark_with_options("a d", &mdx)?, - // "

a d

", - // "should support more complex attribute expression (2)" - // ); + assert_eq!( + micromark_with_options("a d", &mdx)?, + "

a d

", + "should support more complex attribute expression (2)" + ); - // To do: expressions. - // assert_eq!( - // micromark_with_options("a d", &mdx)?, - // "

a d

", - // "should support an attribute value expression" - // ); + assert_eq!( + micromark_with_options("a d", &mdx)?, + "

a d

", + "should support an attribute value expression" + ); - // To do: expressions. - // assert_eq!( - // micromark_with_options("a d", &mdx) - // .err() - // .unwrap(), - // "Unexpected empty expression", - // "should crash on an empty attribute value expression" - // ); + assert_eq!( + micromark_with_options("a d", &mdx) + .err() + .unwrap(), + "1:9: Unexpected empty in expression, expected a value between braces", + "should crash on an empty attribute value expression" + ); - // To do: expressions. + // To do: swc. // assert_eq!( - // micromark_with_options("a c", &mdx) + // micromark_with_options("a c", &swc) // .err() // .unwrap(), // "Could not parse expression with acorn: Unexpected token", // "should crash on a non-spread attribute expression" // ); - // To do: expressions. + // To do: swc. // assert_eq!( - // micromark_with_options("a d", &mdx) + // micromark_with_options("a d", &swc) // .err() // .unwrap(), // "Could not parse expression with acorn: Unexpected token", // "should crash on invalid JS in an attribute value expression" // ); - // // To do: expressions. + // To do: swc. // assert_eq!( - // micromark_with_options("a c", &mdx) + // micromark_with_options("a c", &swc) // .err() // .unwrap(), // "Could not parse expression with acorn: Unexpected token", // "should crash on invalid JS in an attribute expression" // ); - // // To do: expressions. + // To do: swc. // assert_eq!( - // micromark_with_options("a f", &mdx) + // micromark_with_options("a f", &swc) // .err() // .unwrap(), // "Unexpected `ExpressionStatement` in code: expected an object spread", // "should crash on invalid JS in an attribute expression (2)" // ); - // To do: expressions. - // assert_eq!( - // micromark_with_options("a } /> f", &mdx)?, - // "

a f

", - // "should support parenthesized expressions" - // ); + assert_eq!( + micromark_with_options("a } /> f", &mdx)?, + "

a f

", + "should support parenthesized expressions" + ); Ok(()) } @@ -421,61 +413,53 @@ fn mdx_jsx_text_complete() -> Result<(), String> { "should crash on a nonconforming character after name" ); - // To do: expressions. - // assert_eq!( - // micromark_with_options("a c.", &mdx)?, - // "

a c.

", - // "should support attribute expressions" - // ); + assert_eq!( + micromark_with_options("a c.", &mdx)?, + "

a c.

", + "should support attribute expressions" + ); - // To do: expressions. - // assert_eq!( - // micromark_with_options("a c.", &mdx)?, - // "

a c.

", - // "should support nested balanced braces in attribute expressions" - // ); + assert_eq!( + micromark_with_options("a c.", &mdx)?, + "

a c.

", + "should support nested balanced braces in attribute expressions" + ); - // To do: expressions. - // assert_eq!( - // micromark_with_options(".", &mdx)?, - // "

.

", - // "should support attribute expressions directly after a name" - // ); + assert_eq!( + micromark_with_options(".", &mdx)?, + "

.

", + "should support attribute expressions directly after a name" + ); - // To do: expressions. - // assert_eq!( - // micromark_with_options(".", &mdx)?, - // "

.

", - // "should support attribute expressions directly after a member name" - // ); + assert_eq!( + micromark_with_options(".", &mdx)?, + "

.

", + "should support attribute expressions directly after a member name" + ); - // To do: expressions. - // assert_eq!( - // micromark_with_options(".", &mdx)?, - // "

.

", - // "should support attribute expressions directly after a local name" - // ); + assert_eq!( + micromark_with_options(".", &mdx)?, + "

.

", + "should support attribute expressions directly after a local name" + ); - // To do: expressions. - // assert_eq!( - // micromark_with_options("a .", &mdx)?, - // "

a .

", - // "should support attribute expressions directly after boolean attributes" - // ); + assert_eq!( + micromark_with_options("a .", &mdx)?, + "

a .

", + "should support attribute expressions directly after boolean attributes" + ); - // To do: expressions. - // assert_eq!( - // micromark_with_options("a .", &mdx)?, - // "

a .

", - // "should support attribute expressions directly after boolean qualified attributes" - // ); + assert_eq!( + micromark_with_options("a .", &mdx)?, + "

a .

", + "should support attribute expressions directly after boolean qualified attributes" + ); - // To do: expressions. - // assert_eq!( - // micromark_with_options("a c.", &mdx)?, - // "

a c.

", - // "should support attribute expressions and normal attributes" - // ); + assert_eq!( + micromark_with_options("a c.", &mdx)?, + "

a c.

", + "should support attribute expressions and normal attributes" + ); assert_eq!( micromark_with_options("a c.", &mdx)?, @@ -483,23 +467,21 @@ fn mdx_jsx_text_complete() -> Result<(), String> { "should support attributes" ); - // To do: expressions. - // assert_eq!( - // micromark_with_options("a c.", &mdx) - // .err() - // .unwrap(), - // "Unexpected character `~` (U+007E) before attribute name, expected a character that can start an attribute name, such as a letter, `$`, or `_`; whitespace before attributes; or the end of the tag", - // "should crash on a nonconforming character before an attribute name" - // ); + assert_eq!( + micromark_with_options("a c.", &mdx) + .err() + .unwrap(), + "1:12: Unexpected character `~` (U+007E) before attribute name, expected a character that can start an attribute name, such as a letter, `$`, or `_`; whitespace before attributes; or the end of the tag", + "should crash on a nonconforming character before an attribute name" + ); - // To do: expressions. - // assert_eq!( - // micromark_with_options("a c.", &mdx) @@ -553,19 +535,17 @@ fn mdx_jsx_text_complete() -> Result<(), String> { "should crash on a nonconforming character after a local attribute name" ); - // To do: expressions. - // assert_eq!( - // micromark_with_options("a c.", &mdx)?, - // "

a c.

", - // "should support attribute value expressions" - // ); + assert_eq!( + micromark_with_options("a c.", &mdx)?, + "

a c.

", + "should support attribute value expressions" + ); - // To do: expressions. - // assert_eq!( - // micromark_with_options("a c.", &mdx)?, - // "

a c.

", - // "should support nested balanced braces in attribute value expressions" - // ); + assert_eq!( + micromark_with_options("a c.", &mdx)?, + "

a c.

", + "should support nested balanced braces in attribute value expressions" + ); assert_eq!( micromark_with_options("a c.", &mdx) @@ -599,14 +579,13 @@ fn mdx_jsx_text_complete() -> Result<(), String> { "should crash on a missing closing quote in single quoted attribute value" ); - // To do: expressions. - // assert_eq!( - // micromark_with_options("a c.", &mdx) - // .err() - // .unwrap(), - // "Unexpected end of file in expression, expected a corresponding closing brace for `{`", - // "should crash on a missing closing brace in an attribute value expression" - // ); + assert_eq!( + micromark_with_options("a c.", &mdx) + .err() + .unwrap(), + "1:13: Unexpected end of file in expression, expected a corresponding closing brace for `{`", + "should crash on a missing closing brace in an attribute value expression" + ); assert_eq!( micromark_with_options("a c.", &mdx) @@ -622,12 +601,11 @@ fn mdx_jsx_text_complete() -> Result<(), String> { "should support an attribute directly after a value" ); - // To do: expressions. - // assert_eq!( - // micromark_with_options(".", &mdx)?, - // "

.

", - // "should support an attribute directly after an attribute expression" - // ); + assert_eq!( + micromark_with_options(".", &mdx)?, + "

.

", + "should support an attribute directly after an attribute expression" + ); assert_eq!( micromark_with_options("a
c.", &mdx) @@ -797,19 +775,17 @@ fn mdx_jsx_text_complete() -> Result<(), String> { "should support line endings in attribute values" ); - // To do: expressions. - // assert_eq!( - // micromark_with_options("> a f", &mdx)?, - // "
\n

a f

\n
", - // "should support line endings in attribute value expressions" - // ); + assert_eq!( + micromark_with_options("> a f", &mdx)?, + "
\n

a f

\n
", + "should support line endings in attribute value expressions" + ); - // To do: expressions. - // assert_eq!( - // micromark_with_options("> a e", &mdx)?, - // "
\n

a e

\n
", - // "should support line endings in attribute expressions" - // ); + assert_eq!( + micromark_with_options("> a e", &mdx)?, + "
\n

a e

\n
", + "should support line endings in attribute expressions" + ); assert_eq!( micromark_with_options("> a c", &mdx)?, @@ -835,6 +811,12 @@ fn mdx_jsx_text_complete() -> Result<(), String> { "should support lazy text (4)" ); + assert_eq!( + micromark_with_options("> a f", &mdx)?, + "
\n

a f

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

1 < 3

", -- cgit