-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
confluence_test.go
356 lines (302 loc) · 8.16 KB
/
confluence_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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
package confluence_test
import (
"testing"
bfconfluence "github.com/kentaro-m/blackfriday-confluence"
bf "github.com/russross/blackfriday/v2"
)
type testData struct {
input string
expected string
flags bfconfluence.Flag
extensions bf.Extensions
}
func doTest(t *testing.T, tdt []testData) {
for _, v := range tdt {
renderer := &bfconfluence.Renderer{Flags: v.flags}
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 TestParagraph(t *testing.T) {
tdt := []testData{
{input: "single paragraph", expected: "single paragraph", extensions: bf.CommonExtensions},
{input: `first line\
second line`, expected: "first line\nsecond line", extensions: bf.CommonExtensions},
{input: `first line
second line
third line
fourth line`, expected: "first line\nsecond line\nthird line\nfourth line", extensions: bf.CommonExtensions},
{input: `first line\
second line
third line\
fourth line`, expected: "first line\nsecond line\nthird line\n\nfourth line", extensions: bf.CommonExtensions},
{input: `first line
second line
third line
fourth line`, expected: "first line\nsecond line\nthird line\n\nfourth line", extensions: bf.CommonExtensions},
{input: `first line
second line`, expected: "first line\n\nsecond line", extensions: bf.CommonExtensions},
}
doTest(t, tdt)
}
func TestHardLineBreak(t *testing.T) {
tdt := []testData{
{input: `first line\
second line`, expected: "first line\nsecond line", extensions: bf.CommonExtensions | bf.HardLineBreak},
{input: `first line
second line
third line
fourth line`, expected: "first line\nsecond line\nthird line\nfourth line", extensions: bf.CommonExtensions | bf.HardLineBreak},
{input: `first line\
second line
third line\
fourth line`, expected: "first line\nsecond line\nthird line\n\nfourth line", extensions: bf.CommonExtensions | bf.HardLineBreak},
{input: `first line
second line
third line
fourth line`, expected: "first line\n\nsecond line\nthird line\n\nfourth line", extensions: bf.CommonExtensions | bf.HardLineBreak},
{input: `first line
second line`, expected: "first line\n\nsecond line", extensions: bf.CommonExtensions | bf.HardLineBreak},
}
doTest(t, tdt)
}
func TestHeading(t *testing.T) {
tdt := []testData{
{input: "# Section\n", expected: "h1. Section\n", extensions: bf.CommonExtensions},
{input: "## SubSection\n", expected: "h2. SubSection\n", extensions: bf.CommonExtensions},
{input: "### SubSubSection\n", expected: "h3. SubSubSection\n", extensions: bf.CommonExtensions},
}
doTest(t, tdt)
}
func TestBlockQuote(t *testing.T) {
tdt := []testData{
{
input: "> block quote",
expected: "{quote}\nblock quote\n\n{quote}\n\n",
extensions: bf.CommonExtensions,
},
{
input: "> block quote\n> block quote",
expected: "{quote}\nblock quote\nblock quote\n\n{quote}\n\n",
extensions: bf.CommonExtensions,
},
}
doTest(t, tdt)
}
func TestCode(t *testing.T) {
tdt := []testData{
{
input: "this is `foo`.",
expected: "this is {{foo}}.\n\n",
extensions: bf.CommonExtensions,
},
}
doTest(t, tdt)
}
func TestCodeBlock(t *testing.T) {
tdt := []testData{
{
input: "```\n\nint main(void) {\n printf(\"Hello, world.\"); \n}\n```",
expected: "{code}\n\nint main(void) {\n printf(\"Hello, world.\"); \n}\n{code}\n\n",
extensions: bf.CommonExtensions,
},
{
input: "```c\n\nint main(void) {\n printf(\"Hello, world.\"); \n}\n```",
expected: "{code:language=c}\n\nint main(void) {\n printf(\"Hello, world.\"); \n}\n{code}\n\n",
extensions: bf.CommonExtensions,
},
{
input: "```c\n\nint main(void) {\n printf(\"Hello, world.\"); \n}\n```",
expected: "{code:language=c}\n\nint main(void) {\n printf(\"Hello, world.\"); \n}\n{code}\n\n",
flags: bfconfluence.InformationMacros,
extensions: bf.CommonExtensions,
},
{
input: "```tip\n\nhighlighting tip\n```",
expected: "{tip}\n\nhighlighting tip\n{tip}\n\n",
flags: bfconfluence.InformationMacros,
extensions: bf.CommonExtensions,
},
{
input: "```note\n\nhighlighting note\n```",
expected: "{note}\n\nhighlighting note\n{note}\n\n",
flags: bfconfluence.InformationMacros,
extensions: bf.CommonExtensions,
},
{
input: "```warning\n\nhighlighting warning\n```",
expected: "{warning}\n\nhighlighting warning\n{warning}\n\n",
flags: bfconfluence.InformationMacros,
extensions: bf.CommonExtensions,
},
{
input: "```info\n\nhighlighting infomation\n```",
expected: "{info}\n\nhighlighting infomation\n{info}\n\n",
flags: bfconfluence.InformationMacros,
extensions: bf.CommonExtensions,
},
}
doTest(t, tdt)
}
func TestImage(t *testing.T) {
tdt := []testData{
{
input: "![](./sample.png)",
expected: "!./sample.png!\n\n",
extensions: bf.CommonExtensions,
},
}
doTest(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,
},
{
input: "* list1\n* list2\n * list 3\n * list 4\n* list 5\n",
expected: "* list1\n* list2\n** list 3\n** list 4\n* list 5\n\n",
extensions: bf.CommonExtensions,
},
}
doTest(t, tdt)
}
func TestOrderedList(t *testing.T) {
tdt := []testData{
{
input: "1. list1\n1. list2\n1. list3\n",
expected: "# list1\n# list2\n# list3\n\n",
extensions: bf.CommonExtensions,
},
{
input: "1. list1\n 1. list2\n1. list3\n",
expected: "# list1\n## list2\n# list3\n\n",
extensions: bf.CommonExtensions,
},
}
doTest(t, tdt)
}
func TestLink(t *testing.T) {
tdt := []testData{
{
input: "[Example Domain](http://www.example.com/)",
expected: "[Example Domain|http://www.example.com/]\n\n",
extensions: bf.CommonExtensions,
},
}
doTest(t, tdt)
}
func TestHorizontalRule(t *testing.T) {
tdt := []testData{
{
input: "- - - -",
expected: "----\n",
extensions: bf.CommonExtensions,
},
}
doTest(t, tdt)
}
func TestStrong(t *testing.T) {
tdt := []testData{
{
input: "**strong text**",
expected: "*strong text*\n\n",
extensions: bf.CommonExtensions,
},
}
doTest(t, tdt)
}
func TestEmph(t *testing.T) {
tdt := []testData{
{
input: "_emph text_",
expected: "_emph text_\n\n",
extensions: bf.CommonExtensions,
},
}
doTest(t, tdt)
}
func TestDel(t *testing.T) {
tdt := []testData{
{
input: "~~del text~~",
expected: "-del text-\n\n",
extensions: bf.CommonExtensions,
},
}
doTest(t, tdt)
}
func TestTable(t *testing.T) {
tdt := []testData{
{
input: `
First Header | Second Header
------------- | -------------
Content Cell | Content Cell
Content Cell | Content Cell`,
expected: `||First Header||Second Header||
|Content Cell|Content Cell|
|Content Cell|Content Cell|
`,
extensions: bf.CommonExtensions,
},
{
input: `
|a |b |c |
|---|---|---|
|1 |2 |3 |
|4 |5 |6 |`,
expected: `||a||b||c||
|1|2|3|
|4|5|6|
`,
extensions: bf.CommonExtensions,
},
}
doTest(t, tdt)
}
func TestEsc(t *testing.T) {
tdt := []testData{
{
input: "*-_+",
expected: "\\*\\-\\_\\+",
extensions: bf.CommonExtensions,
},
}
doTest(t, tdt)
}
func TestMacros(t *testing.T) {
tdt := []testData{
{
input: "This page displays a list of children\n{children:reverse=true|sort=creation|style=h4|page=Home|all=true}",
expected: "This page displays a list of children\n{children:reverse=true|sort=creation|style=h4|page=Home|all=true}",
flags: bfconfluence.IgnoreMacroEscaping,
extensions: bf.CommonExtensions,
},
{
input: "This page contains some random use of {this}",
expected: "This page contains some random use of \\{this}",
extensions: bf.CommonExtensions,
},
}
doTest(t, tdt)
}
func TestRun(t *testing.T) {
input := `
# Section
hello, world.
`
expected := `h1. Section
hello, world.
`
output := string(bfconfluence.Run([]byte(input)))
if output != expected {
t.Errorf("got:%v\nwant:%v", output, expected)
}
}