From 645fb2b02b1563bd98c07515bdc2d6d8478ba74e Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Thu, 13 Oct 2022 13:32:32 +0200 Subject: Add a bunch more tests for frontmatter --- tests/frontmatter.rs | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'tests') diff --git a/tests/frontmatter.rs b/tests/frontmatter.rs index 267b694..b1380b6 100644 --- a/tests/frontmatter.rs +++ b/tests/frontmatter.rs @@ -44,12 +44,60 @@ fn frontmatter() -> Result<(), String> { "should support empty frontmatter" ); + assert_eq!( + to_html_with_options("--\n---", &frontmatter)?, + "

--

", + "should not support 2 markers in an opening fence" + ); + + assert_eq!( + to_html_with_options("----\n---", &frontmatter)?, + "
\n
", + "should not support 4 markers in an opening fence" + ); + + assert_eq!( + to_html_with_options("---\n--", &frontmatter)?, + "
\n

--

", + "should not support 2 markers in a closing fence" + ); + + assert_eq!( + to_html_with_options("---\n----", &frontmatter)?, + "
\n
", + "should not support 4 markers in a closing fence" + ); + assert_eq!( to_html_with_options("---\n---\n## Neptune", &frontmatter)?, "

Neptune

", "should support content after frontmatter" ); + assert_eq!( + to_html_with_options("--- \t\n---", &frontmatter)?, + "", + "should support spaces and tabs after opening fence" + ); + + assert_eq!( + to_html_with_options("---\n---\t ", &frontmatter)?, + "", + "should support spaces and tabs after closing fence" + ); + + assert_eq!( + to_html_with_options("--- a\n---", &frontmatter)?, + "

--- a

", + "should not support content after opening fence" + ); + + assert_eq!( + to_html_with_options("---\n--- b", &frontmatter)?, + "
\n

--- b

", + "should not support content after closing fence" + ); + assert_eq!( to_html_with_options("## Neptune\n---\n---", &frontmatter)?, "

Neptune

\n
\n
", @@ -74,6 +122,12 @@ fn frontmatter() -> Result<(), String> { "should not support a missing closing fence" ); + assert_eq!( + to_html_with_options("---\na\n\nb\n \t\nc\n---", &frontmatter)?, + "", + "should support blank lines in frontmatter" + ); + assert_eq!( to_mdast("---\na: b\n---", &frontmatter.parse)?, Node::Root(Root { -- cgit