-
Notifications
You must be signed in to change notification settings - Fork 0
/
sisyphus_test.go
209 lines (190 loc) · 5.11 KB
/
sisyphus_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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
package sisyphus_test
import (
"blekksprut.net/sisyphus"
"testing"
)
var htmlcases = [][]string{
{"text\nanother line\n\n", "<p>text\n<br>another line\n\n"},
{"# header", "<h1>header</h1>\n"},
{"## header", "<h2>header</h2>\n"},
{"### header", "<h3>header</h3>\n"},
{"* list", "<ul>\n<li>list\n</ul>\n"},
{"* 1\n> 2", "<ul>\n<li>1\n</ul>\n<blockquote>\n<p>2\n</blockquote>\n"},
{"=> link", "<p><a href='link'>link</a>\n"},
{"> hello\n> hm", "<blockquote>\n<p>hello\n<br>hm\n</blockquote>\n"},
{"> hello\nhm", "<blockquote>\n<p>hello\n</blockquote>\n<p>hm\n"},
{"```\npre", "<pre>pre\n</pre>\n"},
{"```\npre\n```", "<pre>pre\n</pre>\n"},
}
var mdcases = [][]string{
{"text\nanother line\n", "text\nanother line\n"},
{"# header", "# header\n"},
{"## header", "## header\n"},
{"### header", "### header\n"},
{"* list", "* list\n"},
{"* 1\n> 2", "* 1\n> 2\n"},
{"=> link", "[link](link)\n"},
{"> hello\n> hm", "> hello\n> hm\n"},
{"> hello\nhm", "> hello\nhm\n"},
{"```\npre", "```\npre\n```\n"},
}
func TestHtml(t *testing.T) {
for _, c := range htmlcases {
html := sisyphus.Convert(c[0], &sisyphus.Html{})
if html != c[1] {
t.Errorf("%s should be %s", html, c[1])
}
}
}
func TestMarkdown(t *testing.T) {
for _, c := range mdcases {
md := sisyphus.Convert(c[0], &sisyphus.Markdown{})
if md != c[1] {
t.Errorf("%s should be %s", md, c[1])
}
}
}
func TestCallback(t *testing.T) {
flavor := &sisyphus.Markdown{}
flavor.OnLink(".jpg", func(_, _, _ string) string {
return "hijacked!"
})
gmi := "=> test.jpg"
expect := "hijacked!\n"
html := sisyphus.Convert(gmi, flavor)
if html != expect {
t.Errorf("%s should be %s", html, expect)
}
}
func TestAspeq(t *testing.T) {
flavor := &sisyphus.Html{}
flavor.OnLink(".jpg", sisyphus.Aspeq(".", false))
gmi := "=> ume.jpg 梅ちゃん"
expect := "<p><img src='ume.jpg' class=super16 alt='梅ちゃん'>\n"
html := sisyphus.Convert(gmi, flavor)
if html != expect {
t.Errorf("%s should be %s", html, expect)
}
}
func TestAspeqMissing(t *testing.T) {
flavor := &sisyphus.Html{}
flavor.OnLink(".jpg", sisyphus.Aspeq(".", true))
gmi := "=> notfound.jpg"
expect := "<p><img src='notfound.jpg' class=unknown alt=''>\n"
html := sisyphus.Convert(gmi, flavor)
if html != expect {
t.Errorf("%s should be %s", html, expect)
}
}
func TestSelf(t *testing.T) {
gmi := "=> /here a link"
html := sisyphus.Convert(gmi, &sisyphus.Html{Self: "/here"})
expect := "<p><a class=self href='/here'>a link</a>\n"
if html != expect {
t.Errorf("%s should be %s", html, expect)
}
}
func TestHtmlWrap(t *testing.T) {
gmi := "wrap me up"
flavor := sisyphus.Html{}
flavor.Wrap("article")
html := sisyphus.Convert(gmi, &flavor)
expect := "<article>\n<p>wrap me up\n</article>\n"
if html != expect {
t.Errorf("%s should be %s", html, expect)
}
}
func TestHtmlEmptyWrap(t *testing.T) {
gmi := "do not wrap me up"
flavor := sisyphus.Html{}
flavor.Wrap("")
html := sisyphus.Convert(gmi, &flavor)
expect := "<p>do not wrap me up\n"
if html != expect {
t.Errorf("%s should be %s", html, expect)
}
}
func TestMarkdownWrap(t *testing.T) {
gmi := "wrap me up"
flavor := sisyphus.Markdown{}
flavor.Wrap("```")
html := sisyphus.Convert(gmi, &flavor)
expect := "```wrap me up\n```"
if html != expect {
t.Errorf("%s should be %s", html, expect)
}
}
func TestMarkdownEmptyWrap(t *testing.T) {
gmi := "do not wrap me up"
flavor := sisyphus.Markdown{}
flavor.Wrap("")
html := sisyphus.Convert(gmi, &flavor)
expect := "do not wrap me up\n"
if html != expect {
t.Errorf("%s should be %s", html, expect)
}
}
func TestHtmlLinkTag(t *testing.T) {
flavor := &sisyphus.Html{}
flavor.OnLink("photo", func(_, _, _ string) string {
return "!"
})
gmi := "=> test.jpg (photo)"
expect := "<p>!\n"
html := sisyphus.Convert(gmi, flavor)
if html != expect {
t.Errorf("%s should be %s", html, expect)
}
}
func TestHtmlQuote(t *testing.T) {
flavor := &sisyphus.Html{}
flavor.OnQuote(func(_ string) string {
return "!"
})
gmi := ">>12435"
expect := "<blockquote>\n<p>!\n</blockquote>\n"
html := sisyphus.Convert(gmi, flavor)
if html != expect {
t.Errorf("%s should be %s", html, expect)
}
}
func TestMdWrap(t *testing.T) {
gmi := "wrap me up"
flavor := sisyphus.Markdown{}
flavor.Wrap("*")
md := sisyphus.Convert(gmi, &flavor)
expect := "*wrap me up\n*"
if md != expect {
t.Errorf("%s should be %s", md, expect)
}
}
func TestMdQuote(t *testing.T) {
flavor := &sisyphus.Markdown{}
flavor.OnQuote(func(_ string) string {
return "!"
})
gmi := ">>12435"
expect := "!\n"
md := sisyphus.Convert(gmi, flavor)
if md != expect {
t.Errorf("%s should be %s", md, expect)
}
}
func TestGreentext(t *testing.T) {
flavor := &sisyphus.Html{Greentext: true}
gmi := "> 12435"
expect := "<blockquote>\n<p>> 12435\n</blockquote>\n"
html := sisyphus.Convert(gmi, flavor)
if html != expect {
t.Errorf("%s should be %s", html, expect)
}
}
func TestGreentextLink(t *testing.T) {
flavor := &sisyphus.Html{Greentext: true}
gmi := "=> / a link"
expect := "<p><a href='/'>=> a link</a>\n"
html := sisyphus.Convert(gmi, flavor)
if html != expect {
t.Errorf("%s should be %s", html, expect)
}
}