refactored data-types to reduce plugin sizes

This commit is contained in:
2026-06-08 07:02:56 +02:00
parent fec7cc546c
commit b6da9bcad4
90 changed files with 1039 additions and 803 deletions
+15 -12
View File
@@ -9,6 +9,9 @@ import (
"git.portale-stac.it/go-pkg/expr/kern"
"git.portale-stac.it/go-pkg/expr/scan"
"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 TestIteratorParser(t *testing.T) {
@@ -35,7 +38,7 @@ func TestIteratorParser(t *testing.T) {
/* 19 */ {`it=$({1:"one",2:"two",3:"three"}); it++`, int64(1), nil},
/* 20 */ {`it=$({1:"one",2:"two",3:"three"}, "default", "value"); it++`, "one", nil},
/* 21 */ {`it=$({1:"one",2:"two",3:"three"}, "desc", "key"); it++`, int64(3), nil},
/* 22 */ {`it=$({1:"one",2:"two",3:"three"}, "asc", "item"); it++`, kern.NewList([]any{int64(1), "one"}), nil},
/* 22 */ {`it=$({1:"one",2:"two",3:"three"}, "asc", "item"); it++`, array.NewList([]any{int64(1), "one"}), nil},
/* 23 */ {`$$($(1,4,0))`, nil, `step cannot be zero`},
/* 24 */ {`$$($(1,4,-1))`, nil, `step cannot be negative when start < stop`},
/* 25 */ {`$$($(4,1,1))`, nil, `step cannot be positive when start > stop`},
@@ -75,7 +78,7 @@ func TestCallOpIterIter(t *testing.T) {
func TestCallOpDictIter(t *testing.T) {
section := "DictIterator-CallOp"
inner := kern.NewDict(map[any]any{"a": 1})
inner := dict.NewDict(map[any]any{"a": 1})
if it, err := NewDictIterator(inner, nil); err != nil {
t.Errorf(`%s -- NewIterIter() failed: %v`, section, err)
} else {
@@ -87,7 +90,7 @@ func TestCallOpDictIter(t *testing.T) {
func TestCallOpLinkedListIter(t *testing.T) {
section := "LinkedListIterator-CallOp"
inner := kern.NewLinkedListA(1, 2, 3)
inner := list.NewLinkedListA(1, 2, 3)
it := NewLinkedListIterator(inner, nil)
testIteratorCallOp(t, section, it)
@@ -122,8 +125,8 @@ func testIterAttrs(t *testing.T, section string, it kern.Iterator, name, repr st
func TestFilterIterator(t *testing.T) {
section := "Iterator-Filter"
inputs := []inputType{
/* 1 */ {`$$([1,2,3] filter $_%2==0)`, kern.NewLinkedListA(2), nil},
/* 2 */ {`it = [1,2,3] filter $_%2!=1; $$(it)`, kern.NewLinkedListA(2), nil},
/* 1 */ {`$$([1,2,3] filter $_%2==0)`, list.NewLinkedListA(2), nil},
/* 2 */ {`it = [1,2,3] filter $_%2!=1; $$(it)`, list.NewLinkedListA(2), nil},
/* 3 */ {`builtin "os.file"; #$$(fileLineIterator("test-file.txt") filter (#${_} == 2))`, int64(0), nil},
/* 4 */ {`builtin "os.file"; #$$(fileLineIterator("test-file.txt") filter (#${_} == 3))`, int64(2), nil},
}
@@ -147,11 +150,11 @@ func TestDigestIterator(t *testing.T) {
func TestCatIterator(t *testing.T) {
section := "Iterator-Cat"
inputs := []inputType{
/* 1 */ {`$$([1] cat [])`, kern.NewLinkedListA(1), nil},
/* 2 */ {`$$([1] cat [2])`, kern.NewLinkedListA(1, 2), nil},
/* 3 */ {`$$([1] cat nil)`, kern.NewLinkedListA(1), nil},
/* 4 */ {`$$(nil cat [2])`, kern.NewLinkedListA(2), nil},
/* 5 */ {`$$(nil cat nil)`, kern.NewLinkedListA(), nil},
/* 1 */ {`$$([1] cat [])`, list.NewLinkedListA(1), nil},
/* 2 */ {`$$([1] cat [2])`, list.NewLinkedListA(1, 2), nil},
/* 3 */ {`$$([1] cat nil)`, list.NewLinkedListA(1), nil},
/* 4 */ {`$$(nil cat [2])`, list.NewLinkedListA(2), nil},
/* 5 */ {`$$(nil cat nil)`, list.NewLinkedListA(), nil},
/* 6 */ {`$$(["a","b"] cat ["x"-true])`, nil, `[1:23] left operand 'x' [string] and right operand 'true' [bool] are not compatible with operator "-"`},
}
@@ -162,10 +165,10 @@ func TestCatIterator(t *testing.T) {
func TestMapIterator(t *testing.T) {
section := "Iterator-Map"
inputs := []inputType{
/* 1 */ {`$$([3,4,5] map ${_#})`, kern.NewLinkedListA(1, 2, 3), nil},
/* 1 */ {`$$([3,4,5] map ${_#})`, list.NewLinkedListA(1, 2, 3), nil},
/* 2 */ {`#$$($(10) map ${_})`, int64(10), nil},
/* 3 */ {`#$$($(10,0) map ${_})`, int64(10), nil},
/* 4 */ {`builtin "os.file"; $$(fileLineIterator("test-file.txt") map ${__})`, kern.NewLinkedListA(0, 1), nil},
/* 4 */ {`builtin "os.file"; $$(fileLineIterator("test-file.txt") map ${__})`, list.NewLinkedListA(0, 1), nil},
/* 5 */ {`$$(["1", "2", "3"] map int())`, nil, `int(): too few params -- expected 1, got 0`},
}