forked from go-chi/docgen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
markupTemplates_test.go
305 lines (270 loc) · 6.71 KB
/
markupTemplates_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
package docgen
import (
"fmt"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestBaseTemplate(t *testing.T) {
fmt.Println("Testing Base Template")
//check Base Template for expected template fields: {title}, {css}, {favicon.ico}, {intro}, {routes}
expectedFields := []string{"{title}", "{css}", "{favicon.ico}", "{intro}", "{routes}"}
bt := BaseTemplate()
for _, field := range expectedFields {
assert.True(t, strings.Contains(bt, field))
}
fmt.Println("Base Template Testing Complete")
}
func TestListItem(t *testing.T) {
fmt.Println("Testing List Item")
itemText := "test"
li := ListItem(itemText)
assert.True(t, strings.Contains(li, "<li>"))
assert.True(t, strings.Contains(li, "</li>"))
assert.True(t, strings.Contains(li, itemText))
fmt.Println("List Item Testing Complete")
}
func TestOrderedList(t *testing.T) {
fmt.Println("Testing Ordered List")
li := ListItem("test")
ol := OrderedList(li)
assert.True(t, strings.Contains(ol, "<ol>"))
assert.True(t, strings.Contains(ol, "</ol>"))
assert.True(t, strings.Contains(ol, li))
fmt.Println("Ordered List Testing Complete")
}
func TestUnorderedList(t *testing.T) {
fmt.Println("Testing Unordered List")
li := ListItem("test")
ul := UnorderedList(li)
assert.True(t, strings.Contains(ul, "<ul>"))
assert.True(t, strings.Contains(ul, "</ul>"))
assert.True(t, strings.Contains(ul, li))
fmt.Println("Ordered List Testing Complete")
}
func TestDiv(t *testing.T) {
fmt.Println("Testing Div")
testString := "test"
div := Div(testString)
assert.True(t, strings.Contains(div, "<div>"))
assert.True(t, strings.Contains(div, "</div>"))
assert.True(t, strings.Contains(div, testString))
fmt.Println("Div Testing Complete")
}
func TestP(t *testing.T) {
fmt.Println("Testing P")
testString := "test"
p := P(testString)
assert.True(t, strings.Contains(p, "<p>"))
assert.True(t, strings.Contains(p, "</p>"))
assert.True(t, strings.Contains(p, testString))
fmt.Println("P Testing Complete")
}
func TestHeading(t *testing.T) {
fmt.Println("Testing Headings")
testString := "test"
//h1 - h6 are valid
for index := 1; index <= 6; index++ {
h := Head(index, testString)
headerOpenTag := fmt.Sprintf("<h%v>", index)
headerCloseTag := fmt.Sprintf("</h%v>", index)
assert.True(t, strings.Contains(h, headerOpenTag))
assert.True(t, strings.Contains(h, headerCloseTag))
assert.True(t, strings.Contains(h, testString))
}
//anything below 1 should return an h1 tag
hzero := Head(0, "zero | should return h1")
assert.True(t, strings.Contains(hzero, "<h1>"))
//anything above 6 should return an h6 tag
hseven := Head(7, "seven | should return h6")
assert.True(t, strings.Contains(hseven, "<h6>"))
fmt.Println("Heading Testing Complete")
}
func TestCSS(t *testing.T) {
//MilligramMinCSS
css := MilligramMinCSS()
assert.NotNil(t, css)
//TODO: test CSS better?
}
func TestBaseTemplate1(t *testing.T) {
tests := []struct {
name string
want string
expectFail bool
}{
// TODO: Add test cases.
{"baseTest", BaseTemplate(), false},
{"failBlank", "", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := BaseTemplate(); got != tt.want && !tt.expectFail {
t.Errorf("BaseTemplate() = %v, want %v", got, tt.want)
}
})
}
}
func TestUnorderedList1(t *testing.T) {
type args struct {
listItems string
}
tests := []struct {
name string
args args
want string
expectFail bool
}{
{"unorderedListTest", args{"<li>test</li>"}, UnorderedList(ListItem("test")), false},
{"failBlank", args{"<li>test</li>"}, "", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := UnorderedList(tt.args.listItems); got != tt.want && !tt.expectFail {
t.Errorf("UnorderedList() = %v, want %v", got, tt.want)
}
})
}
}
func TestOrderedList1(t *testing.T) {
type args struct {
listItems string
}
tests := []struct {
name string
args args
want string
expectFail bool
}{
{"orderedListTest", args{"<li>test</li>"}, OrderedList(ListItem("test")), false},
{"failBlank", args{"<li>test</li>"}, "", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := OrderedList(tt.args.listItems); got != tt.want && !tt.expectFail {
t.Errorf("OrderedList() = %v, want %v", got, tt.want)
}
})
}
}
func TestListItem1(t *testing.T) {
type args struct {
text string
}
tests := []struct {
name string
args args
want string
}{
{"baseListItem", args{"test"}, "<li>test</li>"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := ListItem(tt.args.text); got != tt.want {
t.Errorf("ListItem() = %v, want %v", got, tt.want)
}
})
}
}
func TestDiv1(t *testing.T) {
type args struct {
text string
}
tests := []struct {
name string
args args
want string
}{
{"baseDivTest", args{"test"}, "<div>test</div>"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Div(tt.args.text); got != tt.want {
t.Errorf("Div() = %v, want %v", got, tt.want)
}
})
}
}
func TestP1(t *testing.T) {
type args struct {
text string
}
tests := []struct {
name string
args args
want string
}{
{"basePTest", args{"test"}, "<p>test</p>"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := P(tt.args.text); got != tt.want {
t.Errorf("P() = %v, want %v", got, tt.want)
}
})
}
}
func TestHead(t *testing.T) {
type args struct {
level int
text string
}
tests := []struct {
name string
args args
want string
}{
{"baseHeadTest", args{1, "test"}, "<h1>test</h1>"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Head(tt.args.level, tt.args.text); got != tt.want {
t.Errorf("Head() = %v, want %v", got, tt.want)
}
})
}
}
func TestMilligramMinCSS(t *testing.T) {
tests := []struct {
name string
want string
}{
{"baseCssTest", MilligramMinCSS()},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := MilligramMinCSS(); got != tt.want {
t.Errorf("MilligramMinCSS() = %v, want %v", got, tt.want)
}
})
}
}
func TestFaviconIcoData(t *testing.T) {
tests := []struct {
name string
want string
}{
{"baseFaviconTest", FaviconIcoData()},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := FaviconIcoData(); got != tt.want {
t.Errorf("FaviconIcoData() = %v, want %v", got, tt.want)
}
})
}
}
func TestBassCSS(t *testing.T) {
tests := []struct {
name string
want string
}{
{"baseBassCSS", BassCSS()},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := BassCSS(); got != tt.want {
t.Errorf("BassCSS() = %v, want %v", got, tt.want)
}
})
}
}