Skip to content
Newer
Older
100644 140 lines (120 sloc) 3.83 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';
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' ~~ /(.)+/ );
69 is @match[0][0], 'a', 'match element [0][0] from /(.)+/ coerced';
70 is @match[0][1], 'b', 'match element [0][1] from /(.)+/ coerced';
71 }
72
34fb50f [t/spec] feeble test for RT #64948
kyle authored
73 # RT #64948
f824933 [t/spec] fudge capturing-contexts.t for Rakudo
moritz authored
74 #?rakudo skip 'RT 64948'
34fb50f [t/spec] feeble test for RT #64948
kyle authored
75 {
76 ok %( 'foo' ~~ /<alpha> oo/ ){ 'alpha' }:exists,
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 #?rakudo skip 'RT 70007'
82 nok 'aa' ~~ /(.)$1/, 'match with non-existent capture does not match';
83 #?rakudo todo 'RT 70007'
84 is_run( q{'aa' ~~ /(.)$1/},
85 {
86 status => 0,
87 out => '',
874939b [t/spec/TODO] See r28888 for tests for r28881 and note similar tests
kyle authored
88 err => rx/undef/,
b54c647 [t/spec] Tests for RT #70007
kyle authored
89 },
90 'match with non-existent capture emits a warning' );
91
0865309 [t/spec] Test for RT 66252: match in void context does not set $/
kyle authored
92 # RT #66252
93 {
94 $_ = 'RT 66252';
5ac6379 @moritz correct and unfudge tests for RT #66252
moritz authored
95 m/(R.)/;
0865309 [t/spec] Test for RT 66252: match in void context does not set $/
kyle authored
96 isa_ok $/, 'Match', 'Match object in $/ after match in void context';
97 is $/, 'RT', 'Matched as intended in void context';
98 }
99
533512a [t/spec] Test for RT 70003: $/.orig produces CodeString
kyle authored
100 # RT #70003
f6891ad [t/spec] improve tests for RT #70007
moritz authored
101 #?rakudo skip 'RT 70003'
533512a [t/spec] Test for RT 70003: $/.orig produces CodeString
kyle authored
102 {
f6891ad [t/spec] improve tests for RT #70007
moritz authored
103 is ($/.orig).rindex('a'), 1, 'rindex() works on $/.orig';
104 is ($/.orig).rindex('a', 2), 1, 'rindex() works on $/.orig';
533512a [t/spec] Test for RT 70003: $/.orig produces CodeString
kyle authored
105 }
106
046b183 [t/spec] tests for RT #71362, $0, $1 etc. work even for $/ := $something
moritz authored
107 # RT #71362
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 …
bbkr authored
114 # RT #72956
115 {
116 $/ = Any;
117 lives_ok { $0 },
118 '$0 accessible when $/ is undefined';
b5caf94 [t/spec] tests for RT #RT #77160, flattening of quantified captures i…
moritz authored
119 ok $0 === Any,
f1ff19a [t/spec] tests for # RT #72956 $0 when $/ is undefined causes Rakudo …
bbkr authored
120 '$0 is Any when $/ is undefined';
816c95f [t/spec] be even more explicit with undefinedness check
moritz authored
121 nok $0.defined, '$0 is undefined';
f1ff19a [t/spec] tests for # RT #72956 $0 when $/ is undefined causes Rakudo …
bbkr authored
122 }
123
b5caf94 [t/spec] tests for RT #RT #77160, flattening of quantified captures i…
moritz authored
124 # RT #77160
125 {
126 ok 'abc' ~~ /(.)+/, 'regex sanity';
127 my $x = 0;
128 $x++ for $/.list;
129 is $x, 1, '$/.list does not flatten quantified subcaptures';
130
131 ok 'abc' ~~ /(.)**2 (.)/, 'regex sanity';
132 $x = 0;
133 $x++ for $/.list;
134 is $x, 2, '$/.list does not flattens subcaptures';
135 }
136
e76dd4c @moritz s/done_testing/done/ as per recent S24 changes
moritz authored
137 done;
b54c647 [t/spec] Tests for RT #70007
kyle authored
138
95ea915 [t/spec] remove rest of "is also" on classes
moritz authored
139 # vim: ft=perl6
Something went wrong with that request. Please try again.