Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 185 lines (158 sloc) 5.198 kb
fd56de2 [t/spec]: S05 - Moved some capturing tests and added a few
unobe authored
1 use v6;
5b8dbb5 @lizmat "use MONKEY_TYPING" -> "use MONKEY-TYPING"
lizmat authored
2 use MONKEY-TYPING;
db4bde7 [t/spec] add 'use MONKEY_TYPING' where appropriate
lwall authored
3
fd56de2 [t/spec]: S05 - Moved some capturing tests and added a few
unobe authored
4 use Test;
bcf79d0 @lizmat Replace cargo-culted BEGIN {@*INC...} by use lib
lizmat authored
5 use lib 't/spec/packages';
b54c647 [t/spec] Tests for RT #70007
kyle authored
6 use Test::Util;
ae245a6 @usev6 Add test for RT #83508
usev6 authored
7 plan 46;
fd56de2 [t/spec]: S05 - Moved some capturing tests and added a few
unobe authored
8
f33600b smartlink updates
szabgab authored
9 # old: L<S05/Return values from matches/"A match always returns a Match object" >
10 # L<S05/Match objects/"A match always returns a " >
fd56de2 [t/spec]: S05 - Moved some capturing tests and added a few
unobe authored
11 {
12 my $match = 'abd' ~~ m/ (a) (b) c || (\w) b d /;
69dfa1d @colomon Fix / fudge for Niecza.
colomon authored
13 isa_ok $match, Match, 'Match object returned';
14 isa_ok $/, Match, 'Match object assigned to $/';
fd56de2 [t/spec]: S05 - Moved some capturing tests and added a few
unobe authored
15 ok( $/ === $match, 'Same match objects');
16 }
17
27ead91 @pmichaud Result of a failed regex match is now Nil; add test for it and
pmichaud authored
18 {
19 my $match = 'xyz' ~~ / abc /;
69dfa1d @colomon Fix / fudge for Niecza.
colomon authored
20 #?niecza skip 'No value for parameter $obj in isa_ok'
27ead91 @pmichaud Result of a failed regex match is now Nil; add test for it and
pmichaud authored
21 isa_ok( $/, Nil, 'Failed match returns Nil' );
22 }
23
f33600b smartlink updates
szabgab authored
24 # old: L<S05/Return values from matches/"The array elements of a C<Match> object are referred to" >
25 # L<S05/Accessing captured subpatterns/"The array elements of a " >
fd56de2 [t/spec]: S05 - Moved some capturing tests and added a few
unobe authored
26 {
27 'abd' ~~ m/ (a) (b) c || (\w) b d /;
28 ok( $/[0] eq 'a', 'positional capture accessible');
29 ok( @($/).[0] eq 'a', 'array context - correct number of positional captures');
30 ok( @($/).elems == 1, 'array context - correct number of positional captures');
3d2c0c9 added tests for $/.list and $/.hash
krunen authored
31 ok( $/.list.elems == 1, 'the .list methods returns a list object');
fd56de2 [t/spec]: S05 - Moved some capturing tests and added a few
unobe authored
32 }
33
f33600b smartlink updates
szabgab authored
34 # old: L<S05/Return values from matches/"When used as a hash, a C<Match> object" >
35 # L<S05/Match objects/"When used as a hash" >
fd56de2 [t/spec]: S05 - Moved some capturing tests and added a few
unobe authored
36 {
37 'abd' ~~ m/ <alpha> <alpha> c || <alpha> b d /;
38 ok( $/<alpha> eq 'a', 'named capture accessible');
39 ok( %($/).keys == 1, 'hash context - correct number of named captures');
40 ok( %($/).<alpha> eq 'a', 'hash context - named capture accessible');
3d2c0c9 added tests for $/.list and $/.hash
krunen authored
41 ok( $/.hash.keys[0] eq 'alpha', 'the .hash method returns a hash object');
fd56de2 [t/spec]: S05 - Moved some capturing tests and added a few
unobe authored
42 }
65a1623 add test for accessing match keys through scalary copy RT 62530
ron authored
43
25668e6 @coke Prefer RT #XXXXXX
coke authored
44 # RT #62530
06bb994 @coke fudge for niecza
coke authored
45 #?niecza skip 'rule declaration outside of grammar'
65a1623 add test for accessing match keys through scalary copy RT 62530
ron authored
46 {
95ea915 [t/spec] remove rest of "is also" on classes
moritz authored
47 augment class Match { method keys () {return %(self).keys }; };
89f0409 @TimToady warning suppression, mostly "not used"
TimToady authored
48 my rule a {H};
49 "Hello" ~~ /<a=&a>/;
65a1623 add test for accessing match keys through scalary copy RT 62530
ron authored
50 is $/.keys, 'a', 'get rule result';
51 my $x = $/;
52 is $x.keys, 'a', 'match copy should be same as match';
53 }
95ea915 [t/spec] remove rest of "is also" on classes
moritz authored
54
404d496 [t/spec] Test for RT #64946
kyle authored
55 # RT #64946
56 {
f824933 [t/spec] fudge capturing-contexts.t for Rakudo
moritz authored
57 my regex o { o };
58 "foo" ~~ /f<o=&o>+/;
404d496 [t/spec] Test for RT #64946
kyle authored
59
60 is ~$<o>, 'o o', 'match list stringifies like a normal list';
6fba902 @moritz add a test for RT #65308; fudge capturing-contexts.t for rakudo
moritz authored
61 ok $<o> ~~ Positional, '... and it is Positional';
404d496 [t/spec] Test for RT #64946
kyle authored
62 # I don't know what difference 'isa' makes, but it does.
63 # Note that calling .WHAT (as in the original ticket) does not have
64 # the same effect.
65 is ~$<o>, 'o o', 'match list stringifies like a normal list AFTER "isa"';
66 }
67
c96e63b [t/spec] Tests for RT #64952
kyle authored
68 # RT #64952
69 {
70 'ab' ~~ /(.)+/;
71 is $/[0][0], 'a', 'match element [0][0] from /(.)+/';
72 is $/[0][1], 'b', 'match element [0][1] from /(.)+/';
73
74 my @match = @( 'ab' ~~ /(.)+/ );
75 is @match[0][0], 'a', 'match element [0][0] from /(.)+/ coerced';
76 is @match[0][1], 'b', 'match element [0][1] from /(.)+/ coerced';
77 }
78
34fb50f [t/spec] feeble test for RT #64948
kyle authored
79 # RT #64948
80 {
e778706 @lizmat Part 2 of 2 of eradication of .exists from spectests
lizmat authored
81 ok %( 'foo' ~~ /<alpha> oo/ )<alpha>:exists,
34fb50f [t/spec] feeble test for RT #64948
kyle authored
82 'Match coerced to Hash says match exists';
83 }
84
afbef95 @usev6 Remove duplicate test for RT #70007
usev6 authored
85 # RT #70007
86 {
87 # undefined captures should fail to match
88 # note the use of $1 (and not $0)
89 # This is similar to a test in S05-interpolation/regex-in-variable.t
90 #?niecza todo 'undefined capture does not match'
91 nok 'aa' ~~ /(.)$1/, 'undefined capture does not match';
92
93 # This looks superfluous as there is a test for warning when interpolating
94 # undefined into a regex in S05-interpolation/regex-in-variable.t
95 #?rakudo todo 'RT #70007'
96 #?niecza todo 'eek'
97 is_run( q{'aa' ~~ /(.)$1/},
b54c647 [t/spec] Tests for RT #70007
kyle authored
98 {
99 status => 0,
100 out => '',
874939b [t/spec/TODO] See r28888 for tests for r28881 and note similar tests
kyle authored
101 err => rx/undef/,
b54c647 [t/spec] Tests for RT #70007
kyle authored
102 },
afbef95 @usev6 Remove duplicate test for RT #70007
usev6 authored
103 'match with undefined capture emits a warning' );
104 }
b54c647 [t/spec] Tests for RT #70007
kyle authored
105
0865309 [t/spec] Test for RT 66252: match in void context does not set $/
kyle authored
106 # RT #66252
107 {
25668e6 @coke Prefer RT #XXXXXX
coke authored
108 $_ = 'RT #66252';
5ac6379 @moritz correct and unfudge tests for RT #66252
moritz authored
109 m/(R.)/;
06bb994 @coke fudge for niecza
coke authored
110 #?niecza todo 'Match object in $/ after match in void context'
0865309 [t/spec] Test for RT 66252: match in void context does not set $/
kyle authored
111 isa_ok $/, 'Match', 'Match object in $/ after match in void context';
112 is $/, 'RT', 'Matched as intended in void context';
113 }
114
533512a [t/spec] Test for RT 70003: $/.orig produces CodeString
kyle authored
115 # RT #70003
116 {
01db9ce @moritz correct and unfudge tests for RT #70003
moritz authored
117 'abc' ~~ /a/;
118 is ($/.orig).rindex('a'), 0, 'rindex() works on $/.orig';
119 is ($/.orig).rindex('a', 2), 0, 'rindex() works on $/.orig';
533512a [t/spec] Test for RT 70003: $/.orig produces CodeString
kyle authored
120 }
121
5fe25b6 @usev6 Modify and unfudge tests for binding $/, add test for RT #114726
usev6 authored
122 # RT #114726
123 {
124 lives_ok { my $/ := 42 }, 'can bind $/';
125 }
126
046b183 [t/spec] tests for RT #71362, $0, $1 etc. work even for $/ := $something
moritz authored
127 # RT #71362
128 {
5fe25b6 @usev6 Modify and unfudge tests for binding $/, add test for RT #114726
usev6 authored
129 my $/ := 'foobar';
046b183 [t/spec] tests for RT #71362, $0, $1 etc. work even for $/ := $something
moritz authored
130 is $0, 'foobar', '$0 works like $/[0], even for non-Match objects';
131 nok $1.defined, '$1 is not defined';
132 }
133
f1ff19a [t/spec] tests for # RT #72956 $0 when $/ is undefined causes Rakudo to ...
bbkr authored
134 # RT #72956
135 {
5fe25b6 @usev6 Modify and unfudge tests for binding $/, add test for RT #114726
usev6 authored
136 my $/ := Any;
f1ff19a [t/spec] tests for # RT #72956 $0 when $/ is undefined causes Rakudo to ...
bbkr authored
137 lives_ok { $0 },
138 '$0 accessible when $/ is undefined';
b5caf94 [t/spec] tests for RT #RT #77160, flattening of quantified captures in M...
moritz authored
139 ok $0 === Any,
f1ff19a [t/spec] tests for # RT #72956 $0 when $/ is undefined causes Rakudo to ...
bbkr authored
140 '$0 is Any when $/ is undefined';
816c95f [t/spec] be even more explicit with undefinedness check
moritz authored
141 nok $0.defined, '$0 is undefined';
f1ff19a [t/spec] tests for # RT #72956 $0 when $/ is undefined causes Rakudo to ...
bbkr authored
142 }
143
b5caf94 [t/spec] tests for RT #RT #77160, flattening of quantified captures in M...
moritz authored
144 # RT #77160
145 {
146 ok 'abc' ~~ /(.)+/, 'regex sanity';
147 my $x = 0;
148 $x++ for $/.list;
149 is $x, 1, '$/.list does not flatten quantified subcaptures';
150
151 ok 'abc' ~~ /(.)**2 (.)/, 'regex sanity';
152 $x = 0;
153 $x++ for $/.list;
154 is $x, 2, '$/.list does not flattens subcaptures';
155 }
156
25668e6 @coke Prefer RT #XXXXXX
coke authored
157 # RT #74180
606e737 @bbkr alphabetic characters can follow digits in $0 variable in interpolation
bbkr authored
158 {
159 my $s;
04daf2d @FROGGS eval => EVAL in S05, S06 and S09
FROGGS authored
160 try { $s = EVAL '"foo" ~~ /(foo)/; "$0a"' };
606e737 @bbkr alphabetic characters can follow digits in $0 variable in interpolation
bbkr authored
161 ok not $!, 'alphabetic characters can follow digits in $0 variable in interpolation';
162 is $s, 'fooa', 'alphabetic characters follows $0 interpolated value';
163 }
164
ec62150 @labster RT #117461 Test for Match.lines (which really means Match ~~ Cool)
labster authored
165 # L<S32::Rules/Match>
166
25668e6 @coke Prefer RT #XXXXXX
coke authored
167 # RT #117461
ec62150 @labster RT #117461 Test for Match.lines (which really means Match ~~ Cool)
labster authored
168 {
169 ok "a \n \b \n c \n d" ~~ /a .* c/, "match multiple lines with '.'";
170 ok $/.can('lines'), "Match has a .lines method";
171 is +$/.lines, 3, "Correct number of lines";
172 isa_ok $/, Cool, "Match is Cool";
173 }
174
ae245a6 @usev6 Add test for RT #83508
usev6 authored
175 # RT #83508
176 {
177 'x' ~~ /(y)? (z)*/;
178 is $0.defined, False, 'quantifier ? matching 0 values returns Nil';
179 is $1.defined, True, 'quantifier * matching 0 values returns empty list';
180 }
181
e76dd4c @moritz s/done_testing/done/ as per recent S24 changes
moritz authored
182 done;
b54c647 [t/spec] Tests for RT #70007
kyle authored
183
95ea915 [t/spec] remove rest of "is also" on classes
moritz authored
184 # vim: ft=perl6
Something went wrong with that request. Please try again.