-
Notifications
You must be signed in to change notification settings - Fork 0
/
tw5-wikitext_test.go
251 lines (239 loc) · 6.7 KB
/
tw5-wikitext_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
package main
import (
"testing"
)
func Test_convertPairedFormatting(t *testing.T) {
type args struct {
txt string
}
tests := []struct {
name string
args args
want string
}{
{"bold", args{"''bold''"}, "**bold**"},
{"italic", args{"//italic//"}, "*italic*"},
{"underlined", args{"__underlined__"}, "<u>underlined</u>"},
{"superscript", args{"^^superscript^^"}, "<sup>superscript</sup>"},
{"subscript", args{",,subscript,,"}, "<sub>subscript</sub>"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := convertPairedFormatting(tt.args.txt); got != tt.want {
t.Errorf("convertPairedFormatting() = %v, want %v", got, tt.want)
}
})
}
}
// func Test_tw5Tiddler_markdownText(t *testing.T) {
// tests := []struct {
// name string
// tid tw5Tiddler
// want string
// }{
// // TODO: Add test cases.
// }
// for _, tt := range tests {
// t.Run(tt.name, func(t *testing.T) {
// if got := tt.tid.markdownText(); got != tt.want {
// t.Errorf("tw5Tiddler.markdownText() = %v, want %v", got, tt.want)
// }
// })
// }
// }
func Test_convertHeadings(t *testing.T) {
type args struct {
txt string
}
tests := []struct {
name string
args args
want string
}{
{"Level 0", args{"No Heading"}, "No Heading\n"},
{"Level 1", args{"! Heading"}, "# Heading\n"},
{"Level 2", args{"!!Heading"}, "## Heading\n"},
{"Level 3", args{" !!! Heading"}, "### Heading\n"},
{"Level 4", args{" !!!!Heading"}, "#### Heading\n"},
{"Level 5", args{"!!!!! Heading!!"}, "##### Heading!!\n"},
{"Level 6", args{"!!! !!! Heading"}, "### !!! Heading\n"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := convertHeadings(tt.args.txt); got != tt.want {
t.Errorf("convertHeadings() = `%v`, want `%v`", got, tt.want)
}
})
}
}
func Test_convertLinks(t *testing.T) {
type args struct {
txt string
}
tests := []struct {
name string
args args
want string
}{
{"no links", args{"[link]] [text|link]] [link space]] [text|link space]] ext[link]] ext[text|link]] ext[link space]] ext[text|link space]]"}, "[link]] [text|link]] [link space]] [text|link space]] ext[link]] ext[text|link]] ext[link space]] ext[text|link space]]\n"},
{"links", args{"[[link]] [[text|link]] [[link space]] [[text|link space]] [ext[link]] [ext[text|link]] [ext[link space]] [ext[text|link space]]"}, "[link](link.md) [text](link.md) [link space](<link space.md>) [text](<link space.md>) [link](link.md) [text](link.md) [link space](<link space.md>) [text](<link space.md>)\n"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := convertLinks(tt.args.txt); got != tt.want {
t.Errorf("convertLinks() = %v, want %v", got, tt.want)
}
})
}
}
func Test_convertLink(t *testing.T) {
type args struct {
link string
}
tests := []struct {
name string
args args
want string
}{
{"link 1", args{"[[link]]"}, "[link](link.md)"},
{"link 2", args{"[[text|link]]"}, "[text](link.md)"},
{"link 3", args{"[[link space]]"}, "[link space](<link space.md>)"},
{"link 4", args{"[[text|link space]]"}, "[text](<link space.md>)"},
{"link 5", args{"[ext[link]]"}, "[link](link.md)"},
{"link 6", args{"[ext[text|link]]"}, "[text](link.md)"},
{"link 7", args{"[ext[link space]]"}, "[link space](<link space.md>)"},
{"link 8", args{"[ext[text|link space]]"}, "[text](<link space.md>)"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := convertLink(tt.args.link); got != tt.want {
t.Errorf("convertLink() = %v, want %v", got, tt.want)
}
})
}
}
func Test_convertTables(t *testing.T) {
type args struct {
txt string
}
tests := []struct {
name string
args args
want string
}{
{"table 1", args{"|!Hdr|!Hdr|\n|c|c|\n"}, "|Hdr|Hdr|\n|---|---|\n|c|c|\n"},
{"table 2", args{"|!Hdr|!Hdr| \n|c|c| \n"}, "|Hdr|Hdr| \n|---|---|\n|c|c| \n"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := convertTables(tt.args.txt); got != tt.want {
t.Errorf("convertTables() = `%v`, want `%v`", got, tt.want)
}
})
}
}
func Test_convertNumberedLists(t *testing.T) {
type args struct {
t string
}
tests := []struct {
name string
args args
want string
}{
{"num list 1", args{"# one"}, "1. one\n"},
{"num list 2", args{"## two"}, " 1. two\n"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := convertNumberedLists(tt.args.t); got != tt.want {
t.Errorf("convertNumberedLists() = `%v`, want `%v`", got, tt.want)
}
})
}
}
func Test_convertBulletedLists(t *testing.T) {
type args struct {
t string
}
tests := []struct {
name string
args args
want string
}{
{"bul list 1", args{"* one"}, "* one\n"},
{"bul list 2", args{"** two"}, " * two\n"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := convertBulletedLists(tt.args.t); got != tt.want {
t.Errorf("convertBulletedLists() = `%v`, want `%v`", got, tt.want)
}
})
}
}
// func Test_convertWikiLinks(t *testing.T) {
// type args struct {
// txt string
// }
// tests := []struct {
// name string
// args args
// want string
// }{
// {"wikilink 1", args{" CamelCase "}, " [[CamelCase]] \n"},
// {"wikilink 2", args{" CamelCCase "}, " [[CamelCCase]] \n"},
// {"wikilink 3", args{" CamelC99 "}, " [[CamelC99]] \n"},
// {"wikilink 3", args{"[[Advanced Search|$:/AdvancedSearch]]"}, "[[Advanced Search|$:/AdvancedSearch]]\n"},
// {"~wikilink 1", args{" ~CamelCase "}, " CamelCase \n"},
// }
// for _, tt := range tests {
// t.Run(tt.name, func(t *testing.T) {
// if got := convertWikiLinks(tt.args.txt); got != tt.want {
// t.Errorf("convertWikiLinks() = `%v`, want `%v`", got, tt.want)
// }
// })
// }
// }
func Test_addTitle(t *testing.T) {
type args struct {
txt string
title string
}
tests := []struct {
name string
args args
want string
}{
{"add title", args{"Text\n[[link]]", "Title"}, "! Title\n\nText\n[[link]]"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := addTitle(tt.args.txt, tt.args.title); got != tt.want {
t.Errorf("addTitle() = %v, want %v", got, tt.want)
}
})
}
}
func Test_convertTransclusion(t *testing.T) {
type args struct {
txt string
}
tests := []struct {
name string
args args
want string
}{
{"trans 1", args{"{{link}}"}, "{{link.md}}\n"},
{"trans 2", args{"{{link space}}"}, "{{link space.md}}\n"},
{"!trans 1", args{"{link space}}"}, "{link space}}\n"},
{"!trans 2", args{"{{link space}"}, "{{link space}\n"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := convertTransclusion(tt.args.txt); got != tt.want {
t.Errorf("convertTransclusion() = `%v`, want `%v`", got, tt.want)
}
})
}
}