-
Notifications
You must be signed in to change notification settings - Fork 1
/
funcs_test.go
85 lines (63 loc) · 2.18 KB
/
funcs_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
package html
import (
. "github.com/101loops/bdd"
"github.com/101loops/strutil"
)
var _ = Describe("Template Funcs", func() {
var loader *Loader
var reverseFn = func(text string) string { return strutil.Reverse(text) }
BeforeEach(func() {
loader = fixtureLoader(false)
})
It("function raw", func() {
out, err := loader.NewSet().Add("funcs/raw").ViewMust().HTML()
Check(err, IsNil)
Check(out, Equals, "<br>")
})
It("function nl2br", func() {
out, err := loader.NewSet().Add("funcs/nl2br").ViewMust().HTML()
Check(err, IsNil)
Check(out, Equals, "<br>")
})
It("function runSet", func() {
set := loader.NewSet().Add("pages/nonsense")
_, err := loader.NewSet().Add("funcs/run_set").ViewMust().HTML(set)
Check(err, NotNil).And(Contains, `error calling runSet: template "pages/nonsense" not found`)
})
It("function runView", func() {
view := loader.NewSet().Add("pages/content").ViewMust()
out, err := loader.NewSet().Add("funcs/run_view").ViewMust().HTML(view)
Check(err, IsNil)
Check(out, Equals, "<h1>Content</h1>")
})
It("function runView: error", func() {
view := loader.NewSet()
_, err := loader.NewSet().Add("funcs/run_view").ViewMust().HTML(view)
Check(err, NotNil).And(Contains, `wrong type for value; expected *html.View; got *html.Set`)
})
It("function runTemplate", func() {
tmpl := "pages/content"
out, err := loader.NewSet().Add("funcs/run_template").ViewMust().HTML(tmpl)
Check(err, IsNil)
Check(out, Equals, "<h1>Content</h1>")
})
It("function runTemplate: error", func() {
tmpl := "pages/nonsense"
_, err := loader.NewSet().Add("funcs/run_template").ViewMust().HTML(tmpl)
Check(err, NotNil).And(Contains, `error calling runTemplate: template "pages/nonsense" not found`)
})
It("add single func", func() {
out, err := loader.NewSet().Add("funcs/dynamic1").AddFunc("customFunc", reverseFn).ViewMust().HTML()
Check(err, IsNil)
Check(out, Equals, "cba")
})
It("add multiple funcs", func() {
out, err := loader.NewSet().
Add("funcs/dynamic2").
AddFuncs(map[string]interface{}{"customFunc1": reverseFn, "customFunc2": reverseFn}).
ViewMust().
HTML()
Check(err, IsNil)
Check(trim(out), Equals, "abc")
})
})