-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathview_test.go
53 lines (49 loc) · 1.05 KB
/
view_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
package golf
import (
"testing"
)
func TestStringRendering(t *testing.T) {
cases := []struct {
content string
args map[string]interface{}
output string
}{
{
"This is a sample template without args.",
map[string]interface{}{},
"This is a sample template without args.",
},
{
"Article: {{ .title }}",
map[string]interface{}{
"title": "Hello World",
},
"Article: Hello World",
},
{
"Article: {{ .title }}, Count: {{ .count }}",
map[string]interface{}{
"title": "Hello World",
"count": 5,
},
"Article: Hello World, Count: 5",
},
}
for _, c := range cases {
view := NewView()
result, err := view.RenderFromString("", c.content, c.args)
if err != nil {
t.Errorf("Can not render from string")
}
if result != c.output {
t.Errorf("Rendered content %q != %q", result, c.output)
}
}
}
func TestSetTemplateLoader(t *testing.T) {
view := NewView()
view.SetTemplateLoader("test", "/test/path/")
if view.templateLoader["test"] == nil {
t.Errorf("Could not set template loader for view")
}
}