forked from volatiletech/sqlboiler
-
Notifications
You must be signed in to change notification settings - Fork 1
/
templates_test.go
68 lines (56 loc) · 1.17 KB
/
templates_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
package main
import (
"sort"
"testing"
"text/template"
)
func TestTemplateNameListSort(t *testing.T) {
t.Parallel()
templs := templateNameList{
"bob.tpl",
"all.tpl",
"struct.tpl",
"ttt.tpl",
}
expected := []string{"bob.tpl", "all.tpl", "struct.tpl", "ttt.tpl"}
for i, v := range templs {
if v != expected[i] {
t.Errorf("Order mismatch, expected: %s, got: %s", expected[i], v)
}
}
expected = []string{"struct.tpl", "all.tpl", "bob.tpl", "ttt.tpl"}
sort.Sort(templs)
for i, v := range templs {
if v != expected[i] {
t.Errorf("Order mismatch, expected: %s, got: %s", expected[i], v)
}
}
}
func TestTemplateList_Templates(t *testing.T) {
t.Parallel()
tpl := template.New("")
tpl.New("wat.tpl").Parse("hello")
tpl.New("que.tpl").Parse("there")
tpl.New("not").Parse("hello")
tplList := templateList{tpl}
foundWat, foundQue, foundNot := false, false, false
for _, n := range tplList.Templates() {
switch n {
case "wat.tpl":
foundWat = true
case "que.tpl":
foundQue = true
case "not":
foundNot = true
}
}
if !foundWat {
t.Error("want wat")
}
if !foundQue {
t.Error("want que")
}
if foundNot {
t.Error("don't want not")
}
}