Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 115 lines (99 sloc) 3.426 kb
fd56de2 [t/spec]: S05 - Moved some capturing tests and added a few
unobe authored
1 use v6;
2 use Test;
b54c647 [t/spec] Tests for RT #70007
kyle authored
3 BEGIN { @*INC.push('t/spec/packages/') };
4 use Test::Util;
5 plan *;
fd56de2 [t/spec]: S05 - Moved some capturing tests and added a few
unobe authored
6
7 if !eval('("a" ~~ /a/)') {
8 skip_rest "skipped tests - rules support appears to be missing";
9 exit;
10 }
11
f33600b smartlink updates
szabgab authored
12 # old: L<S05/Return values from matches/"A match always returns a Match object" >
13 # L<S05/Match objects/"A match always returns a " >
fd56de2 [t/spec]: S05 - Moved some capturing tests and added a few
unobe authored
14 {
15 my $match = 'abd' ~~ m/ (a) (b) c || (\w) b d /;
16 isa_ok( $match, 'Match', 'Match object returned');
17 isa_ok( $/, 'Match', 'Match object assigned to $/');
18 ok( $/ === $match, 'Same match objects');
19 }
20
f33600b smartlink updates
szabgab authored
21 # old: L<S05/Return values from matches/"The array elements of a C<Match> object are referred to" >
22 # L<S05/Accessing captured subpatterns/"The array elements of a " >
fd56de2 [t/spec]: S05 - Moved some capturing tests and added a few
unobe authored
23 {
24 'abd' ~~ m/ (a) (b) c || (\w) b d /;
25 ok( $/[0] eq 'a', 'positional capture accessible');
26 ok( @($/).[0] eq 'a', 'array context - correct number of positional captures');
27 ok( @($/).elems == 1, 'array context - correct number of positional captures');
3d2c0c9 added tests for $/.list and $/.hash
krunen authored
28 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
29 }
30
f33600b smartlink updates
szabgab authored
31 # old: L<S05/Return values from matches/"When used as a hash, a C<Match> object" >
32 # L<S05/Match objects/"When used as a hash" >
fd56de2 [t/spec]: S05 - Moved some capturing tests and added a few
unobe authored
33 {
34 'abd' ~~ m/ <alpha> <alpha> c || <alpha> b d /;
35 ok( $/<alpha> eq 'a', 'named capture accessible');
36 ok( %($/).keys == 1, 'hash context - correct number of named captures');
37 ok( %($/).<alpha> eq 'a', 'hash context - named capture accessible');
3d2c0c9 added tests for $/.list and $/.hash
krunen authored
38 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
39 }
65a1623 add test for accessing match keys through scalary copy RT 62530
ron authored
40
41 # RT 62530
95ea915 [t/spec] remove rest of "is also" on classes
moritz authored
42 #?rakudo skip 'augment'
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 {
54 regex o { o };
55 "foo" ~~ /f<o>+/;
56
57 is ~$<o>, 'o o', 'match list stringifies like a normal list';
58 isa_ok $<o>, List;
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' ~~ /(.)+/ );
72 #?rakudo 2 todo 'match coerced to array is flattened (RT #64952)'
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 {
79 #?rakudo skip 'RT #64948'
80 ok %( 'foo' ~~ /<alpha> oo/ ){ 'alpha' }:exists,
81 'Match coerced to Hash says match exists';
82 }
83
874939b [t/spec/TODO] See r28888 for tests for r28881 and note similar tests
kyle authored
84 # This is similar to a test in S05-interpolation/regex-in-variable.t
b54c647 [t/spec] Tests for RT #70007
kyle authored
85 #?rakudo skip 'RT 70007'
86 nok 'aa' ~~ /(.)$1/, 'match with non-existent capture does not match';
87 #?rakudo todo 'RT 70007'
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';
99 /(R.)/;
100 #?rakudo 2 todo 'RT 66252'
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 {
107 'a' ~~ /a/;
108 #?rakudo skip 'RT 70003'
109 is ($/.orig).rindex('a'), 0, 'rindex() works on $/.orig';
110 }
111
b54c647 [t/spec] Tests for RT #70007
kyle authored
112 done_testing;
113
95ea915 [t/spec] remove rest of "is also" on classes
moritz authored
114 # vim: ft=perl6
Something went wrong with that request. Please try again.