Skip to content

Commit

Permalink
Merge pull request #20 from JerryHue/issue-19
Browse files Browse the repository at this point in the history
Add test cases for MarkdownParser.cs
  • Loading branch information
dbelokon authored Nov 22, 2021
2 parents 097f91e + 043794c commit 18a68fa
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 18a68fa

Please sign in to comment.