all repos — grayfriday @ 3af64a90ad74a0c4bd13fc63b41b298b8a09ac21

blackfriday fork with a few changes

block_test.go (view raw)

  1//
  2// Black Friday Markdown Processor
  3// Originally based on http://github.com/tanoku/upskirt
  4// by Russ Ross <russ@russross.com>
  5//
  6
  7//
  8// Unit tests for block parsing
  9//
 10
 11package blackfriday
 12
 13import (
 14	"testing"
 15)
 16
 17func runMarkdownBlock(input string, extensions uint32) string {
 18	html_flags := 0
 19	html_flags |= HTML_USE_XHTML
 20
 21	renderer := HtmlRenderer(html_flags)
 22
 23	return string(Markdown([]byte(input), renderer, extensions))
 24}
 25
 26func doTestsBlock(t *testing.T, tests []string, extensions uint32) {
 27	for i := 0; i+1 < len(tests); i += 2 {
 28		input := tests[i]
 29		expected := tests[i+1]
 30		actual := runMarkdownBlock(input, extensions)
 31		if actual != expected {
 32			t.Errorf("\nInput   [%#v]\nExpected[%#v]\nActual  [%#v]",
 33				input, expected, actual)
 34		}
 35	}
 36}
 37
 38func TestPrefixHeaderNoExtensions(t *testing.T) {
 39	var tests = []string{
 40		"# Header 1\n",
 41		"<h1>Header 1</h1>\n",
 42
 43		"## Header 2\n",
 44		"<h2>Header 2</h2>\n",
 45
 46		"### Header 3\n",
 47		"<h3>Header 3</h3>\n",
 48
 49		"#### Header 4\n",
 50		"<h4>Header 4</h4>\n",
 51
 52		"##### Header 5\n",
 53		"<h5>Header 5</h5>\n",
 54
 55		"###### Header 6\n",
 56		"<h6>Header 6</h6>\n",
 57
 58		"####### Header 7\n",
 59		"<h6># Header 7</h6>\n",
 60
 61		"#Header 1\n",
 62		"<h1>Header 1</h1>\n",
 63
 64		"##Header 2\n",
 65		"<h2>Header 2</h2>\n",
 66
 67		"###Header 3\n",
 68		"<h3>Header 3</h3>\n",
 69
 70		"####Header 4\n",
 71		"<h4>Header 4</h4>\n",
 72
 73		"#####Header 5\n",
 74		"<h5>Header 5</h5>\n",
 75
 76		"######Header 6\n",
 77		"<h6>Header 6</h6>\n",
 78
 79		"#######Header 7\n",
 80		"<h6>#Header 7</h6>\n",
 81
 82		"Hello\n# Header 1\nGoodbye\n",
 83		"<p>Hello</p>\n\n<h1>Header 1</h1>\n\n<p>Goodbye</p>\n",
 84
 85		"* List\n# Header\n* List\n",
 86		"<ul>\n<li><p>List</p>\n\n<h1>Header</h1></li>\n<li><p>List</p></li>\n</ul>\n",
 87
 88		"* List\n#Header\n* List\n",
 89		"<ul>\n<li><p>List</p>\n\n<h1>Header</h1></li>\n<li><p>List</p></li>\n</ul>\n",
 90
 91		"*   List\n    * Nested list\n    # Nested header\n",
 92		"<ul>\n<li><p>List</p>\n\n<ul>\n<li><p>Nested list</p>\n\n" +
 93			"<h1>Nested header</h1></li>\n</ul></li>\n</ul>\n",
 94
 95		"*   List\n    * Sublist\n    Not a header\n    ------\n",
 96		"<ul>\n<li>List\n\n<ul>\n<li>Sublist\nNot a header\n------</li>\n</ul></li>\n</ul>\n",
 97	}
 98	doTestsBlock(t, tests, 0)
 99}
100
101func TestPrefixHeaderSpaceExtension(t *testing.T) {
102	var tests = []string{
103		"# Header 1\n",
104		"<h1>Header 1</h1>\n",
105
106		"## Header 2\n",
107		"<h2>Header 2</h2>\n",
108
109		"### Header 3\n",
110		"<h3>Header 3</h3>\n",
111
112		"#### Header 4\n",
113		"<h4>Header 4</h4>\n",
114
115		"##### Header 5\n",
116		"<h5>Header 5</h5>\n",
117
118		"###### Header 6\n",
119		"<h6>Header 6</h6>\n",
120
121		"####### Header 7\n",
122		"<p>####### Header 7</p>\n",
123
124		"#Header 1\n",
125		"<p>#Header 1</p>\n",
126
127		"##Header 2\n",
128		"<p>##Header 2</p>\n",
129
130		"###Header 3\n",
131		"<p>###Header 3</p>\n",
132
133		"####Header 4\n",
134		"<p>####Header 4</p>\n",
135
136		"#####Header 5\n",
137		"<p>#####Header 5</p>\n",
138
139		"######Header 6\n",
140		"<p>######Header 6</p>\n",
141
142		"#######Header 7\n",
143		"<p>#######Header 7</p>\n",
144
145		"Hello\n# Header 1\nGoodbye\n",
146		"<p>Hello</p>\n\n<h1>Header 1</h1>\n\n<p>Goodbye</p>\n",
147
148		"* List\n# Header\n* List\n",
149		"<ul>\n<li><p>List</p>\n\n<h1>Header</h1></li>\n<li><p>List</p></li>\n</ul>\n",
150
151		"* List\n#Header\n* List\n",
152		"<ul>\n<li>List\n#Header</li>\n<li>List</li>\n</ul>\n",
153
154		"*   List\n    * Nested list\n    # Nested header\n",
155		"<ul>\n<li><p>List</p>\n\n<ul>\n<li><p>Nested list</p>\n\n" +
156			"<h1>Nested header</h1></li>\n</ul></li>\n</ul>\n",
157
158		"*   List\n    * Sublist\n    Not a header\n    ------\n",
159		"<ul>\n<li>List\n\n<ul>\n<li>Sublist\nNot a header\n------</li>\n</ul></li>\n</ul>\n",
160	}
161	doTestsBlock(t, tests, EXTENSION_SPACE_HEADERS)
162}