Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 135 lines (116 sloc) 3.88 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;
7 plan *;
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';
55 isa_ok $<o>, List;
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' ~~ /(.)+/ );
f824933 [t/spec] fudge capturing-contexts.t for Rakudo
moritz authored
69 #?rakudo 2 skip 'match coerced to array is flattened (RT #64952)'
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
f824933 [t/spec] fudge capturing-contexts.t for Rakudo
moritz authored
75 #?rakudo skip 'RT 64948'
34fb50f [t/spec] feeble test for RT #64948
kyle authored
76 {
77 ok %( 'foo' ~~ /<alpha> oo/ ){ 'alpha' }:exists,
78 'Match coerced to Hash says match exists';
79 }
80
874939b [t/spec/TODO] See r28888 for tests for r28881 and note similar tests
kyle authored
81 # This is similar to a test in S05-interpolation/regex-in-variable.t
b54c647 [t/spec] Tests for RT #70007
kyle authored
82 #?rakudo skip 'RT 70007'
83 nok 'aa' ~~ /(.)$1/, 'match with non-existent capture does not match';
84 #?rakudo todo 'RT 70007'
85 is_run( q{'aa' ~~ /(.)$1/},
86 {
87 status => 0,
88 out => '',
874939b [t/spec/TODO] See r28888 for tests for r28881 and note similar tests
kyle authored
89 err => rx/undef/,
b54c647 [t/spec] Tests for RT #70007
kyle authored
90 },
91 'match with non-existent capture emits a warning' );
92
0865309 [t/spec] Test for RT 66252: match in void context does not set $/
kyle authored
93 # RT #66252
94 {
95 $_ = 'RT 66252';
96 /(R.)/;
97 #?rakudo 2 todo 'RT 66252'
98 isa_ok $/, 'Match', 'Match object in $/ after match in void context';
99 is $/, 'RT', 'Matched as intended in void context';
100 }
101
533512a [t/spec] Test for RT 70003: $/.orig produces CodeString
kyle authored
102 # RT #70003
f6891ad [t/spec] improve tests for RT #70007
moritz authored
103 #?rakudo skip 'RT 70003'
533512a [t/spec] Test for RT 70003: $/.orig produces CodeString
kyle authored
104 {
f6891ad [t/spec] improve tests for RT #70007
moritz authored
105 is ($/.orig).rindex('a'), 1, 'rindex() works on $/.orig';
106 is ($/.orig).rindex('a', 2), 1, 'rindex() works on $/.orig';
533512a [t/spec] Test for RT 70003: $/.orig produces CodeString
kyle authored
107 }
108
f1ff19a [t/spec] tests for # RT #72956 $0 when $/ is undefined causes Rakudo to ...
bbkr authored
109 # RT #72956
110 {
111 $/ = Any;
112 lives_ok { $0 },
113 '$0 accessible when $/ is undefined';
b5caf94 [t/spec] tests for RT #RT #77160, flattening of quantified captures in M...
moritz authored
114 ok $0 === Any,
f1ff19a [t/spec] tests for # RT #72956 $0 when $/ is undefined causes Rakudo to ...
bbkr authored
115 '$0 is Any when $/ is undefined';
816c95f [t/spec] be even more explicit with undefinedness check
moritz authored
116 nok $0.defined, '$0 is undefined';
f1ff19a [t/spec] tests for # RT #72956 $0 when $/ is undefined causes Rakudo to ...
bbkr authored
117 }
118
b5caf94 [t/spec] tests for RT #RT #77160, flattening of quantified captures in M...
moritz authored
119 # RT #77160
120 {
121 ok 'abc' ~~ /(.)+/, 'regex sanity';
122 my $x = 0;
123 $x++ for $/.list;
124 is $x, 1, '$/.list does not flatten quantified subcaptures';
125
126 ok 'abc' ~~ /(.)**2 (.)/, 'regex sanity';
127 $x = 0;
128 $x++ for $/.list;
129 is $x, 2, '$/.list does not flattens subcaptures';
130 }
131
b54c647 [t/spec] Tests for RT #70007
kyle authored
132 done_testing;
133
95ea915 [t/spec] remove rest of "is also" on classes
moritz authored
134 # vim: ft=perl6
Something went wrong with that request. Please try again.