tpl: After now accepts 0 as index
authorBaibhav Vatsa <baibhavvatsa@gmail.com>
Fri, 11 Oct 2019 01:16:15 +0000 (20:16 -0500)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 11 Oct 2019 06:35:27 +0000 (08:35 +0200)
Modified the if conditional because of which after threw an error if called with 0 as index. The function now returns the whole original slice if 0 is passed as an index. Also added tests to test the new behavior.

Fixes #6388

tpl/collections/collections.go
tpl/collections/collections_test.go

index 195199876403203473514ee53d2659749ced3b98..eb6ecb9bbbae2d59203a9d2fb224a1ab9a0739c5 100644 (file)
@@ -60,7 +60,7 @@ func (ns *Namespace) After(index interface{}, seq interface{}) (interface{}, err
                return nil, err
        }
 
-       if indexv < 1 {
+       if indexv < 0 {
                return nil, errors.New("can't return negative/empty count of items from sequence")
        }
 
index 8ea973f0bc1f53ac75d4cd7370e51354cea8530e..781f44e0a29444103ae535fe317bdfd72cd1dbda 100644 (file)
@@ -50,6 +50,8 @@ func TestAfter(t *testing.T) {
                {int64(2), []int{100, 200, 300}, []int{300}},
                {100, []int{100, 200}, []int{}},
                {"1", []int{100, 200, 300}, []int{200, 300}},
+               {0, []int{100, 200, 300, 400, 500}, []int{100, 200, 300, 400, 500}},
+               {0, []string{"a", "b", "c", "d", "e"}, []string{"a", "b", "c", "d", "e"}},
                {int64(-1), []int{100, 200, 300}, false},
                {"noint", []int{100, 200, 300}, false},
                {2, []string{}, []string{}},