// // Black Friday Markdown Processor // Originally based on http://github.com/tanoku/upskirt // by Russ Ross // // // Unit tests for block parsing // package blackfriday import ( "testing" ) func runMarkdownBlock(input string, extensions uint32) string { html_flags := 0 html_flags |= HTML_USE_XHTML renderer := HtmlRenderer(html_flags) return string(Markdown([]byte(input), renderer, extensions)) } func doTestsBlock(t *testing.T, tests []string, extensions uint32) { for i := 0; i+1 < len(tests); i += 2 { input := tests[i] expected := tests[i+1] actual := runMarkdownBlock(input, extensions) if actual != expected { t.Errorf("\nInput [%#v]\nExpected[%#v]\nActual [%#v]", input, expected, actual) } } } func TestPrefixHeaderNoExtensions(t *testing.T) { var tests = []string{ "# Header 1\n", "

Header 1

\n", "## Header 2\n", "

Header 2

\n", "### Header 3\n", "

Header 3

\n", "#### Header 4\n", "

Header 4

\n", "##### Header 5\n", "
Header 5
\n", "###### Header 6\n", "
Header 6
\n", "####### Header 7\n", "
# Header 7
\n", "#Header 1\n", "

Header 1

\n", "##Header 2\n", "

Header 2

\n", "###Header 3\n", "

Header 3

\n", "####Header 4\n", "

Header 4

\n", "#####Header 5\n", "
Header 5
\n", "######Header 6\n", "
Header 6
\n", "#######Header 7\n", "
#Header 7
\n", "Hello\n# Header 1\nGoodbye\n", "

Hello

\n\n

Header 1

\n\n

Goodbye

\n", "* List\n# Header\n* List\n", "\n", "* List\n#Header\n* List\n", "\n", "* List\n * Nested list\n # Nested header\n", "\n", } doTestsBlock(t, tests, 0) } func TestPrefixHeaderSpaceExtension(t *testing.T) { var tests = []string{ "# Header 1\n", "

Header 1

\n", "## Header 2\n", "

Header 2

\n", "### Header 3\n", "

Header 3

\n", "#### Header 4\n", "

Header 4

\n", "##### Header 5\n", "
Header 5
\n", "###### Header 6\n", "
Header 6
\n", "####### Header 7\n", "

####### Header 7

\n", "#Header 1\n", "

#Header 1

\n", "##Header 2\n", "

##Header 2

\n", "###Header 3\n", "

###Header 3

\n", "####Header 4\n", "

####Header 4

\n", "#####Header 5\n", "

#####Header 5

\n", "######Header 6\n", "

######Header 6

\n", "#######Header 7\n", "

#######Header 7

\n", "Hello\n# Header 1\nGoodbye\n", "

Hello

\n\n

Header 1

\n\n

Goodbye

\n", "* List\n# Header\n* List\n", "\n", "* List\n#Header\n* List\n", "\n", "* List\n * Nested list\n # Nested header\n", "\n", } doTestsBlock(t, tests, EXTENSION_SPACE_HEADERS) } func TestUnderlineHeaders(t *testing.T) { var tests = []string{ "Header 1\n========\n", "

Header 1

\n", "Header 2\n--------\n", "

Header 2

\n", "A\n=\n", "

A

\n", "B\n-\n", "

B

\n", "Paragraph\nHeader\n=\n", "

Paragraph

\n\n

Header

\n", "Header\n===\nParagraph\n", "

Header

\n\n

Paragraph

\n", "Header\n===\nAnother header\n---\n", "

Header

\n\n

Another header

\n", " Header\n======\n", "

Header

\n", " Code\n========\n", "
Code\n
\n\n

========

\n", "Header with *inline*\n=====\n", "

Header with inline

\n", "* List\n * Sublist\n Not a header\n ------\n", "\n", "Paragraph\n\n\n\n\nHeader\n===\n", "

Paragraph

\n\n

Header

\n", "Trailing space \n==== \n\n", "

Trailing space

\n", "Trailing spaces\n==== \n\n", "

Trailing spaces

\n", "Double underline\n=====\n=====\n", "

Double underline

\n\n

=====

\n", } doTestsBlock(t, tests, 0) } func TestHorizontalRule(t *testing.T) { var tests = []string{ "-\n", "

-

\n", "--\n", "

--

\n", "---\n", "
\n", "----\n", "
\n", "*\n", "

*

\n", "**\n", "

**

\n", "***\n", "
\n", "****\n", "
\n", "_\n", "

_

\n", "__\n", "

__

\n", "___\n", "
\n", "____\n", "
\n", "-*-\n", "

-*-

\n", "- - -\n", "
\n", "* * *\n", "
\n", "_ _ _\n", "
\n", "-----*\n", "

-----*

\n", " ------ \n", "
\n", "Hello\n***\n", "

Hello

\n\n
\n", "---\n***\n___\n", "
\n\n
\n\n
\n", } doTestsBlock(t, tests, 0) } func TestUnorderedList(t *testing.T) { var tests = []string{ "* Hello\n", "\n", "* Yin\n* Yang\n", "\n", "* Ting\n* Bong\n* Goo\n", "\n", "* Yin\n\n* Yang\n", "\n", "* Ting\n\n* Bong\n* Goo\n", "\n", "+ Hello\n", "\n", "+ Yin\n+ Yang\n", "\n", "+ Ting\n+ Bong\n+ Goo\n", "\n", "+ Yin\n\n+ Yang\n", "\n", "+ Ting\n\n+ Bong\n+ Goo\n", "\n", "- Hello\n", "\n", "- Yin\n- Yang\n", "\n", "- Ting\n- Bong\n- Goo\n", "\n", "- Yin\n\n- Yang\n", "\n", "- Ting\n\n- Bong\n- Goo\n", "\n", "*Hello\n", "

*Hello

\n", "* Hello \n", "\n", "* Hello \n Next line \n", "\n", "Paragraph\n* No linebreak\n", "

Paragraph\n* No linebreak

\n", "Paragraph\n\n* Linebreak\n", "

Paragraph

\n\n\n", "* List\n * Nested list\n", "\n", "* List\n\n * Nested list\n", "\n", "* List\n Second line\n\n + Nested\n", "\n", "* List\n + Nested\n\n Continued\n", "\n", "* List\n * shallow indent\n", "\n", "* List\n" + " * shallow indent\n" + " * part of second list\n" + " * still second\n" + " * almost there\n" + " * third level\n", "\n", } doTestsBlock(t, tests, 0) }