-
Notifications
You must be signed in to change notification settings - Fork 0
/
pongo2_test.go
58 lines (49 loc) · 1.15 KB
/
pongo2_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
package pongo2
import (
"github.com/stretchr/testify/require"
"testing"
"fmt"
)
func Test_Render_Simple_HTML(t *testing.T) {
r := require.New(t)
input := `<p>Hi</p>`
s, err := BuffaloRenderer(input, nil, nil)
r.NoError(err)
r.Equal(input, s)
}
func Test_Render_Variable(t *testing.T) {
r := require.New(t)
input := `{{ greet }} {{ name }}!`
ctxData := map[string]interface{}{
"greet": "Hello",
"name": "Stan",
}
s, err := BuffaloRenderer(input, ctxData, nil)
r.NoError(err)
r.Equal("Hello Stan!", s)
}
func Test_Render_Condition(t *testing.T) {
r := require.New(t)
input := `{% if is_allowed %}I'm allowed!{% endif %}`
ctxData := map[string]interface{}{
"is_allowed": true,
}
s, err := BuffaloRenderer(input, ctxData, nil)
r.NoError(err)
r.Equal("I'm allowed!", s)
}
func Test_Render_Helper(t *testing.T) {
r := require.New(t)
input := `{{ hello_helper(user) }}`
ctxData := map[string]interface{}{
"user": "Mark",
}
helpers := map[string]interface{}{
"hello_helper": func (s string) string {
return fmt.Sprintf("Hello %s!", s)
},
}
s, err := BuffaloRenderer(input, ctxData, helpers)
r.NoError(err)
r.Equal("Hello Mark!", s)
}