From afe75b0508cedba1df5c9701a22e5732c7d0d00e Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 13 Oct 2022 15:30:33 +0200 Subject: Add more tests for whitespace in jsx tags --- src/construct/partial_mdx_jsx.rs | 12 ++----- tests/mdx_jsx_text.rs | 72 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 10 deletions(-) diff --git a/src/construct/partial_mdx_jsx.rs b/src/construct/partial_mdx_jsx.rs index 1bf6fc2..e654416 100644 --- a/src/construct/partial_mdx_jsx.rs +++ b/src/construct/partial_mdx_jsx.rs @@ -1104,20 +1104,12 @@ pub fn es_whitespace_eol_after(tokenizer: &mut Tokenizer) -> State { /// Check if a character can start a JSX identifier. fn id_start_opt(code: Option) -> bool { - if let Some(char) = code { - id_start(char) - } else { - false - } + code.map_or(false, id_start) } /// Check if a character can continue a JSX identifier. fn id_cont_opt(code: Option) -> bool { - if let Some(char) = code { - id_cont(char, true) - } else { - false - } + code.map_or(false, |c| id_cont(c, true)) } /// Crash because something happened `at`, with info on what was `expect`ed diff --git a/tests/mdx_jsx_text.rs b/tests/mdx_jsx_text.rs index 2d1ec0a..d6e3d56 100644 --- a/tests/mdx_jsx_text.rs +++ b/tests/mdx_jsx_text.rs @@ -344,6 +344,78 @@ fn mdx_jsx_text_core() -> Result<(), String> { "should not support things that look like character references but aren’t" ); + assert_eq!( + to_mdast(".", &mdx.parse)?, + Node::Root(Root { + children: vec![Node::Paragraph(Paragraph { + children: vec![ + Node::MdxJsxTextElement(MdxJsxTextElement { + name: Some("a".into()), + attributes: vec![ + AttributeContent::Property(MdxJsxAttribute { + name: "b".into(), + value: None, + }), + AttributeContent::Property(MdxJsxAttribute { + name: "c".into(), + value: None, + }), + AttributeContent::Property(MdxJsxAttribute { + name: "d".into(), + value: None, + }) + ], + children: vec![], + position: Some(Position::new(1, 1, 0, 1, 22, 21)) + }), + Node::Text(Text { + value: ".".into(), + position: Some(Position::new(1, 22, 21, 1, 23, 22)) + }) + ], + position: Some(Position::new(1, 1, 0, 1, 23, 22)) + })], + position: Some(Position::new(1, 1, 0, 1, 23, 22)) + }), + "should support unicode whitespace in a lot of places" + ); + + assert_eq!( + to_mdast(".", &mdx.parse)?, + Node::Root(Root { + children: vec![Node::Paragraph(Paragraph { + children: vec![ + Node::MdxJsxTextElement(MdxJsxTextElement { + name: Some("a".into()), + attributes: vec![ + AttributeContent::Property(MdxJsxAttribute { + name: "b".into(), + value: None, + }), + AttributeContent::Property(MdxJsxAttribute { + name: "c".into(), + value: None, + }), + AttributeContent::Property(MdxJsxAttribute { + name: "d".into(), + value: None, + }) + ], + children: vec![], + position: Some(Position::new(1, 1, 0, 5, 3, 13)) + }), + Node::Text(Text { + value: ".".into(), + position: Some(Position::new(5, 3, 13, 5, 4, 14)) + }) + ], + position: Some(Position::new(1, 1, 0, 5, 4, 14)) + })], + position: Some(Position::new(1, 1, 0, 5, 4, 14)) + }), + "should support line endings in a lot of places" + ); + assert_eq!( to_mdast("a c", &mdx.parse) .err() -- cgit