8e596d5979
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.
51 lines
2.0 KiB
Go
51 lines
2.0 KiB
Go
// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
|
|
// All rights reserved.
|
|
|
|
// t_index_test.go
|
|
package expr
|
|
|
|
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]`, `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, 27)
|
|
RunTestSuite(t, section, inputs)
|
|
}
|