Skip to content

Commit 8742805

Browse files
committed
Add more index* tests to test empty string paths
1 parent 83197a2 commit 8742805

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

t/moar/08-indexic.t

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
#!/usr/bin/env nqp
2-
plan(119 * 2);
2+
plan(119 * 2 + 4 * 3);
3+
ok(nqp::indexic('hi', '', 2) == 2, 'nqp::indexic finds empty string after last index');
4+
ok(nqp::indexic('hi', '', 0) == 0, 'nqp::indexic finds empty string at start');
5+
ok(nqp::indexic('hi', '', 1) == 1, 'nqp::indexic finds empty string in the middle');
6+
ok(nqp::indexic('hi', '', 3) == -1, 'nqp::indexic does not find empty string at graphs + 1');
7+
ok(nqp::indexicim('hi', '', 2) == 2, 'nqp::indexicim finds empty string after last index');
8+
ok(nqp::indexicim('hi', '', 0) == 0, 'nqp::indexicim finds empty string at start');
9+
ok(nqp::indexicim('hi', '', 1) == 1, 'nqp::indexicim finds empty string in the middle');
10+
ok(nqp::indexicim('hi', '', 3) == -1, 'nqp::indexicim does not find empty string at graphs + 1');
11+
ok(nqp::indexim('hi', '', 2) == 2, 'nqp::indexim finds empty string after last index');
12+
ok(nqp::indexim('hi', '', 0) == 0, 'nqp::indexim finds empty string at start');
13+
ok(nqp::indexim('hi', '', 1) == 1, 'nqp::indexim finds empty string in the middle');
14+
ok(nqp::indexim('hi', '', 3) == -1, 'nqp::indexim does not find empty string at graphs + 1');
315
my @array :=
416
# (haystack, needle, result)
517
# line below is a todo example: commented out in case someone else needs to todo one of these tests

t/nqp/059-nqpop.t

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Test nqp::op pseudo-functions.
44

5-
plan(318);
5+
plan(326);
66

77
ok( nqp::add_i(5,2) == 7, 'nqp::add_i');
88
ok( nqp::sub_i(5,2) == 3, 'nqp::sub_i');
@@ -64,6 +64,16 @@ ok( nqp::rindex('Hello World', '', 1) == 1, 'nqp::rindex with empty match at off
6464
ok( nqp::rindex('Hello World', '', 11) == 11, 'nqp::rindex with empty match at end returns length');
6565
ok( nqp::rindex('Hello World', '', 100) == -1, 'nqp::rindex with empty match at offset outside string returns -1');
6666

67+
# Empty string tests
68+
ok(nqp::rindex('hi', '', 2) == 2, 'nqp::rindex finds empty string after last index');
69+
ok(nqp::rindex('hi', '', 0) == 0, 'nqp::rindex finds empty string at start');
70+
ok(nqp::rindex('hi', '', 1) == 1, 'nqp::rindex finds empty string in the middle');
71+
ok(nqp::rindex('hi', '', 3) == -1, 'nqp::rindex does not find empty string at graphs + 1');
72+
ok(nqp::index('hi', '', 2) == 2, 'nqp::index finds empty string after last index');
73+
ok(nqp::index('hi', '', 0) == 0, 'nqp::index finds empty string at start');
74+
ok(nqp::index('hi', '', 1) == 1, 'nqp::index finds empty string in the middle');
75+
ok(nqp::index('hi', '', 3) == -1, 'nqp::dindex does not find empty string at graphs + 1');
76+
6777
is( nqp::chr(120), 'x', 'nqp::chr');
6878
is( nqp::ord('xyz'),120, 'nqp::ord');
6979
is( nqp::ord('xyz',2),122, '2 argument nqp::ord');
@@ -311,7 +321,7 @@ ok(!nqp::isgt_s('abc', 'abc'), 'nqp::isge - both string equal');
311321
ok(!nqp::isgt_s('abcdaz', 'abcdbzefg'), 'nqp::isge left string greater');
312322

313323
ok((1.1 != 1) == 1, '!= between floating point numbers (not equal)');
314-
ok((1.1 != 1.1) == 0,'!= between floating point numbers (equal)');
324+
ok((1.1 != 1.1) == 0,'!= between floating point numbers (equal)');
315325

316326
ok(12.5 % 5 == 2.5, '% test');
317327
ok(3 % 2.5 == 0.5, '% test');

0 commit comments

Comments
 (0)