From 88a9d147741c677c75cd159bc65dcb84ff1a1d5b Mon Sep 17 00:00:00 2001 From: Oldes Date: Tue, 23 Oct 2018 22:40:05 +0200 Subject: [PATCH] FIX: FIND/PART not working after skipping the series fixes issue: https://github.com/rebol/rebol-issues/issues/2324 --- src/core/t-block.c | 2 +- src/core/t-string.c | 2 +- src/tests/run-tests.r3 | 1 + src/tests/units/series-test.r3 | 47 ++++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 src/tests/units/series-test.r3 diff --git a/src/core/t-block.c b/src/core/t-block.c index 28fbf33cef..55a4b574ca 100644 --- a/src/core/t-block.c +++ b/src/core/t-block.c @@ -713,7 +713,7 @@ static struct { args = Find_Refines(ds, ALL_FIND_REFS); // if (ANY_BLOCK(arg) || args) { len = ANY_BLOCK(arg) ? VAL_BLK_LEN(arg) : 1; - if (args & AM_FIND_PART) tail = Partial1(value, D_ARG(ARG_FIND_LENGTH)); + if (args & AM_FIND_PART) tail = index + Partial1(value, D_ARG(ARG_FIND_LENGTH)); ret = 1; if (args & AM_FIND_SKIP) ret = Int32s(D_ARG(ARG_FIND_SIZE), 1); ret = Find_Block(ser, index, tail, arg, len, args, ret); diff --git a/src/core/t-string.c b/src/core/t-string.c index 09c10e7bee..b63c7a4e71 100644 --- a/src/core/t-string.c +++ b/src/core/t-string.c @@ -517,7 +517,7 @@ static REBSER *make_binary(REBVAL *arg, REBOOL make) if (ANY_BINSTR(arg)) len = VAL_LEN(arg); - if (args & AM_FIND_PART) tail = Partial(value, 0, D_ARG(ARG_FIND_LENGTH), 0); + if (args & AM_FIND_PART) tail = index + Partial(value, 0, D_ARG(ARG_FIND_LENGTH), 0); ret = 1; // skip size if (args & AM_FIND_SKIP) ret = Partial(value, 0, D_ARG(ARG_FIND_SIZE), 0); diff --git a/src/tests/run-tests.r3 b/src/tests/run-tests.r3 index 0f580a8705..2f0312bdfc 100644 --- a/src/tests/run-tests.r3 +++ b/src/tests/run-tests.r3 @@ -25,6 +25,7 @@ wrap load %units/protect-test.r3 wrap load %units/crash-test.r3 wrap load %units/bincode-test.r3 wrap load %units/codecs-test.r3 +wrap load %units/series-test.r3 recycle/torture recycle diff --git a/src/tests/units/series-test.r3 b/src/tests/units/series-test.r3 new file mode 100644 index 0000000000..e0a193a483 --- /dev/null +++ b/src/tests/units/series-test.r3 @@ -0,0 +1,47 @@ +Rebol [ + Title: "Rebol series test script" + Author: "Oldes" + File: %series-test.r3 + Tabs: 4 + Needs: [%../quick-test-module.r3] +] + +~~~start-file~~~ "Series" + +===start-group=== "FIND & SELECT" + +--test-- "SELECT or FIND NONE! anything == none - #473" + --assert none? find none 1 + --assert none? select none 1 + +--test-- "FIND" + --assert none? find/part [x] 'x 0 + --assert equal? [x] find/part [x] 'x 1 + --assert equal? [x] find/reverse tail [x] 'x + --assert equal? [y] find/match [x y] 'x + --assert equal? [x] find/last [x] 'x + --assert equal? [x] find/last [x x x] 'x + +--test-- https://github.com/rebol/rebol-issues/issues/66 + --assert none? find/skip [1 2 3 4 5 6] 2 3 + +--test-- https://github.com/rebol/rebol-issues/issues/88 + --assert "c" = find "abc" charset ["c"] + --assert none? find/part "ab" "b" 1 + +--test-- https://github.com/rebol/rebol-issues/issues/2324 + str: "1.1.1" + --assert "1.1.1" == find/part str "1." 2 + str: skip str 2 + --assert "1.1" == find str "1." + --assert "1.1" == find/part str "1." 2 + +--test-- "SELECT" + --assert 2 = select/part [1 2 1 3 1 2] 1 2 + --assert none? select/part [1 2 1 3 1 2] 2 2 + --assert 3 = select/part (skip [1 2 1 3 1 2] 2) 1 2 + + +===end-group=== + +~~~end-file~~~ \ No newline at end of file