refactored data-types to reduce plugin sizes
This commit is contained in:
+39
-37
@@ -7,7 +7,9 @@ package expr
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.portale-stac.it/go-pkg/expr/kern"
|
||||
"git.portale-stac.it/go-pkg/expr/types/array"
|
||||
"git.portale-stac.it/go-pkg/expr/types/dict"
|
||||
"git.portale-stac.it/go-pkg/expr/types/list"
|
||||
)
|
||||
|
||||
func TestOperator(t *testing.T) {
|
||||
@@ -52,26 +54,26 @@ func TestOperator(t *testing.T) {
|
||||
func TestOperatorInsert(t *testing.T) {
|
||||
section := "Operator-Insert"
|
||||
inputs := []inputType{
|
||||
/* 1 */ {`["a", "b"] << nil`, kern.NewListA("a", "b"), nil},
|
||||
/* 2 */ {`["a", "b"] << []`, kern.NewListA("a", "b", kern.NewListA()), nil},
|
||||
/* 3 */ {`["a", "b"] << $([])`, kern.NewListA("a", "b"), nil},
|
||||
/* 4 */ {`["a", "b"] << 3`, kern.NewListA("a", "b", int64(3)), nil},
|
||||
/* 5 */ {`3 << ["a", "b"]`, nil, `[1:5] left operand '3' [integer] and right operand '["a", "b"]' [list] are not compatible with operator "<<"`},
|
||||
/* 6 */ {`nil >> ["a", "b"]`, kern.NewListA("a", "b"), nil},
|
||||
/* 7 */ {`[] >> ["a", "b"]`, kern.NewListA(kern.NewListA(), "a", "b"), nil},
|
||||
/* 8 */ {`$([]) >> ["a", "b"]`, kern.NewListA("a", "b"), nil},
|
||||
/* 9 */ {`["a", "b"] << $([1,2,3])`, kern.NewListA("a", "b", int64(1), int64(2), int64(3)), nil},
|
||||
/* 10 */ {`L=["a", "b"]; L << $([1,2,3])`, kern.NewListA("a", "b", int64(1), int64(2), int64(3)), nil},
|
||||
/* 11 */ {`L=["a", "b"]; L << $([1,2,3]); L`, kern.NewListA("a", "b"), nil},
|
||||
/* 1 */ {`["a", "b"] << nil`, array.NewListA("a", "b"), nil},
|
||||
/* 2 */ {`["a", "b"] << []`, array.NewListA("a", "b", array.NewListA()), nil},
|
||||
/* 3 */ {`["a", "b"] << $([])`, array.NewListA("a", "b"), nil},
|
||||
/* 4 */ {`["a", "b"] << 3`, array.NewListA("a", "b", int64(3)), nil},
|
||||
/* 5 */ {`3 << ["a", "b"]`, nil, `[1:5] left operand '3' [integer] and right operand '["a", "b"]' [array] are not compatible with operator "<<"`},
|
||||
/* 6 */ {`nil >> ["a", "b"]`, array.NewListA("a", "b"), nil},
|
||||
/* 7 */ {`[] >> ["a", "b"]`, array.NewListA(array.NewListA(), "a", "b"), nil},
|
||||
/* 8 */ {`$([]) >> ["a", "b"]`, array.NewListA("a", "b"), nil},
|
||||
/* 9 */ {`["a", "b"] << $([1,2,3])`, array.NewListA("a", "b", int64(1), int64(2), int64(3)), nil},
|
||||
/* 10 */ {`L=["a", "b"]; L << $([1,2,3])`, array.NewListA("a", "b", int64(1), int64(2), int64(3)), nil},
|
||||
/* 11 */ {`L=["a", "b"]; L << $([1,2,3]); L`, array.NewListA("a", "b"), nil},
|
||||
/* 12 */ {`L << $([1,2,3])`, nil, `undefined variable or function "L"`},
|
||||
/* 13 */ {`[<>] << 1`, kern.NewLinkedListA(1), nil},
|
||||
/* 14 */ {`[<>] << [1,2]`, kern.NewLinkedListA(kern.NewListA(int64(1), int64(2))), nil},
|
||||
/* 15 */ {`[<>] << [<1,2>]`, kern.NewLinkedListA(kern.NewLinkedListA(1, 2)), nil},
|
||||
/* 16 */ {`1 >> [<>]`, kern.NewLinkedListA(1), nil},
|
||||
/* 17 */ {`[1,2] >> [<>]`, kern.NewLinkedListA(kern.NewListA(int64(1), int64(2))), nil},
|
||||
/* 18 */ {`[<1,2>] >> [<>]`, kern.NewLinkedListA(kern.NewLinkedListA(1, 2)), nil},
|
||||
/* 19 */ {`$([1,2]) >> [<>]`, kern.NewLinkedListA(1, 2), nil},
|
||||
/* 20 */ {`$([<1,2>]) >> [<>]`, kern.NewLinkedListA(1, 2), nil},
|
||||
/* 13 */ {`[<>] << 1`, list.NewLinkedListA(1), nil},
|
||||
/* 14 */ {`[<>] << [1,2]`, list.NewLinkedListA(array.NewListA(int64(1), int64(2))), nil},
|
||||
/* 15 */ {`[<>] << [<1,2>]`, list.NewLinkedListA(list.NewLinkedListA(1, 2)), nil},
|
||||
/* 16 */ {`1 >> [<>]`, list.NewLinkedListA(1), nil},
|
||||
/* 17 */ {`[1,2] >> [<>]`, list.NewLinkedListA(array.NewListA(int64(1), int64(2))), nil},
|
||||
/* 18 */ {`[<1,2>] >> [<>]`, list.NewLinkedListA(list.NewLinkedListA(1, 2)), nil},
|
||||
/* 19 */ {`$([1,2]) >> [<>]`, list.NewLinkedListA(1, 2), nil},
|
||||
/* 20 */ {`$([<1,2>]) >> [<>]`, list.NewLinkedListA(1, 2), nil},
|
||||
}
|
||||
|
||||
// runTestSuiteSpec(t, section, inputs, 9)
|
||||
@@ -81,10 +83,10 @@ func TestOperatorInsert(t *testing.T) {
|
||||
func TestOperatorDeepAssign(t *testing.T) {
|
||||
section := "Operator-DeepAssign"
|
||||
inputs := []inputType{
|
||||
/* 1 */ {`DD={"uno": 1, "due": 2}; D=DD; D["uno"]=11; DD`, kern.NewDict(map[any]any{"uno": int64(11), "due": int64(2)}), nil},
|
||||
/* 2 */ {`DD={"uno": 1, "due": 2}; D:=DD; D["uno"]=11; DD`, kern.NewDict(map[any]any{"uno": int64(1), "due": int64(2)}), nil},
|
||||
/* 3 */ {`LL=["a", "b"]; L=LL; L[0]="x"; LL`, kern.NewListA("x", "b"), nil},
|
||||
/* 4 */ {`LL=["a", "b"]; L:=LL; L[0]="x"; LL`, kern.NewListA("a", "b"), nil},
|
||||
/* 1 */ {`DD={"uno": 1, "due": 2}; D=DD; D["uno"]=11; DD`, dict.NewDict(map[any]any{"uno": int64(11), "due": int64(2)}), nil},
|
||||
/* 2 */ {`DD={"uno": 1, "due": 2}; D:=DD; D["uno"]=11; DD`, dict.NewDict(map[any]any{"uno": int64(1), "due": int64(2)}), nil},
|
||||
/* 3 */ {`LL=["a", "b"]; L=LL; L[0]="x"; LL`, array.NewListA("x", "b"), nil},
|
||||
/* 4 */ {`LL=["a", "b"]; L:=LL; L[0]="x"; LL`, array.NewListA("a", "b"), nil},
|
||||
}
|
||||
|
||||
// runTestSuiteSpec(t, section, inputs, 4)
|
||||
@@ -105,25 +107,25 @@ 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"})),
|
||||
dict.NewDict(map[any]any{
|
||||
"1": array.NewListA(dict.NewDict(map[any]any{"num": int64(1), "alpha": "one"})),
|
||||
"2": array.NewListA(dict.NewDict(map[any]any{"num": int64(2), "alpha": "two"})),
|
||||
"3": array.NewListA(dict.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"})),
|
||||
dict.NewDict(map[any]any{
|
||||
"jeep": array.NewListA(
|
||||
dict.NewDict(map[any]any{"model": "compas", "vendor": "jeep"}),
|
||||
dict.NewDict(map[any]any{"model": "limited", "vendor": "jeep"})),
|
||||
"fiat": array.NewListA(dict.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)),
|
||||
dict.NewDict(map[any]any{
|
||||
"0": array.NewListA(int64(3)),
|
||||
"1": array.NewListA(int64(4)),
|
||||
"2": array.NewListA(int64(5)),
|
||||
}),
|
||||
nil},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user