Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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