several changes:

1. moved scan/symbol.go to new package sym and adapted all files that reference Symbol type and its values.
2. new type interval defined by begin, end and step values.
3. replaced operator-range.go with operator-interval.go.
4. replaced range operator begin:end with begin..end..step.
5. new implementation of sub-collection extraction based on new interval literal.
This commit is contained in:
2026-07-27 16:01:52 +02:00
parent 07aecfc4e7
commit 8e596d5979
63 changed files with 1125 additions and 755 deletions
+29 -9
View File
@@ -8,23 +8,43 @@ import (
"testing"
"git.portale-stac.it/go-pkg/expr/types/array"
"git.portale-stac.it/go-pkg/expr/types/list"
)
func TestCollections(t *testing.T) {
section := "Index"
inputs := []inputType{
/* 1 */ {`"abcdef"[1:3]`, "bc", nil},
/* 2 */ {`"abcdef"[:3]`, "abc", nil},
/* 3 */ {`"abcdef"[1:]`, "bcdef", nil},
/* 4 */ {`"abcdef"[:]`, "abcdef", nil},
/* 5 */ {`"abcdef"[1:2:3]`, nil, `[1:14] invalid range specification`},
/* 6 */ {`"abcdef"[((1>0)?{1}:{0}):3]`, "bc", nil},
/* 7 */ {`"abcdef"[[0,1][0]:1]`, "a", nil},
/* 8 */ {`[0,1,2,3,4][:]`, array.NewArrayA(int64(0), int64(1), int64(2), int64(3), int64(4)), nil},
/* 1 */ {`"abcdef"[1..3]`, "bc", nil},
/* 2 */ {`"abcdef"[..3]`, "abc", nil},
/* 3 */ {`"abcdef"[1..]`, "bcdef", nil},
/* 4 */ {`"abcdef"[..]`, "abcdef", nil},
/* 5 */ {`"abcdef"[1..2..3]`, `b`, nil},
/* 6 */ {`"abcdef"[((1>0)?{1}:{0})..3]`, "bc", nil},
/* 7 */ {`"abcdef"[[0,1][0]..1]`, "a", nil},
/* 8 */ {`"abcdef"[..1]`, "a", nil},
/* 9 */ {`"abcdef"[..-1]`, "abcde", nil},
/* 10 */ {`"abcdef"[..-1..2]`, "ace", nil},
/* 11 */ {`"abcdef"[-3..-1..2]`, "d", nil},
/* 12 */ {`"abcdef"[3..0]`, "dcba", nil},
/* 13 */ {`"abcdef"[-1..0..2]`, "fdb", nil},
/* 14 */ {`[0,1,2,3,4][..]`, array.NewIntArrayA(0, 1, 2, 3, 4), nil},
/* 15 */ {`[0,1,2,3,4][2..3]`, array.NewIntArrayA(2), nil},
/* 16 */ {`[0,1,2,3,4][3..-1]`, array.NewIntArrayA(3), nil},
/* 17 */ {`[0,1,2,3,4][-3..-1]`, array.NewIntArrayA(2, 3), nil},
/* 18 */ {`[0,1,2,3,4][0..]`, array.NewIntArrayA(0, 1, 2, 3, 4), nil},
/* 19 */ {`[0,1,2,3,4][0..-1..2]`, array.NewIntArrayA(0, 2), nil},
/* 20 */ {`[0,1,2,3,4][-1..0..2]`, array.NewIntArrayA(4, 2), nil},
/* 21 */ {`[<0,1,2,3,4>][..]`, list.NewLinkedListA(0, 1, 2, 3, 4), nil},
/* 22 */ {`[<0,1,2,3,4>][2..3]`, list.NewLinkedListA(2), nil},
/* 23 */ {`[<0,1,2,3,4>][3..-1]`, list.NewLinkedListA(3), nil},
/* 24 */ {`[<0,1,2,3,4>][-3..-1]`, list.NewLinkedListA(2, 3), nil},
/* 25 */ {`[<0,1,2,3,4>][0..]`, list.NewLinkedListA(0, 1, 2, 3, 4), nil},
/* 26 */ {`[<0,1,2,3,4>][0..-1..2]`, list.NewLinkedListA(0, 2), nil},
/* 27 */ {`[<0,1,2,3,4>][-1..0..2]`, list.NewLinkedListA(4, 2), nil},
}
t.Setenv("EXPR_PATH", ".")
// runTestSuiteSpec(t, section, inputs, 5)
// RunTestSuiteSpec(t, section, inputs, 27)
RunTestSuite(t, section, inputs)
}