Skip to content

Commit 323f23b

Browse files
committed
Move tests to builtin_test.go
1 parent 1829e72 commit 323f23b

File tree

2 files changed

+13
-32
lines changed

2 files changed

+13
-32
lines changed

builtin/builtin_test.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ import (
1818
)
1919

2020
func TestBuiltin(t *testing.T) {
21+
env := map[string]any{
22+
"ArrayOfString": []string{"foo", "bar", "baz"},
23+
"ArrayOfInt": []int{1, 2, 3},
24+
"ArrayOfAny": []any{1, "2", true},
25+
"ArrayOfFoo": []mock.Foo{{Value: "a"}, {Value: "b"}, {Value: "c"}},
26+
}
27+
2128
var tests = []struct {
2229
input string
2330
want any
@@ -87,13 +94,14 @@ func TestBuiltin(t *testing.T) {
8794
{`get({foo: 1, bar: 2}, "unknown")`, nil},
8895
{`"foo" in keys({foo: 1, bar: 2})`, true},
8996
{`1 in values({foo: 1, bar: 2})`, true},
97+
{`groupBy(1..9, # % 2)`, map[any][]any{0: {2, 4, 6, 8}, 1: {1, 3, 5, 7, 9}}},
98+
{`groupBy(1..9, # % 2)[0]`, []any{2, 4, 6, 8}},
99+
{`groupBy(1..3, # > 1)[true]`, []any{2, 3}},
100+
{`groupBy(1..3, # > 1 ? nil : "")[nil]`, []any{2, 3}},
101+
{`groupBy(ArrayOfFoo, .Value).a`, []any{mock.Foo{Value: "a"}}},
102+
{`countBy(1..9, # % 2)`, map[any]int{0: 4, 1: 5}},
90103
}
91104

92-
env := map[string]any{
93-
"ArrayOfString": []string{"foo", "bar", "baz"},
94-
"ArrayOfInt": []int{1, 2, 3},
95-
"ArrayOfAny": []any{1, "2", true},
96-
}
97105
for _, test := range tests {
98106
t.Run(test.input, func(t *testing.T) {
99107
program, err := expr.Compile(test.input, expr.Env(env))

expr_test.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,33 +1040,6 @@ func TestExpr(t *testing.T) {
10401040
`4/2 == 2`,
10411041
true,
10421042
},
1043-
{
1044-
`groupBy(1..9, # % 2)`,
1045-
map[any][]any{
1046-
0: {2, 4, 6, 8},
1047-
1: {1, 3, 5, 7, 9},
1048-
},
1049-
},
1050-
{
1051-
`groupBy(1..9, # % 2)[0]`,
1052-
[]any{2, 4, 6, 8},
1053-
},
1054-
{
1055-
`groupBy(1..3, # > 1)[true]`,
1056-
[]any{2, 3},
1057-
},
1058-
{
1059-
`groupBy(1..3, # > 1 ? nil : "")[nil]`,
1060-
[]any{2, 3},
1061-
},
1062-
{
1063-
`groupBy(ArrayOfFoo, .Value).foo`,
1064-
[]any{env.ArrayOfFoo[0]},
1065-
},
1066-
{
1067-
`countBy(1..9, # % 2)`,
1068-
map[any]int{0: 4, 1: 5},
1069-
},
10701043
}
10711044

10721045
for _, tt := range tests {

0 commit comments

Comments
 (0)