-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview_test.go
88 lines (69 loc) · 1.94 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright (c) Jeevanandam M. (https://github.com/jeevatkm)
// go-aah/view source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.
package view
import (
"html/template"
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"
"testing"
"aahframework.org/config.v0"
"aahframework.org/log.v0"
"aahframework.org/test.v0/assert"
"aahframework.org/vfs.v0"
)
func TestViewAddTemplateFunc(t *testing.T) {
AddTemplateFunc(template.FuncMap{
"join": strings.Join,
"safeHTML": strings.Join, // for duplicate test, don't mind
})
_, found := TemplateFuncMap["join"]
assert.True(t, found)
}
func TestViewStore(t *testing.T) {
err := AddEngine("go", &GoViewEngine{})
assert.NotNil(t, err)
assert.Equal(t, "view: engine name 'go' is already added, skip it", err.Error())
err = AddEngine("custom", nil)
assert.NotNil(t, err)
assert.Equal(t, "view: engine value is nil", err.Error())
engine, found := GetEngine("go")
assert.NotNil(t, engine)
assert.True(t, found)
engine, found = GetEngine("myengine")
assert.Nil(t, engine)
assert.False(t, found)
}
func TestViewTemplates(t *testing.T) {
tmpls := &Templates{}
err := tmpls.Add("views/layouts/master.html", &template.Template{})
assert.Nil(t, err)
err = tmpls.Add("views/pages/app/index.html", &template.Template{})
assert.Nil(t, err)
keys := tmpls.Keys()
assert.True(t, len(keys) == 2)
err = tmpls.Add("views/pages/app/index.html", &template.Template{})
assert.NotNil(t, err)
assert.Equal(t, "view: template key exists", err.Error())
assert.False(t, tmpls.IsExists("not-exixts"))
}
func testdataBaseDir() string {
wd, _ := os.Getwd()
return filepath.Join(wd, "testdata")
}
func newVFS() *vfs.VFS {
fs := new(vfs.VFS)
fs.AddMount("/testdata", testdataBaseDir())
return fs
}
func join(s ...string) string {
return "/" + path.Join(s...)
}
func newLog() log.Loggerer {
l, _ := log.New(config.NewEmpty())
l.SetWriter(ioutil.Discard)
return l
}