Add straight forward unit tests.

This commit is contained in:
T. Thiery
2017-09-18 20:42:50 +02:00
parent 218a094f0d
commit 0c408951b8

View File

@@ -1,4 +1,4 @@
// Copyright (c) Alexandre Mutel. All rights reserved.
// Copyright (c) Alexandre Mutel. All rights reserved.
// This file is licensed under the BSD-Clause 2 license.
// See the license.txt file in the project root for more information.
@@ -11,6 +11,36 @@ namespace Markdig.Tests
public class TestNormalize
{
[Test]
public void TestCodeBlock()
{
AssertNormalizeNoTrim(" public void HelloWorld();\n {\n }\n\n");
AssertNormalizeNoTrim("```` \npublic void HelloWorld();\n{\n}\n````\n"); //TODO: Bug? Space after the fence
AssertNormalizeNoTrim("````csharp \npublic void HelloWorld();\n{\n}\n````\n"); //TODO: Bug? two spaces after the language
AssertNormalizeNoTrim("````csharp hideNewKeyword=true \npublic void HelloWorld();\n{\n}\n````\n"); //TODO: Bug? space after the attributes
}
[Test]
public void TestHeading()
{
AssertNormalizeNoTrim("# Heading\n\n");
AssertNormalizeNoTrim("## Heading\n\n");
AssertNormalizeNoTrim("### Heading\n\n");
AssertNormalizeNoTrim("#### Heading\n\n");
AssertNormalizeNoTrim("##### Heading\n\n");
AssertNormalizeNoTrim("###### Heading\n\n");
AssertNormalizeNoTrim("Heading\n=======\n\n", "# Heading\n\n");
}
[Test]
public void TestHtml()
{
/*AssertNormalizeNoTrim(@"<div id=""foo"" class=""bar
baz"">
</ div >");*/ // TODO: Bug: Throws Exception during emit
}
[Test]
public void TestParagraph()
{
@@ -52,6 +82,25 @@ line3");
");
}
[Test]
public void TestListOrderedAndIntended()
{
AssertNormalize(@"
1. a
2. b
- foo
- bar
3. c
", @"
1. a
2. b
- foo
- bar
3. c
"); // TODO: Bug: intend is always stripped a space.
}
[Test]
public void TestHeaderAndParagraph()
{
@@ -73,6 +122,25 @@ paragraph
");
}
[Test]
public void TestThematicBreak()
{
AssertNormalizeNoTrim("***\n");
AssertNormalizeNoTrim("* * *\n", "***\n");
}
[Test]
public void TestAutolinkInline()
{
AssertNormalizeNoTrim("This has a <auto.link.com>");
}
[Test]
public void TestCodeInline()
{
AssertNormalizeNoTrim("This has a `HelloWorld()` in it");
}
[Test]
public void TestEmphasis()
@@ -91,15 +159,29 @@ paragraph
AssertNormalize("This is an ![image](http://company.com)");
}
[Test]
public void TestHtmlEntity()
{
AssertNormalizeNoTrim("This is a &auml; blank", "This is a ä blank"); //TODO: bug?
}
public void AssertNormalize(string input, string expected = null)
[Test]
public void TestHtmlInline()
{
AssertNormalizeNoTrim("foo <hr/> bar");
}
public void AssertNormalizeNoTrim(string input, string expected = null)
=> AssertNormalize(input, expected, false);
public void AssertNormalize(string input, string expected = null, bool trim = true)
{
expected = expected ?? input;
input = NormText(input);
expected = NormText(expected);
input = NormText(input, trim);
expected = NormText(expected, trim);
var result = Markdown.Normalize(input);
result = NormText(result);
result = NormText(result, trim);
Console.WriteLine("```````````````````Source");
Console.WriteLine(TestParser.DisplaySpaceAndTabs(input));
@@ -113,9 +195,13 @@ paragraph
TextAssert.AreEqual(expected, result);
}
private static string NormText(string text)
private static string NormText(string text, bool trim)
{
return text.Trim().Replace("\r\n", "\n").Replace('\r', '\n');
if (trim)
{
text = text.Trim();
}
return text.Replace("\r\n", "\n").Replace('\r', '\n');
}
}
}