Skip to content
Newer
Older
100644 91 lines (69 sloc) 3.12 KB
58135b3 [t/spec] changed 'use v6-alpha;' to 'use v6;'
moritz authored May 8, 2008
1 use v6;
fb71d06 Test suite refactoring (spec/S29).
cosimo authored Jan 12, 2008
2 use Test;
3
b7f4853 point several smartlinks to the S32::Str specs
szabgab authored Apr 26, 2009
4 # L<S32::Str/Str/"=item rindex">
fb71d06 Test suite refactoring (spec/S29).
cosimo authored Jan 12, 2008
5
3e980b2 @usev6 Tests for index/rindex with negative start position
usev6 authored Nov 22, 2015
6 plan 45;
d2e3055 @lizmat Minimal test changes for rindex(--> Index)
lizmat authored Jul 30, 2015
7
8 # Type of return value
a93ea8e @lizmat Remove tests for Index
lizmat authored Aug 6, 2015
9 isa-ok('abc'.rindex('b'), Int);
d2e3055 @lizmat Minimal test changes for rindex(--> Index)
lizmat authored Jul 29, 2015
10 isa-ok('abc'.rindex('d'), Nil);
fb71d06 Test suite refactoring (spec/S29).
cosimo authored Jan 12, 2008
11
12 # Simple - with just a single char
13
14 is(rindex("Hello World", "H"), 0, "One char, at beginning");
15 is(rindex("Hello World", "l"), 9, "One char, in the middle");
16 is(rindex("Hello World", "d"), 10, "One char, in the end");
5c3e4c6 [spec] Str.rindex: Replace comparition to -1 with checking defined() …
bacek authored Aug 24, 2008
17 ok(!defined(rindex("Hello World", "x")), "One char, no match");
fb71d06 Test suite refactoring (spec/S29).
cosimo authored Jan 12, 2008
18
19 is(rindex("Hello World", "l", 10), 9, "One char, first match, pos @ end");
20 is(rindex("Hello World", "l", 9), 9, "- 1. match again, pos @ match");
21 is(rindex("Hello World", "l", 8), 3, "- 2. match");
22 is(rindex("Hello World", "l", 2), 2, "- 3. match");
5c3e4c6 [spec] Str.rindex: Replace comparition to -1 with checking defined() …
bacek authored Aug 24, 2008
23 ok(!defined(rindex("Hello World", "l", 1)), "- no more matches");
fb71d06 Test suite refactoring (spec/S29).
cosimo authored Jan 12, 2008
24
25 # Simple - with a string
26
27 is(rindex("Hello World", "Hello"), 0, "Substr, at beginning");
28 is(rindex("Hello World", "o W"), 4, "Substr, in the middle");
29 is(rindex("Hello World", "World"), 6, "Substr, at the end");
5c3e4c6 [spec] Str.rindex: Replace comparition to -1 with checking defined() …
bacek authored Aug 24, 2008
30 ok(!defined(rindex("Hello World", "low")), "Substr, no match");
fb71d06 Test suite refactoring (spec/S29).
cosimo authored Jan 12, 2008
31 is(rindex("Hello World", "Hello World"), 0, "Substr eq Str");
32
33 # Empty strings
34
35 is(rindex("Hello World", ""), 11, "Substr is empty");
36 is(rindex("", ""), 0, "Both strings are empty");
5c3e4c6 [spec] Str.rindex: Replace comparition to -1 with checking defined() …
bacek authored Aug 24, 2008
37 ok(!defined(rindex("", "Hello")), "Only main-string is empty");
fb71d06 Test suite refactoring (spec/S29).
cosimo authored Jan 12, 2008
38 is(rindex("Hello", "", 3), 3, "Substr is empty, pos within str");
39 is(rindex("Hello", "", 5), 5, "Substr is empty, pos at end of str");
bcbe584 @TimToady fix off-the-end index/rindex tests
TimToady authored Mar 9, 2015
40 nok(rindex("Hello", "", 999).defined, "rindex where pos > length of str return undefined");
fb71d06 Test suite refactoring (spec/S29).
cosimo authored Jan 12, 2008
41
42 # More difficult strings
43
a80ff41 [t/spec] some random unfudges and fixes
moritz authored Aug 29, 2008
44 is(rindex("abcdabcab", "abcd"), 0, "Start-of-substr matches several times");
fb71d06 Test suite refactoring (spec/S29).
cosimo authored Jan 12, 2008
45 is(rindex("uuúuúuùù", "úuù"), 4, "Accented chars");
46 is(rindex("Ümlaut", "Ü"), 0, "Umlaut");
47 is(rindex("what are these « » unicode characters for ?", "uni"), 19, "over unicode characters");
48
49 # .rindex use
50 is("Hello World".rindex("l"), 9, ".rindex on string");
d2e3055 @lizmat Minimal test changes for rindex(--> Index)
lizmat authored Jul 29, 2015
51 is("Hello World".rindex(''), 11, ".rindex('') on string gives string length graphemes");
fb71d06 Test suite refactoring (spec/S29).
cosimo authored Jan 12, 2008
52
53 # on scalar variable
54 my $s = "Hello World";
55 is(rindex($s, "o"), 7, "rindex on scalar variable");
56 is($s.rindex("o"), 7, ".rindex on scalar variable");
57
58 is(rindex(uc($s), "O"), 7, "rindex on uc");
59 is($s.uc.rindex("O"), 7, ".uc.rindex ");
60
61 # ideas for deeper chained . calls ?
f7e8545 @coke s/ucfirst/tc/ - ucfirst is going away
coke authored Jul 25, 2012
62 is($s.lc.tc.rindex("w"), 6, ".lc.tc.rindex");
fb71d06 Test suite refactoring (spec/S29).
cosimo authored Jan 12, 2008
63
04abb4f [t/spec] tests for rindex on non-strings (Int, in this case)
moritz authored Sep 7, 2008
64 # rindex on non-strings
65 ok 3459.rindex(5) == 2, 'rindex on integers';
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored Aug 8, 2009
66
f7639b1 @moritz RT #112818, rindex with non-Latin-1 strings
moritz authored May 10, 2012
67 # RT #112818
68 is "\x261b perl \x261a".rindex('e'), 3, 'rindex with non-latin-1 strings';
69
3e980b2 @usev6 Tests for index/rindex with negative start position
usev6 authored Nov 22, 2015
70 # rindex with negative start position not allowed
71 ok rindex("xxyxx", "y", -1) ~~ Failure, 'rindex with negative start position fails (1)';
72 throws-like 'rindex("xxyxx", "y", -1)', X::OutOfRange, 'rindex with negative start position fails (2)';
e29df31 @lizmat Add tests for #125784
lizmat authored Aug 11, 2015
73
74 # RT #125784
75 {
3e980b2 @usev6 Tests for index/rindex with negative start position
usev6 authored Nov 22, 2015
76 for -1e34, -1e35 -> $pos {
77 ok rindex( 'xxyxx','y', $pos ) ~~ Failure, "sub does $pos fails";
78 ok 'xxyxx'.rindex( 'y', $pos ) ~~ Failure, "method does $pos fails";
79 }
80 for 1e34, 1e35 -> $pos {
db02e90 @lizmat Fix index/rindex tests
lizmat authored Nov 29, 2015
81 throws-like rindex( 'xxyxx','y', $pos ), X::OutOfRange,
82 got => $pos,
83 "sub does $pos fails";
84 throws-like 'xxyxx'.rindex( 'y', $pos ), X::OutOfRange,
85 got => $pos,
86 "method does $pos fails";
e29df31 @lizmat Add tests for #125784
lizmat authored Aug 11, 2015
87 }
88 }
89
7f29bc5 [t/spec] Add vim: lines everywhere.
kyle authored Aug 8, 2009
90 # vim: ft=perl6
Something went wrong with that request. Please try again.