-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathhelpers_test.go
More file actions
48 lines (43 loc) · 1.06 KB
/
helpers_test.go
File metadata and controls
48 lines (43 loc) · 1.06 KB
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
package plush_test
import (
"errors"
"testing"
"github.com/gobuffalo/plush/v5"
"github.com/stretchr/testify/require"
)
func Test_Helpers_WithoutData(t *testing.T) {
type data map[string]interface{}
r := require.New(t)
table := []struct {
I string
E string
Err error
}{
{I: `<%= foo() {return bar + name} %>`, E: "BARunknown"},
{I: `<%= foo({name: "mark"}) {return bar + name} %>`, E: "BARmark"},
{I: `<%= foo({name: "mark", bbb: "hello-world"}) {return bar + name} %><%= bbb %>`, Err: errors.New(`line 1: "bbb": unknown identifier`)},
}
for _, tt := range table {
ctx := plush.NewContext()
ctx.Set("name", "unknown")
ctx.Set("bar", "BAR")
ctx.Set("foo", func(d data, help plush.HelperContext) (string, error) {
c := help.New()
if n, ok := d["name"]; ok {
c.Set("name", n)
}
if n, ok := d["bbb"]; ok {
c.Set("bbb", n)
}
return help.BlockWith(c)
})
s, err := plush.Render(tt.I, ctx)
if tt.Err == nil {
r.NoError(err)
r.Equal(tt.E, s)
} else {
r.Error(err)
r.EqualError(err, tt.Err.Error())
}
}
}