// // 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", "* List\n * Sublist\n Not a header\n ------\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", "* List\n * Sublist\n Not a header\n ------\n", "\n", } doTestsBlock(t, tests, EXTENSION_SPACE_HEADERS) }