new operator 'groupby'
This commit is contained in:
+75
-7
@@ -35,16 +35,84 @@ func TestOperator(t *testing.T) {
|
||||
/* 20 */ {`a=1; a^=2`, int64(3), nil},
|
||||
/* 21 */ {`a=1; ++a`, int64(2), nil},
|
||||
/* 22 */ {`a=1; --a`, int64(0), nil},
|
||||
/* 23 */ {`[1,2,3] map var("_")`, kern.NewList([]any{int64(1), int64(2), int64(3)}), nil},
|
||||
/* 24 */ {`[1,2,3] map $_`, kern.NewList([]any{int64(1), int64(2), int64(3)}), nil},
|
||||
/* 25 */ {`[1,2,3,4] filter ($_ % 2 == 0)`, kern.NewList([]any{int64(2), int64(4)}), nil},
|
||||
/* 26 */ {`max=0; [2,3,1] digest max=(($_ > max) ? {$_} :: {max})`, int64(3), nil},
|
||||
/* 27 */ {`["a","b"] join ["x"]`, kern.NewList([]any{"a", "b", "x"}), nil},
|
||||
/* 28 */ {`["a","b"] join ["x"-true]`, nil, `[1:21] left operand 'x' [string] and right operand 'true' [bool] are not compatible with operator "-"`},
|
||||
}
|
||||
|
||||
// t.Setenv("EXPR_PATH", ".")
|
||||
|
||||
// runTestSuiteSpec(t, section, inputs, 28)
|
||||
// runTestSuiteSpec(t, section, inputs, 22)
|
||||
runTestSuite(t, section, inputs)
|
||||
}
|
||||
|
||||
func TestOperatorMap(t *testing.T) {
|
||||
section := "Operator-Map"
|
||||
inputs := []inputType{
|
||||
/* 1 */ {`a=1; --a`, int64(0), nil},
|
||||
/* 2 */ {`[1,2,3] map var("_")`, kern.NewList([]any{int64(1), int64(2), int64(3)}), nil},
|
||||
/* 3 */ {`[1,2,3] map $_`, kern.NewList([]any{int64(1), int64(2), int64(3)}), nil},
|
||||
}
|
||||
|
||||
// runTestSuiteSpec(t, section, inputs, 3)
|
||||
runTestSuite(t, section, inputs)
|
||||
}
|
||||
|
||||
func TestOperatorFilter(t *testing.T) {
|
||||
section := "Operator-Filter"
|
||||
inputs := []inputType{
|
||||
/* 1 */ {`[1,2,3,4] filter ($_ % 2 == 0)`, kern.NewList([]any{int64(2), int64(4)}), nil},
|
||||
}
|
||||
|
||||
// runTestSuiteSpec(t, section, inputs, 1)
|
||||
runTestSuite(t, section, inputs)
|
||||
}
|
||||
|
||||
func TestOperatorDigest(t *testing.T) {
|
||||
section := "Operator-Digest"
|
||||
inputs := []inputType{
|
||||
/* 1 */ {`max=0; [2,3,1] digest max=(($_ > max) ? {$_} :: {max})`, int64(3), nil},
|
||||
}
|
||||
|
||||
// runTestSuiteSpec(t, section, inputs, 29)
|
||||
runTestSuite(t, section, inputs)
|
||||
}
|
||||
|
||||
func TestOperatorJoin(t *testing.T) {
|
||||
section := "Operator-Join"
|
||||
inputs := []inputType{
|
||||
/* 1 */ {`["a","b"] join ["x"]`, kern.NewList([]any{"a", "b", "x"}), nil},
|
||||
/* 2 */ {`["a","b"] join ["x"-true]`, nil, `[1:21] left operand 'x' [string] and right operand 'true' [bool] are not compatible with operator "-"`},
|
||||
}
|
||||
|
||||
// runTestSuiteSpec(t, section, inputs, 2)
|
||||
runTestSuite(t, section, inputs)
|
||||
}
|
||||
|
||||
func TestOperatorGroupBy(t *testing.T) {
|
||||
section := "Operator-GroupBy"
|
||||
inputs := []inputType{
|
||||
/* 1 */ {`L=[{"num": 1, "alpha": "one"}, {"num": 2, "alpha": "two"}, {"num": 3, "alpha": "three"}]; L groupby "num"`,
|
||||
kern.NewDict(map[any]any{
|
||||
"1": kern.NewListA(kern.NewDict(map[any]any{"num": int64(1), "alpha": "one"})),
|
||||
"2": kern.NewListA(kern.NewDict(map[any]any{"num": int64(2), "alpha": "two"})),
|
||||
"3": kern.NewListA(kern.NewDict(map[any]any{"num": int64(3), "alpha": "three"})),
|
||||
}),
|
||||
nil},
|
||||
/* 2 */ {`cars = [{"model": "compas", "vendor": "jeep"}, {"model": "limited", "vendor": "jeep"}, {"model": "600", "vendor":"fiat"}]; cars groupby "vendor"`,
|
||||
kern.NewDict(map[any]any{
|
||||
"jeep": kern.NewListA(
|
||||
kern.NewDict(map[any]any{"model": "compas", "vendor": "jeep"}),
|
||||
kern.NewDict(map[any]any{"model": "limited", "vendor": "jeep"})),
|
||||
"fiat": kern.NewListA(kern.NewDict(map[any]any{"model": "600", "vendor": "fiat"})),
|
||||
}),
|
||||
nil},
|
||||
/* 3 */ {`[3,4,5] groupby $__`,
|
||||
kern.NewDict(map[any]any{
|
||||
"0": kern.NewListA(int64(3)),
|
||||
"1": kern.NewListA(int64(4)),
|
||||
"2": kern.NewListA(int64(5)),
|
||||
}),
|
||||
nil},
|
||||
}
|
||||
|
||||
runTestSuiteSpec(t, section, inputs, 3)
|
||||
// runTestSuite(t, section, inputs)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user