Files
expr/t_index_test.go
T

55 lines
2.4 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},
/* 28 */ {`[-1..0..2]`, nil, `[1:8] unexpected interval expression`},
/* 29 */ {`"abcdef"['x'..]`, nil, `[1:14] interval expression expected integer, got string (x)`},
/* 30 */ {`"abcdef"[1+..]`, nil, `[1:12] infix operator "+" requires two non-nil operands, got 1`},
/* 31 */ {`"abcdef"[1..4+]`, nil, `[1:15] infix operator "+" requires two non-nil operands, got 1`},
}
t.Setenv("EXPR_PATH", ".")
// RunTestSuiteSpec(t, section, inputs, 30)
RunTestSuite(t, section, inputs)
}