-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathvariadic_test.go
More file actions
73 lines (61 loc) · 1.52 KB
/
Copy pathvariadic_test.go
File metadata and controls
73 lines (61 loc) · 1.52 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
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
package plush_test
import (
"testing"
"github.com/gobuffalo/plush/v5"
"github.com/stretchr/testify/require"
)
func Test_Variadic_Helper(t *testing.T) {
r := require.New(t)
input := `<%= foo(1, 2, 3) %>`
ctx := plush.NewContext()
ctx.Set("foo", func(args ...int) int {
return len(args)
})
s, err := plush.Render(input, ctx)
r.NoError(err)
r.Equal("3", s)
}
func Test_Variadic_Helper_Second_Arg(t *testing.T) {
r := require.New(t)
input := `<%= foo("hello") %>`
ctx := plush.NewContext()
ctx.Set("foo", func(s string, args ...interface{}) string {
return s
})
s, err := plush.Render(input, ctx)
r.NoError(err)
r.Equal("hello", s)
}
func Test_Variadic_Helper_No_Param(t *testing.T) {
r := require.New(t)
input := `<%= foo() %>`
ctx := plush.NewContext()
ctx.Set("foo", func(args ...int) int {
return len(args)
})
s, err := plush.Render(input, ctx)
r.NoError(err)
r.Equal("0", s)
}
func Test_Variadic_Helper_No_Variadic_Param(t *testing.T) {
r := require.New(t)
input := `<%= foo(1) %>`
ctx := plush.NewContext()
ctx.Set("foo", func(a int, args ...int) int {
return a + len(args)
})
s, err := plush.Render(input, ctx)
r.NoError(err)
r.Equal("1", s)
}
func Test_Variadic_Helper_With_Wrong_Param(t *testing.T) {
r := require.New(t)
input := `<%= foo(1, 2, "test") %>`
ctx := plush.NewContext()
ctx.Set("foo", func(args ...int) int {
return len(args)
})
_, err := plush.Render(input, ctx)
r.Error(err)
r.Contains(err.Error(), "test (string) is an invalid argument for foo at pos 2: expected (int)")
}