forked from gobuffalo/plush
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhashes_test.go
61 lines (54 loc) · 1.27 KB
/
hashes_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
package plush
import (
"testing"
"github.com/stretchr/testify/require"
)
func Test_Render_Hash_Array_Index(t *testing.T) {
r := require.New(t)
input := `<%= m["first"] + " " + m["last"] %>|<%= a[0+1] %>`
s, err := Render(input, NewContextWith(map[string]interface{}{
"m": map[string]string{"first": "Mark", "last": "Bates"},
"a": []string{"john", "paul"},
}))
r.NoError(err)
r.Equal("Mark Bates|paul", s)
}
func Test_Render_HashCall(t *testing.T) {
r := require.New(t)
input := `<%= m["a"] %>`
ctx := NewContext()
ctx.Set("m", map[string]string{
"a": "A",
})
s, err := Render(input, ctx)
r.NoError(err)
r.Equal("A", s)
}
func Test_Render_HashCall_OnAttribute(t *testing.T) {
r := require.New(t)
input := `<%= m.MyMap[key] %>`
ctx := NewContext()
ctx.Set("m", struct {
MyMap map[string]string
}{
MyMap: map[string]string{"a": "A"},
})
ctx.Set("key", "a")
s, err := Render(input, ctx)
r.NoError(err)
r.Equal("A", s)
}
func Test_Render_HashCall_OnAttribute_IntoFunction(t *testing.T) {
r := require.New(t)
input := `<%= debug(m.MyMap[key]) %>`
ctx := NewContext()
ctx.Set("m", struct {
MyMap map[string]string
}{
MyMap: map[string]string{"a": "A"},
})
ctx.Set("key", "a")
s, err := Render(input, ctx)
r.NoError(err)
r.Equal("<pre>A</pre>", s)
}