-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhtml_test.go
97 lines (74 loc) · 2.53 KB
/
html_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
89
90
91
92
93
94
95
96
97
package html
import (
. "github.com/101loops/bdd"
)
var _ = Describe("HTML", func() {
var loader *Loader
BeforeEach(func() {
loader = fixtureLoader(false)
})
It("render: add template", func() {
view, err := loader.NewSet().Add("layout", "pages/home").View()
Check(err, IsNil)
Check(view, NotNil)
out, err := view.HTML()
Check(err, IsNil)
Check(trim(out), Equals, `<html> <body> <h1>Home</h1> </body> </html>`)
})
It("render: add & set template", func() {
view, err := loader.NewSet().Add("layout").Set("content", "pages/content").View()
Check(err, IsNil)
Check(view, NotNil)
out, err := view.HTML()
Check(err, IsNil)
Check(trim(out), Equals, `<html> <body> <h1>Content</h1> </body> </html>`)
})
It("render: add set", func() {
baseSet := loader.NewSet().Add("layout")
view, err := loader.NewSet().AddSet(baseSet).Add("pages/home").View()
out, err := view.HTML()
Check(err, IsNil)
Check(trim(out), Equals, `<html> <body> <h1>Home</h1> </body> </html>`)
})
It("reload template source", func() {
loader = fixtureLoader(true)
view := loader.NewSet().Add("dynamic").ViewMust()
out, err := view.HTML()
Check(err, IsNil)
Check(trim(out), IsEmpty)
setDynamicTemplate("dynamic")
out, err = view.HTML()
Check(err, IsNil)
Check(trim(out), Equals, "dynamic")
setDynamicTemplate("{{ invalid }}")
out, err = view.HTML()
Check(err, NotNil).And(Contains, `function "invalid" not defined`)
})
It("error for missing template", func() {
_, err := loader.NewSet().Add("not-existing").View()
Check(err, NotNil).And(Contains, `template "not-existing" not found`)
})
It("error for invalid syntax", func() {
_, err := loader.NewSet().Add("invalid_syntax").View()
Check(err, NotNil).And(Contains, `unexpected unterminated quoted string in command`)
})
It("error for missing function", func() {
_, err := loader.NewSet().Add("invalid_func").View()
Check(err, NotNil).And(Contains, `function "invalid" not defined`)
})
It("error for root template redefinition", func() {
_, err := loader.NewSet().Add("layout", "layout").View()
Check(err, NotNil).And(Contains, `redefinition of root template`)
})
It("error for incomplete template", func() {
_, err := loader.NewSet().Add("pages/home").View()
Check(err, NotNil).And(Contains, "missing root template")
_, err = loader.NewSet().Add("layout").View()
Check(err, NotNil).And(Contains, `missing template(s) ["content"]`)
})
It("panic for error", func() {
Check(func() {
loader.NewSet().Add("not-existing").ViewMust()
}, Panics)
})
})