Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 150 lines (130 sloc) 4.427 kb
fd56de2 [t/spec]: S05 - Moved some capturing tests and added a few
unobe authored
1 use v6;
db4bde7 [t/spec] add 'use MONKEY_TYPING' where appropriate
lwall authored
2 use MONKEY_TYPING;
3
fd56de2 [t/spec]: S05 - Moved some capturing tests and added a few
unobe authored
4 use Test;
b54c647 [t/spec] Tests for RT #70007
kyle authored
5 BEGIN { @*INC.push('t/spec/packages/') };
6 use Test::Util;
d2482f4 replace plan *; with number of tests S03-S06
mberends authored
7 plan 36;
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 /;
7176c48 @coke niecza (auto)unfudge
coke authored
13 #?niecza todo 'match returns match object'
fd56de2 [t/spec]: S05 - Moved some capturing tests and added a few
unobe authored
14 isa_ok( $match, 'Match', 'Match object returned');
7176c48 @coke niecza (auto)unfudge
coke authored
15 #?niecza todo 'match returns match object'
fd56de2 [t/spec]: S05 - Moved some capturing tests and added a few
unobe authored
16 isa_ok( $/, 'Match', 'Match object assigned to $/');
17 ok( $/ === $match, 'Same match objects');
18 }
19
f33600b smartlink updates
szabgab authored
20 # old: L<S05/Return values from matches/"The array elements of a C<Match> object are referred to" >
21 # L<S05/Accessing captured subpatterns/"The array elements of a " >
fd56de2 [t/spec]: S05 - Moved some capturing tests and added a few
unobe authored
22 {
23 'abd' ~~ m/ (a) (b) c || (\w) b d /;
24 ok( $/[0] eq 'a', 'positional capture accessible');
25 ok( @($/).[0] eq 'a', 'array context - correct number of positional captures');
26 ok( @($/).elems == 1, 'array context - correct number of positional captures');
3d2c0c9 added tests for $/.list and $/.hash
krunen authored
27 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
28 }
29
f33600b smartlink updates
szabgab authored
30 # old: L<S05/Return values from matches/"When used as a hash, a C<Match> object" >
31 # L<S05/Match objects/"When used as a hash" >
fd56de2 [t/spec]: S05 - Moved some capturing tests and added a few
unobe authored
32 {
33 'abd' ~~ m/ <alpha> <alpha> c || <alpha> b d /;
34 ok( $/<alpha> eq 'a', 'named capture accessible');
35 ok( %($/).keys == 1, 'hash context - correct number of named captures');
36 ok( %($/).<alpha> eq 'a', 'hash context - named capture accessible');
3d2c0c9 added tests for $/.list and $/.hash
krunen authored
37 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
38 }
65a1623 add test for accessing match keys through scalary copy RT 62530
ron authored
39
40 # RT 62530
95ea915 [t/spec] remove rest of "is also" on classes
moritz authored
41 #?rakudo skip 'augment'
06bb994 @coke fudge for niecza
coke authored
42 #?niecza skip 'rule declaration outside of grammar'
65a1623 add test for accessing match keys through scalary copy RT 62530
ron authored
43 {
95ea915 [t/spec] remove rest of "is also" on classes
moritz authored
44 augment class Match { method keys () {return %(self).keys }; };
65a1623 add test for accessing match keys through scalary copy RT 62530
ron authored
45 rule a {H};
46 "Hello" ~~ /<a>/;
47 is $/.keys, 'a', 'get rule result';
48 my $x = $/;
49 is $x.keys, 'a', 'match copy should be same as match';
50 }
95ea915 [t/spec] remove rest of "is also" on classes
moritz authored
51
404d496 [t/spec] Test for RT #64946
kyle authored
52 # RT #64946
53 {
f824933 [t/spec] fudge capturing-contexts.t for Rakudo
moritz authored
54 my regex o { o };
55 "foo" ~~ /f<o=&o>+/;
404d496 [t/spec] Test for RT #64946
kyle authored
56
57 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
58 ok $<o> ~~ Positional, '... and it is Positional';
404d496 [t/spec] Test for RT #64946
kyle authored
59 # I don't know what difference 'isa' makes, but it does.
60 # Note that calling .WHAT (as in the original ticket) does not have
61 # the same effect.
62 is ~$<o>, 'o o', 'match list stringifies like a normal list AFTER "isa"';
63 }
64
c96e63b [t/spec] Tests for RT #64952
kyle authored
65 # RT #64952
66 {
67 'ab' ~~ /(.)+/;
68 is $/[0][0], 'a', 'match element [0][0] from /(.)+/';
69 is $/[0][1], 'b', 'match element [0][1] from /(.)+/';
70
71 my @match = @( 'ab' ~~ /(.)+/ );
6fba902 @moritz add a test for RT #65308; fudge capturing-contexts.t for rakudo
moritz authored
72 #?rakudo 2 todo 'nom regression'
c96e63b [t/spec] Tests for RT #64952
kyle authored
73 is @match[0][0], 'a', 'match element [0][0] from /(.)+/ coerced';
74 is @match[0][1], 'b', 'match element [0][1] from /(.)+/ coerced';
75 }
76
34fb50f [t/spec] feeble test for RT #64948
kyle authored
77 # RT #64948
78 {
890bc5f @coke rakudo fudging
coke authored
79 ok %( 'foo' ~~ /<alpha> oo/ ).exists('alpha'),
34fb50f [t/spec] feeble test for RT #64948
kyle authored
80 'Match coerced to Hash says match exists';
81 }
82
874939b [t/spec/TODO] See r28888 for tests for r28881 and note similar tests
kyle authored
83 # This is similar to a test in S05-interpolation/regex-in-variable.t
06bb994 @coke fudge for niecza
coke authored
84 #?niecza todo 'match with non-existent capture does not match'
b54c647 [t/spec] Tests for RT #70007
kyle authored
85 nok 'aa' ~~ /(.)$1/, 'match with non-existent capture does not match';
86 #?rakudo todo 'RT 70007'
06bb994 @coke fudge for niecza
coke authored
87 #?niecza todo 'eek'
b54c647 [t/spec] Tests for RT #70007
kyle authored
88 is_run( q{'aa' ~~ /(.)$1/},
89 {
90 status => 0,
91 out => '',
874939b [t/spec/TODO] See r28888 for tests for r28881 and note similar tests
kyle authored
92 err => rx/undef/,
b54c647 [t/spec] Tests for RT #70007
kyle authored
93 },
94 'match with non-existent capture emits a warning' );
95
0865309 [t/spec] Test for RT 66252: match in void context does not set $/
kyle authored
96 # RT #66252
97 {
98 $_ = 'RT 66252';
5ac6379 @moritz correct and unfudge tests for RT #66252
moritz authored
99 m/(R.)/;
06bb994 @coke fudge for niecza
coke authored
100 #?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
101 isa_ok $/, 'Match', 'Match object in $/ after match in void context';
102 is $/, 'RT', 'Matched as intended in void context';
103 }
104
533512a [t/spec] Test for RT 70003: $/.orig produces CodeString
kyle authored
105 # RT #70003
106 {
01db9ce @moritz correct and unfudge tests for RT #70003
moritz authored
107 'abc' ~~ /a/;
108 is ($/.orig).rindex('a'), 0, 'rindex() works on $/.orig';
109 is ($/.orig).rindex('a', 2), 0, 'rindex() works on $/.orig';
533512a [t/spec] Test for RT 70003: $/.orig produces CodeString
kyle authored
110 }
111
046b183 [t/spec] tests for RT #71362, $0, $1 etc. work even for $/ := $something
moritz authored
112 # RT #71362
6fba902 @moritz add a test for RT #65308; fudge capturing-contexts.t for rakudo
moritz authored
113 #?rakudo skip 'binding to $/'
046b183 [t/spec] tests for RT #71362, $0, $1 etc. work even for $/ := $something
moritz authored
114 {
115 $/ := 'foobar';
116 is $0, 'foobar', '$0 works like $/[0], even for non-Match objects';
117 nok $1.defined, '$1 is not defined';
118 }
119
f1ff19a [t/spec] tests for # RT #72956 $0 when $/ is undefined causes Rakudo …
bbkr authored
120 # RT #72956
06bb994 @coke fudge for niecza
coke authored
121 #?niecza skip 'Unsupported use of $/ variable as input record separator'
f1ff19a [t/spec] tests for # RT #72956 $0 when $/ is undefined causes Rakudo …
bbkr authored
122 {
123 $/ = Any;
124 lives_ok { $0 },
125 '$0 accessible when $/ is undefined';
6fba902 @moritz add a test for RT #65308; fudge capturing-contexts.t for rakudo
moritz authored
126 #?rakudo todo 'RT 72956'
b5caf94 [t/spec] tests for RT #RT #77160, flattening of quantified captures i…
moritz authored
127 ok $0 === Any,
f1ff19a [t/spec] tests for # RT #72956 $0 when $/ is undefined causes Rakudo …
bbkr authored
128 '$0 is Any when $/ is undefined';
816c95f [t/spec] be even more explicit with undefinedness check
moritz authored
129 nok $0.defined, '$0 is undefined';
f1ff19a [t/spec] tests for # RT #72956 $0 when $/ is undefined causes Rakudo …
bbkr authored
130 }
131
b5caf94 [t/spec] tests for RT #RT #77160, flattening of quantified captures i…
moritz authored
132 # RT #77160
133 {
134 ok 'abc' ~~ /(.)+/, 'regex sanity';
135 my $x = 0;
136 $x++ for $/.list;
6fba902 @moritz add a test for RT #65308; fudge capturing-contexts.t for rakudo
moritz authored
137 #?rakudo todo 'nom regression'
b5caf94 [t/spec] tests for RT #RT #77160, flattening of quantified captures i…
moritz authored
138 is $x, 1, '$/.list does not flatten quantified subcaptures';
139
140 ok 'abc' ~~ /(.)**2 (.)/, 'regex sanity';
141 $x = 0;
142 $x++ for $/.list;
6fba902 @moritz add a test for RT #65308; fudge capturing-contexts.t for rakudo
moritz authored
143 #?rakudo todo 'nom regression'
b5caf94 [t/spec] tests for RT #RT #77160, flattening of quantified captures i…
moritz authored
144 is $x, 2, '$/.list does not flattens subcaptures';
145 }
146
e76dd4c @moritz s/done_testing/done/ as per recent S24 changes
moritz authored
147 done;
b54c647 [t/spec] Tests for RT #70007
kyle authored
148
95ea915 [t/spec] remove rest of "is also" on classes
moritz authored
149 # vim: ft=perl6
Something went wrong with that request. Please try again.