forked from miekg/mmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cm_test.go
94 lines (75 loc) · 2.48 KB
/
cm_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Unit tests for commonmark parsing
package mmark
import (
"testing"
)
func runMarkdownCommonMark(input string, extensions int) string {
htmlFlags := 0
renderer := HtmlRenderer(htmlFlags, "", "")
return Parse([]byte(input), renderer, extensions).String()
}
func doTestsCommonMark(t *testing.T, tests []string, extensions int) {
// catch and report panics
var candidate string
defer func() {
if err := recover(); err != nil {
t.Errorf("\npanic while processing [%#v]: %s\n", candidate, err)
}
}()
for i := 0; i+1 < len(tests); i += 2 {
input := tests[i]
candidate = input
expected := tests[i+1]
actual := runMarkdownCommonMark(candidate, extensions)
if actual != expected {
t.Errorf("\nInput [%#v]\nExpected[%#v]\nActual [%#v]",
candidate, expected, actual)
}
// now test every substring to stress test bounds checking
if !testing.Short() {
for start := 0; start < len(input); start++ {
for end := start + 1; end <= len(input); end++ {
candidate = input[start:end]
_ = runMarkdownBlock(candidate, extensions)
}
}
}
}
}
func TestPrefixHeaderCommonMark_29(t *testing.T) {
var tests = []string{
"# hallo\n\n # hallo\n\n # hallo\n\n # hallo\n\n # hallo\n",
"<h1>hallo</h1>\n\n<h1>hallo</h1>\n\n<h1>hallo</h1>\n\n<h1>hallo</h1>\n\n<pre><code># hallo\n</code></pre>\n",
}
doTestsCommonMark(t, tests, 0)
}
func TestHRuleCommonMark_18_22(t *testing.T) {
var tests = []string{
"* List\n * Sublist\n Not a header\n ------\n",
"<ul>\n<li>List\n\n<ul>\n<li>Sublist\nNot a header</li>\n</ul>\n\n<hr></li>\n</ul>\n",
"- Foo\n- * * *\n- Bar\n",
"<ul>\n<li>Foo</li>\n<li>* * *</li>\n<li>Bar</li>\n</ul>\n",
"* Foo\n* * * *\n",
"<ul>\n<li>Foo</li>\n</ul>\n\n<hr>\n",
"* Foo\n * - - -\n",
"<ul>\n<li>Foo\n\n<ul>\n<li>- - -</li>\n</ul></li>\n</ul>\n",
}
doTestsCommonMark(t, tests, 0)
}
func TestFencedCodeBlockCommonMark_81(t *testing.T) {
var tests = []string{
" ```\n aaa\naaa\n```\n",
"<pre><code>aaa\naaa\n</code></pre>\n",
"```\n bbb\nbbb\n```\n",
"<pre><code> bbb\nbbb\n</code></pre>\n",
// disabled this behavior, using blackfriday's standard now.
"```\nbbb\nbbb\n",
//"<pre><code>bbb\nbbb\n</code></pre>\n",
"<p>```\nbbb\nbbb</p>\n",
"~~~~ ruby\ndef foo(x)\n return 3\nend\n~~~~\n",
"<pre><code class=\"language-ruby\">def foo(x)\n return 3\nend\n</code></pre>\n",
"```\n[foo]: /url\n```\n",
"<pre><code>[foo]: /url\n</code></pre>\n",
}
doTestsCommonMark(t, tests, EXTENSION_FENCED_CODE)
}