forked from karriereat/blackfriday-slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slackdown_test.go
126 lines (105 loc) · 2.52 KB
/
slackdown_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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package slackdown_test
import (
"testing"
slackdown "github.com/moira-alert/blackfriday-slack"
bf "github.com/russross/blackfriday/v2"
)
type testData struct {
input string
expected string
extensions bf.Extensions
}
func runTest(t *testing.T, tdt []testData) {
for _, v := range tdt {
renderer := &slackdown.Renderer{}
md := bf.New(bf.WithRenderer(renderer), bf.WithExtensions(v.extensions))
ast := md.Parse([]byte(v.input))
output := string(renderer.Render(ast))
if output != v.expected {
t.Errorf("got:%v\nwant:%v", output, v.expected)
}
}
}
func TestHeading(t *testing.T) {
tdt := []testData{
{input: "# Head1\n", expected: "*Head1*\n", extensions: bf.CommonExtensions},
{input: "## Head2\n", expected: "*Head2*\n", extensions: bf.CommonExtensions},
{input: "### Head3\n", expected: "*Head3*\n", extensions: bf.CommonExtensions},
}
runTest(t, tdt)
}
func TestCode(t *testing.T) {
tdt := []testData{
{
input: "this is `foo`.",
expected: "this is `foo`.\n\n",
extensions: bf.CommonExtensions,
},
}
runTest(t, tdt)
}
func TestList(t *testing.T) {
tdt := []testData{
{
input: "* list1\n* list2\n* list 3\n",
expected: " - list1\n - list2\n - list 3\n\n",
extensions: bf.CommonExtensions,
},
}
runTest(t, tdt)
}
func TestNestedList(t *testing.T) {
tdt := []testData{
{
input: "* list1\n* list2\n * list3\n * list4",
expected: " - list1\n - list2\n - list3\n - list4\n\n",
extensions: bf.CommonExtensions,
},
{
input: "* list1\n* list2\n * list3\n * list4\n* list5",
expected: " - list1\n - list2\n - list3\n - list4\n - list5\n\n",
extensions: bf.CommonExtensions,
},
}
runTest(t, tdt)
}
func TestOrderedList(t *testing.T) {
tdt := []testData{
{
input: "1. list1\n2. list2\n3. list3\n4. list4",
expected: " 1. list1\n 2. list2\n 3. list3\n 4. list4\n\n",
extensions: bf.CommonExtensions,
},
}
runTest(t, tdt)
}
func TestDel(t *testing.T) {
tdt := []testData{
{
input: "~~del text~~",
expected: "~del text~\n\n",
extensions: bf.CommonExtensions,
},
}
runTest(t, tdt)
}
func TestLink(t *testing.T) {
tdt := []testData{
{
input: "[google.at](http://www.google.at)",
expected: "<http://www.google.at|google.at>\n\n",
extensions: bf.CommonExtensions,
},
}
runTest(t, tdt)
}
func TestBold(t *testing.T) {
tdt := []testData{
{
input: "**bold text**",
expected: "*bold text*\n\n",
extensions: bf.CommonExtensions,
},
}
runTest(t, tdt)
}