-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtpl_test.go
More file actions
64 lines (48 loc) · 1.39 KB
/
tpl_test.go
File metadata and controls
64 lines (48 loc) · 1.39 KB
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
package tpl
import (
"bytes"
"strings"
"testing"
)
func TestExecute(t *testing.T) {
tmpl := New()
_, err := tmpl.ParseDir("testdata", ".html")
ok(t, err)
cases := map[string]string{
"top.html": "This is content of top.html",
"middle.html": "This is content of middle.html and content of partial.html",
"bottom.html": "This is content of bottom.html and content of partial.html",
"standalone/standalone.html": "This is content of standalone.html and content of partial.html",
"partials/empty.html": "",
}
for k := range cases {
t.Run(k, func(t *testing.T) {
var b bytes.Buffer
err = tmpl.Execute(&b, k, "")
ok(t, err)
equals(t, cases[k], strings.TrimSpace(b.String()))
})
}
}
func TestExecuteError(t *testing.T) {
tmpl := New()
_, err := tmpl.ParseDir("testdata", ".html")
ok(t, err)
var b bytes.Buffer
err = tmpl.Execute(&b, "notfound", "")
equals(t, "template notfound is not found", err.Error())
}
func TestLookup(t *testing.T) {
tmpl := New()
_, err := tmpl.ParseDir("testdata", ".html")
ok(t, err)
template := tmpl.Lookup("standalone/standalone.html")
assert(t, template != nil, "template is nil")
}
func TestLookupNotFound(t *testing.T) {
tmpl := New()
_, err := tmpl.ParseDir("testdata", ".html")
ok(t, err)
template := tmpl.Lookup("notfound")
assert(t, template == nil, "template is not nil")
}