-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunc_test.go
48 lines (43 loc) · 1.04 KB
/
func_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
package pl_test
import (
"testing"
"github.com/lesomnus/pl"
"github.com/lesomnus/pl/funcs"
"github.com/stretchr/testify/require"
)
func TestFuncMapDefaultFunctions(t *testing.T) {
executor := pl.NewExecutor()
tcs := []struct {
desc string
input *pl.Fn
expected any
}{
{
desc: "pass",
input: &pl.Fn{Name: "pass", Args: must(pl.NewArgs("a", 42, 3.14))},
expected: []any{"a", 42, 3.14},
},
{
desc: "printf",
input: &pl.Fn{Name: "printf", Args: must(pl.NewArgs("%s %d %.2f", "a", 42, 3.14))},
expected: []any{"a 42 3.14"},
},
{
desc: "regex",
input: &pl.Fn{Name: "regex", Args: must(pl.NewArgs(`foo([a-zA-Z]+)baz`, "foobarbaz"))},
expected: []any{&funcs.RegexMatch{
Source: "foobarbaz",
ByIndex: []string{"bar"},
ByName: make(map[string]string),
}},
},
}
for _, tc := range tcs {
t.Run(tc.desc, func(t *testing.T) {
require := require.New(t)
rst, err := executor.Execute(pl.NewPl(tc.input), nil)
require.NoError(err)
require.Equal(tc.expected, rst)
})
}
}