-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathview_test.go
68 lines (64 loc) · 1.06 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package goview
import (
"bytes"
"html/template"
"testing"
)
var cases = []struct {
Name string
Data M
Out string
}{
{
Name: "echo.tpl",
Data: M{"name": "GoView"},
Out: "$GoView",
},
{
Name: "include",
Data: M{"name": "GoView"},
Out: "<v>IncGoView</v>",
},
{
Name: "index",
Data: M{},
Out: "<v>Index</v>",
},
{
Name: "sum",
Data: M{
"sum": func(a int, b int) int {
return a + b
},
"a": 1,
"b": 2,
},
Out: "<v>3</v>",
},
}
func TestViewEngine_RenderWriter(t *testing.T) {
gv := New(Config{
Root: "_examples/test",
Extension: ".tpl",
Master: "layouts/master",
Partials: []string{},
Funcs: template.FuncMap{
"echo": func(v string) string {
return "$" + v
},
},
DisableCache: true,
})
for _, v := range cases {
buff := new(bytes.Buffer)
err := gv.RenderWriter(buff, v.Name, v.Data)
if err != nil {
t.Errorf("name: %v, data: %v, error: %v", v.Name, v.Data, err)
continue
}
val := string(buff.Bytes())
if val != v.Out {
t.Errorf("actual: %v, expect: %v", val, v.Out)
}
}
}