pkg/eval/vals: Remove support for the legacy a:b slice syntax.

This syntax was deprecated in 0.15.0 and no longer documented since then.
This commit is contained in:
Qi Xiao 2021-10-22 17:41:09 +01:00
parent b12c29fb53
commit fc66ad1d10
4 changed files with 9 additions and 30 deletions

View File

@ -19,8 +19,8 @@ func (a customAssocer) Assoc(k, v interface{}) (interface{}, error) {
func TestAssoc(t *testing.T) {
Test(t, Fn("Assoc", Assoc), Table{
Args("0123", "0", "foo").Rets("foo123", nil),
Args("0123", "1:3", "bar").Rets("0bar3", nil),
Args("0123", "1:3", 12).Rets(nil, errReplacementMustBeString),
Args("0123", "1..3", "bar").Rets("0bar3", nil),
Args("0123", "1..3", 12).Rets(nil, errReplacementMustBeString),
Args("0123", "x", "y").Rets(nil, errIndexMustBeInteger),
Args(MakeList("0", "1", "2", "3"), "0", "foo").Rets(
@ -31,7 +31,7 @@ func TestAssoc(t *testing.T) {
Args(MakeList("0"), "1", "x").Rets(nil, errs.OutOfRange{
What: "index", ValidLow: "0", ValidHigh: "0", Actual: "1"}),
// TODO: Support list assoc with slice
Args(MakeList("0", "1", "2", "3"), "1:3", MakeList("foo")).Rets(
Args(MakeList("0", "1", "2", "3"), "1..3", MakeList("foo")).Rets(
nil, errAssocWithSlice),
Args(MakeMap("k", "v", "k2", "v2"), "k", "newv").Rets(

View File

@ -23,7 +23,7 @@ func TestHasKey(t *testing.T) {
Args(keysIterator{vs("lorem")}, "ipsum").Rets(false),
// Fallback to Len
Args(MakeList("lorem", "ipsum"), "0").Rets(true),
Args(MakeList("lorem", "ipsum"), "0:").Rets(true),
Args(MakeList("lorem", "ipsum"), "0..").Rets(true),
Args(MakeList("lorem", "ipsum"), "2").Rets(false),
// Non-container

View File

@ -137,9 +137,6 @@ func parseIndexString(s string, n int) (slice bool, i int, j int, err error) {
}
func splitIndexString(s string) (low, sep, high string) {
if i := strings.IndexRune(s, ':'); i >= 0 {
return s[:i], ":", s[i+1:]
}
if i := strings.Index(s, "..="); i >= 0 {
return s[:i], "..=", s[i+3:]
}

View File

@ -29,12 +29,6 @@ func TestIndex(t *testing.T) {
Args("abc", "..").Rets("abc", nil),
Args("abc", "..0").Rets("", nil), // i == j == 0 is allowed
Args("abc", "3..").Rets("", nil), // i == j == n is allowed
// String slices with half-open range, using deprecated syntax.
Args("abc", "1:2").Rets("b", nil),
Args("abc", "1:").Rets("bc", nil),
Args("abc", ":").Rets("abc", nil),
Args("abc", ":0").Rets("", nil), // i == j == 0 is allowed
Args("abc", "3:").Rets("", nil), // i == j == n is allowed
// String slices with closed range.
Args("abc", "0..=1").Rets("ab", nil),
Args("abc", "1..=").Rets("bc", nil),
@ -92,18 +86,6 @@ func TestIndex(t *testing.T) {
Args(li0, "..").Rets(Eq(li0), nil),
Args(li4, "..").Rets(Eq(li4), nil),
// Half-open slices using deprecated syntax.
Args(li4, "1:3").Rets(Eq(MakeList("bar", "lorem")), nil),
Args(li4, "3:4").Rets(Eq(MakeList("ipsum")), nil),
Args(li4, "0:0").Rets(Eq(EmptyList), nil), // i == j == 0 is allowed
Args(li4, "4:4").Rets(Eq(EmptyList), nil), // i == j == n is allowed
Args(li4, ":2").Rets(Eq(MakeList("foo", "bar")), nil),
Args(li4, ":-1").Rets(Eq(MakeList("foo", "bar", "lorem")), nil),
Args(li4, "3:").Rets(Eq(MakeList("ipsum")), nil),
Args(li4, "-2:").Rets(Eq(MakeList("lorem", "ipsum")), nil),
Args(li0, ":").Rets(Eq(li0), nil),
Args(li4, ":").Rets(Eq(li4), nil),
// Closed slices.
Args(li4, "1..=2").Rets(Eq(MakeList("bar", "lorem")), nil),
Args(li4, "..=1").Rets(Eq(MakeList("foo", "bar")), nil),
@ -112,16 +94,16 @@ func TestIndex(t *testing.T) {
Args(li4, "..=").Rets(Eq(li4), nil),
// Slice index out of range.
Args(li4, "-5:1").Rets(nil, errs.OutOfRange{
Args(li4, "-5..1").Rets(nil, errs.OutOfRange{
What: "negative index", ValidLow: "-4", ValidHigh: "-1", Actual: "-5"}),
Args(li4, "0:5").Rets(nil, errs.OutOfRange{
Args(li4, "0..5").Rets(nil, errs.OutOfRange{
What: "index", ValidLow: "0", ValidHigh: "4", Actual: "5"}),
Args(li4, z+":").Rets(nil,
Args(li4, z+"..").Rets(nil,
errs.OutOfRange{What: "index", ValidLow: "0", ValidHigh: "4", Actual: z}),
// Slice index upper < lower
Args(li4, "3:2").Rets(nil, errs.OutOfRange{
Args(li4, "3..2").Rets(nil, errs.OutOfRange{
What: "slice upper index", ValidLow: "3", ValidHigh: "4", Actual: "2"}),
Args(li4, "-1:-2").Rets(nil,
Args(li4, "-1..-2").Rets(nil,
errs.OutOfRange{What: "negative slice upper index",
ValidLow: "-1", ValidHigh: "-1", Actual: "-2"}),