From 043794ce0ce7071e41b9a7a6122496193e6ad8b6 Mon Sep 17 00:00:00 2001 From: Gerardo Arriaga Rendon Date: Sat, 20 Nov 2021 01:52:20 -0800 Subject: [PATCH] Add test cases for MarkdownParser.cs * Test case for empty header text * Test case for trailing hashtags after the header text * Test case for immediate trailing hashtags in the header text --- glazed-donut.Tests/MarkdownParserTests.cs | 50 +++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/glazed-donut.Tests/MarkdownParserTests.cs b/glazed-donut.Tests/MarkdownParserTests.cs index 8099b1a..a116da2 100644 --- a/glazed-donut.Tests/MarkdownParserTests.cs +++ b/glazed-donut.Tests/MarkdownParserTests.cs @@ -49,5 +49,55 @@ public void ReturnHtmlString_WhenParagraphIsValid(string input, string expectedH new object[] { "# Markdown", "

Markdown

\n" }, new object[] { "---", "
" } }; + + [Theory] + [InlineData("#")] + [InlineData("#\n")] + [InlineData("# ")] + [InlineData("# \n")] + public void ReturnEmptyHeaderElement_WhenHeaderTextIsEmpty(string input) + { + var stream = new MemoryStream(Encoding.UTF8.GetBytes(input)); + var parser = new MarkdownParser(stream); + + var htmlString = parser.Parse(); + + Assert.Equal("

\n", htmlString); + } + + [Theory] + [InlineData("# header #")] + [InlineData("# header #\n")] + [InlineData("# header ##")] + [InlineData("# header ##\n")] + public void ReturnNormalHeaderElement_WhenHeaderTextFollowedByHashtags(string input) + { + var stream = new MemoryStream(Encoding.UTF8.GetBytes(input)); + var parser = new MarkdownParser(stream); + + var htmlString = parser.Parse(); + + Assert.Equal("

header

\n", htmlString); + } + + [Theory, MemberData(nameof(HeaderTextWithImmediateHashtags))] + public void ReturnHeaderElementWithHashtags_WhenHeaderTextImmediatelyFollowedByHashtags(string input, string expectedHtmlString) + { + var stream = new MemoryStream(Encoding.UTF8.GetBytes(input)); + var parser = new MarkdownParser(stream); + + var htmlString = parser.Parse(); + + Assert.Equal(expectedHtmlString, htmlString); + } + + public static IEnumerable HeaderTextWithImmediateHashtags => + new List + { + new object[] { "# header#", "

header#

\n" }, + new object[] { "# header#\n", "

header#

\n" }, + new object[] { "# header##", "

header##

\n" }, + new object[] { "# header##\n", "

header##

\n" } + }; } }