all repos — grayfriday @ 2abc3af015f3538c33b3d8b290e402d05bd0c3e0

blackfriday fork with a few changes

starting inline unit tests, fix a few minor bugs they exposed
Russ Ross russ@russross.com
Wed, 01 Jun 2011 12:17:17 -0600
commit

2abc3af015f3538c33b3d8b290e402d05bd0c3e0

parent

87f1e83da24d67e492b375bb073a5bb4ca4838f4

3 files changed, 252 insertions(+), 0 deletions(-)

jump to
M .gitignore.gitignore

@@ -3,4 +3,5 @@ *.swp

*.8 *.6 _obj +_test* markdown
M inline.goinline.go

@@ -124,6 +124,7 @@ }

} if i < nb && end >= len(data) { + out.WriteByte('`') return 0 // no matching delimiter }
A inline_test.go

@@ -0,0 +1,250 @@

+// +// Black Friday Markdown Processor +// Originally based on http://github.com/tanoku/upskirt +// by Russ Ross <russ@russross.com> +// + +// +// 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", + "<p>nothing inline</p>\n", + + "simple *inline* test\n", + "<p>simple <em>inline</em> test</p>\n", + + "*at the* beginning\n", + "<p><em>at the</em> beginning</p>\n", + + "at the *end*\n", + "<p>at the <em>end</em></p>\n", + + "*try two* in *one line*\n", + "<p><em>try two</em> in <em>one line</em></p>\n", + + "over *two\nlines* test\n", + "<p>over <em>two\nlines</em> test</p>\n", + + "odd *number of* markers* here\n", + "<p>odd <em>number of</em> markers* here</p>\n", + + "odd *number\nof* markers* here\n", + "<p>odd <em>number\nof</em> markers* here</p>\n", + + "simple _inline_ test\n", + "<p>simple <em>inline</em> test</p>\n", + + "_at the_ beginning\n", + "<p><em>at the</em> beginning</p>\n", + + "at the _end_\n", + "<p>at the <em>end</em></p>\n", + + "_try two_ in _one line_\n", + "<p><em>try two</em> in <em>one line</em></p>\n", + + "over _two\nlines_ test\n", + "<p>over <em>two\nlines</em> test</p>\n", + + "odd _number of_ markers_ here\n", + "<p>odd <em>number of</em> markers_ here</p>\n", + + "odd _number\nof_ markers_ here\n", + "<p>odd <em>number\nof</em> markers_ here</p>\n", + + "mix of *markers_\n", + "<p>mix of *markers_</p>\n", + } + doTests(t, tests) +} + +func TestStrong(t *testing.T) { + var tests = []string{ + "nothing inline\n", + "<p>nothing inline</p>\n", + + "simple **inline** test\n", + "<p>simple <strong>inline</strong> test</p>\n", + + "**at the** beginning\n", + "<p><strong>at the</strong> beginning</p>\n", + + "at the **end**\n", + "<p>at the <strong>end</strong></p>\n", + + "**try two** in **one line**\n", + "<p><strong>try two</strong> in <strong>one line</strong></p>\n", + + "over **two\nlines** test\n", + "<p>over <strong>two\nlines</strong> test</p>\n", + + "odd **number of** markers** here\n", + "<p>odd <strong>number of</strong> markers** here</p>\n", + + "odd **number\nof** markers** here\n", + "<p>odd <strong>number\nof</strong> markers** here</p>\n", + + "simple __inline__ test\n", + "<p>simple <strong>inline</strong> test</p>\n", + + "__at the__ beginning\n", + "<p><strong>at the</strong> beginning</p>\n", + + "at the __end__\n", + "<p>at the <strong>end</strong></p>\n", + + "__try two__ in __one line__\n", + "<p><strong>try two</strong> in <strong>one line</strong></p>\n", + + "over __two\nlines__ test\n", + "<p>over <strong>two\nlines</strong> test</p>\n", + + "odd __number of__ markers__ here\n", + "<p>odd <strong>number of</strong> markers__ here</p>\n", + + "odd __number\nof__ markers__ here\n", + "<p>odd <strong>number\nof</strong> markers__ here</p>\n", + + "mix of **markers__\n", + "<p>mix of **markers__</p>\n", + } + doTests(t, tests) +} + +func TestEmphasisMix(t *testing.T) { + var tests = []string{ + "***triple emphasis***\n", + "<p><strong><em>triple emphasis</em></strong></p>\n", + + "***triple\nemphasis***\n", + "<p><strong><em>triple\nemphasis</em></strong></p>\n", + + "___triple emphasis___\n", + "<p><strong><em>triple emphasis</em></strong></p>\n", + + "***triple emphasis___\n", + "<p>***triple emphasis___</p>\n", + + "*__triple emphasis__*\n", + "<p><em><strong>triple emphasis</strong></em></p>\n", + + "__*triple emphasis*__\n", + "<p><strong><em>triple emphasis</em></strong></p>\n", + + "**improper *nesting** is* bad\n", + "<p><strong>improper *nesting</strong> is* bad</p>\n", + + "*improper **nesting* is** bad\n", + "<p><em>improper **nesting</em> is** bad</p>\n", + } + doTests(t, tests) +} + +func TestStrikeThrough(t *testing.T) { + var tests = []string{ + "nothing inline\n", + "<p>nothing inline</p>\n", + + "simple ~~inline~~ test\n", + "<p>simple <del>inline</del> test</p>\n", + + "~~at the~~ beginning\n", + "<p><del>at the</del> beginning</p>\n", + + "at the ~~end~~\n", + "<p>at the <del>end</del></p>\n", + + "~~try two~~ in ~~one line~~\n", + "<p><del>try two</del> in <del>one line</del></p>\n", + + "over ~~two\nlines~~ test\n", + "<p>over <del>two\nlines</del> test</p>\n", + + "odd ~~number of~~ markers~~ here\n", + "<p>odd <del>number of</del> markers~~ here</p>\n", + + "odd ~~number\nof~~ markers~~ here\n", + "<p>odd <del>number\nof</del> markers~~ here</p>\n", + } + doTests(t, tests) +} + +func TestCodeSpan(t *testing.T) { + var tests = []string{ + "`source code`\n", + "<p><code>source code</code></p>\n", + + "` source code with spaces `\n", + "<p><code>source code with spaces</code></p>\n", + + "` source code with spaces `not here\n", + "<p><code>source code with spaces</code>not here</p>\n", + + "a `single marker\n", + "<p>a `single marker</p>\n", + + "a single multi-tick marker with ``` no text\n", + "<p>a single multi-tick marker with ``` no text</p>\n", + + "markers with ` ` a space\n", + "<p>markers with <code></code> a space</p>\n", + + "`source code` and a `stray\n", + "<p><code>source code</code> and a `stray</p>\n", + + "`source with _awkward characters_ in it`\n", + "<p><code>source with _awkward characters_ in it</code></p>\n", + + "`split over\ntwo lines`\n", + "<p><code>split over\ntwo lines</code></p>\n", + + "```multiple ticks``` for the marker\n", + "<p><code>multiple ticks</code> for the marker</p>\n", + + "```multiple ticks `with` ticks inside```\n", + "<p><code>multiple ticks `with` ticks inside</code></p>\n", + } + doTests(t, tests) +}