Skip to content

Commit 433d068

Browse files
committed
FIX: take/all on a series with a tail over the index must return an empty series instead of none
1 parent b06a757 commit 433d068

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

src/core/t-block.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,8 @@ static struct {
761761

762762
case A_TAKE:
763763
if (D_REF(ARG_TAKE_ALL)) {
764-
len = tail > index ? tail - index : 0;
764+
if (tail <= index) goto zero_blk;
765+
len = tail - index;
765766
SET_TRUE(D_ARG(ARG_TAKE_PART));
766767
}
767768
else if (D_REF(ARG_TAKE_PART)) {

src/core/t-string.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,8 @@ static struct {
714714

715715
case A_TAKE:
716716
if (D_REF(ARG_TAKE_ALL)) {
717-
len = tail > index ? tail - index : 0;
717+
if (tail <= index) goto zero_str;
718+
len = tail - index;
718719
SET_TRUE(D_ARG(ARG_TAKE_PART));
719720
}
720721
else if (D_REF(ARG_TAKE_PART)) {

src/tests/units/series-test.r3

+6
Original file line numberDiff line numberDiff line change
@@ -987,18 +987,24 @@ Rebol [
987987
--assert all [#{010203040506} == take/all s empty? s]
988988
s: skip #{010203040506} 3
989989
--assert all [#{040506} == take/all s #{010203} == head s]
990+
s: next #{0102} clear head s ;; tail over index
991+
--assert all [#{} == take/all s #{} == head s]
990992

991993
--test-- "take/all block!"
992994
s: [1 2 3 4 5 6]
993995
--assert all [[1 2 3 4 5 6] == take/all s empty? s]
994996
s: skip [1 2 3 4 5 6] 3
995997
--assert all [[4 5 6] == take/all s [1 2 3] == head s]
998+
s: next [1 2] clear head s ;; tail over index
999+
--assert all [[] == take/all s [] == head s]
9961000

9971001
--test-- "take/all string!"
9981002
s: "123456"
9991003
--assert all ["123456" == take/all s empty? s]
10001004
s: skip "123456" 3
10011005
--assert all ["456" == take/all s "123" == head s]
1006+
s: next "12" clear head s ;; tail over index
1007+
--assert all ["" == take/all s "" == head s]
10021008

10031009
===end-group===
10041010

0 commit comments

Comments
 (0)