// // Black Friday Markdown Processor // Originally based on http://github.com/tanoku/upskirt // by Russ Ross // // // Unit tests for inline parsing // package blackfriday import ( "testing" ) func runMarkdown(input string) string { var extensions uint32 extensions |= EXTENSION_NO_INTRA_EMPHASIS extensions |= EXTENSION_TABLES extensions |= EXTENSION_FENCED_CODE extensions |= EXTENSION_AUTOLINK extensions |= EXTENSION_STRIKETHROUGH extensions |= EXTENSION_SPACE_HEADERS extensions |= EXTENSION_LAX_HTML_BLOCKS html_flags := 0 html_flags |= HTML_USE_XHTML html_flags |= HTML_USE_SMARTYPANTS html_flags |= HTML_SMARTYPANTS_FRACTIONS html_flags |= HTML_SMARTYPANTS_LATEX_DASHES renderer := HtmlRenderer(html_flags) return string(Markdown([]byte(input), renderer, extensions)) } func doTests(t *testing.T, tests []string) { for i := 0; i+1 < len(tests); i += 2 { input := tests[i] expected := tests[i+1] actual := runMarkdown(input) if actual != expected { t.Errorf("\nInput [%#v]\nExpected[%#v]\nActual [%#v]", input, expected, actual) } } } func TestEmphasis(t *testing.T) { var tests = []string{ "nothing inline\n", "

nothing inline

\n", "simple *inline* test\n", "

simple inline test

\n", "*at the* beginning\n", "

at the beginning

\n", "at the *end*\n", "

at the end

\n", "*try two* in *one line*\n", "

try two in one line

\n", "over *two\nlines* test\n", "

over two\nlines test

\n", "odd *number of* markers* here\n", "

odd number of markers* here

\n", "odd *number\nof* markers* here\n", "

odd number\nof markers* here

\n", "simple _inline_ test\n", "

simple inline test

\n", "_at the_ beginning\n", "

at the beginning

\n", "at the _end_\n", "

at the end

\n", "_try two_ in _one line_\n", "

try two in one line

\n", "over _two\nlines_ test\n", "

over two\nlines test

\n", "odd _number of_ markers_ here\n", "

odd number of markers_ here

\n", "odd _number\nof_ markers_ here\n", "

odd number\nof markers_ here

\n", "mix of *markers_\n", "

mix of *markers_

\n", } doTests(t, tests) } func TestStrong(t *testing.T) { var tests = []string{ "nothing inline\n", "

nothing inline

\n", "simple **inline** test\n", "

simple inline test

\n", "**at the** beginning\n", "

at the beginning

\n", "at the **end**\n", "

at the end

\n", "**try two** in **one line**\n", "

try two in one line

\n", "over **two\nlines** test\n", "

over two\nlines test

\n", "odd **number of** markers** here\n", "

odd number of markers** here

\n", "odd **number\nof** markers** here\n", "

odd number\nof markers** here

\n", "simple __inline__ test\n", "

simple inline test

\n", "__at the__ beginning\n", "

at the beginning

\n", "at the __end__\n", "

at the end

\n", "__try two__ in __one line__\n", "

try two in one line

\n", "over __two\nlines__ test\n", "

over two\nlines test

\n", "odd __number of__ markers__ here\n", "

odd number of markers__ here

\n", "odd __number\nof__ markers__ here\n", "

odd number\nof markers__ here

\n", "mix of **markers__\n", "

mix of **markers__

\n", } doTests(t, tests) } func TestEmphasisMix(t *testing.T) { var tests = []string{ "***triple emphasis***\n", "

triple emphasis

\n", "***triple\nemphasis***\n", "

triple\nemphasis

\n", "___triple emphasis___\n", "

triple emphasis

\n", "***triple emphasis___\n", "

***triple emphasis___

\n", "*__triple emphasis__*\n", "

triple emphasis

\n", "__*triple emphasis*__\n", "

triple emphasis

\n", "**improper *nesting** is* bad\n", "

improper *nesting is* bad

\n", "*improper **nesting* is** bad\n", "

improper **nesting is** bad

\n", } doTests(t, tests) } func TestStrikeThrough(t *testing.T) { var tests = []string{ "nothing inline\n", "

nothing inline

\n", "simple ~~inline~~ test\n", "

simple inline test

\n", "~~at the~~ beginning\n", "

at the beginning

\n", "at the ~~end~~\n", "

at the end

\n", "~~try two~~ in ~~one line~~\n", "

try two in one line

\n", "over ~~two\nlines~~ test\n", "

over two\nlines test

\n", "odd ~~number of~~ markers~~ here\n", "

odd number of markers~~ here

\n", "odd ~~number\nof~~ markers~~ here\n", "

odd number\nof markers~~ here

\n", } doTests(t, tests) } func TestCodeSpan(t *testing.T) { var tests = []string{ "`source code`\n", "

source code

\n", "` source code with spaces `\n", "

source code with spaces

\n", "` source code with spaces `not here\n", "

source code with spacesnot here

\n", "a `single marker\n", "

a `single marker

\n", "a single multi-tick marker with ``` no text\n", "

a single multi-tick marker with ``` no text

\n", "markers with ` ` a space\n", "

markers with a space

\n", "`source code` and a `stray\n", "

source code and a `stray

\n", "`source with _awkward characters_ in it`\n", "

source with _awkward characters_ in it

\n", "`split over\ntwo lines`\n", "

split over\ntwo lines

\n", "```multiple ticks``` for the marker\n", "

multiple ticks for the marker

\n", "```multiple ticks `with` ticks inside```\n", "

multiple ticks `with` ticks inside

\n", } doTests(t, tests) }