mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-05 03:17:50 +08:00
parent
a57275564b
commit
7bae8f2df7
|
@ -129,7 +129,11 @@ func parseIndexString(s string, n int) (slice bool, i int, j int, err error) {
|
|||
}
|
||||
if sep == "..=" {
|
||||
// TODO: Handle j == MaxInt-1
|
||||
j++
|
||||
if j == -1 { // subtle corner case that is same as no high value
|
||||
j = n
|
||||
} else {
|
||||
j++
|
||||
}
|
||||
}
|
||||
}
|
||||
// Two numbers
|
||||
|
|
|
@ -34,6 +34,7 @@ func TestIndex(t *testing.T) {
|
|||
Args("abc", "1..=").Rets("bc", nil),
|
||||
Args("abc", "..=1").Rets("ab", nil),
|
||||
Args("abc", "..=").Rets("abc", nil),
|
||||
Args("abc", "..=-1").Rets("abc", nil),
|
||||
// String slices not at rune boundary.
|
||||
Args("你好", "2..").Rets(Any, errIndexNotAtRuneBoundary),
|
||||
Args("你好", "..2").Rets(Any, errIndexNotAtRuneBoundary),
|
||||
|
@ -92,6 +93,7 @@ func TestIndex(t *testing.T) {
|
|||
Args(li4, "..=-2").Rets(eq(MakeList("foo", "bar", "lorem")), nil),
|
||||
Args(li4, "3..=").Rets(eq(MakeList("ipsum")), nil),
|
||||
Args(li4, "..=").Rets(eq(li4), nil),
|
||||
Args(li4, "..=-1").Rets(eq(li4), nil),
|
||||
|
||||
// Slice index out of range.
|
||||
Args(li4, "-5..1").Rets(nil, errs.OutOfRange{
|
||||
|
|
Loading…
Reference in New Issue
Block a user