-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathtemplate_test.go
55 lines (50 loc) · 1.26 KB
/
template_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
package golf
import (
"bytes"
"testing"
)
type TemplateData struct {
Title string
Path string
User interface{}
Nav map[string]string
Data map[string]interface{}
}
func TestTemplateRendering(t *testing.T) {
st := &TemplateManager{
Loader: &MapLoader{
"test.html": `<title>{{.Title}}</title> Key={{.Data}}`,
"test2.html": "Lorem ipsum dolor sit amet.",
"test3.html": `{{.Foo}}`,
"extends.html": `header {{ template "content" }} footer`,
},
}
cases := []struct {
content string
args map[string]interface{}
output string
}{
{
"Lorem ipsum dolor sit amet.",
map[string]interface{}{},
"Lorem ipsum dolor sit amet.",
},
{
`Lorem ipsum {{ include "test2.html" }} sit amet.`,
map[string]interface{}{},
"Lorem ipsum Lorem ipsum dolor sit amet. sit amet.",
},
{
`{{ extends "extends.html" }} {{ define "content" }}Lorem ipsum Lorem ipsum dolor sit amet. sit amet.{{ end }}`,
map[string]interface{}{},
`header Lorem ipsum Lorem ipsum dolor sit amet. sit amet. footer`,
},
}
for _, c := range cases {
var buf bytes.Buffer
st.RenderFromString(&buf, c.content, c.args)
if buf.String() != c.output {
t.Errorf("String template rendering with loader failed: %q != %q", buf.String(), c.output)
}
}
}