Skip to content

Commit

Permalink
FIX: find/same not working when used a block as a key
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Apr 17, 2024
1 parent 00a6c8f commit cfe4ffc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/core/t-block.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ static void No_Nones_Or_Logic(REBVAL *arg) {
cnt = 0;
value = BLK_SKIP(series, index);
for (val = VAL_BLK_DATA(target); NOT_END(val); val++, value++) {
if (0 != Cmp_Value(value, val, (REBOOL)(flags & AM_FIND_CASE))) break;
if ((flags & AM_FIND_SAME)) {
if (0 == Compare_Values(value, val, 3))
break;
}
else if (0 != Cmp_Value(value, val, (REBOOL)(flags & AM_FIND_CASE))) break;
if (++cnt >= len) {
return index;
}
Expand Down
17 changes: 17 additions & 0 deletions src/tests/units/series-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,23 @@ Rebol [
--assert 2 = index? find/same [1.0 1] 1
--assert 1 = index? find/same [1.0 1] 1.0

--test-- "FIND block! block!"
;@@ https://github.com/Oldes/Rebol-issues/issues/2473
blk: [1.0 3 1 3 1.0 2.0 1 2]
--assert 5 = index? find blk [1 2]
--assert 1 = index? find blk [1 3]
--assert 5 = index? find blk [1.0 2]
--assert 7 = index? find/same blk [1 2]
--assert 3 = index? find/same blk [1 3]
--assert none? find/same blk [1.0 2]
a: "a" b: "b" blk: reduce ["a" "b" a b]
--assert 1 = index? find blk reduce [a b]
--assert 1 = index? find blk reduce ["a" "b"]
--assert 3 = index? find/same blk reduce [a b]
--assert none? find/same blk reduce [a "b"]
--assert none? find/same blk reduce ["a" "b"]


--test-- "FIND/SAME in string!"
--assert "AbcdAe" = find/same "aAbcdAe" "A"
--assert "Ae" = find/same/last "aAbcdAe" "A"
Expand Down

0 comments on commit cfe4ffc

Please sign in to comment.