Skip to content

Commit

Permalink
Add test cases for MarkdownParser.cs
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
JerryHue committed Nov 20, 2021
1 parent 097f91e commit 043794c
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions glazed-donut.Tests/MarkdownParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,55 @@ public void ReturnHtmlString_WhenParagraphIsValid(string input, string expectedH
new object[] { "# Markdown", "<h1>Markdown</h1>\n" },
new object[] { "---", "<hr>" }
};

[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("<h1></h1>\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("<h1>header</h1>\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<object[]> HeaderTextWithImmediateHashtags =>
new List<object[]>
{
new object[] { "# header#", "<h1>header#</h1>\n" },
new object[] { "# header#\n", "<h1>header#</h1>\n" },
new object[] { "# header##", "<h1>header##</h1>\n" },
new object[] { "# header##\n", "<h1>header##</h1>\n" }
};
}
}

0 comments on commit 043794c

Please sign in to comment.