Skip to content

Commit fe86784

Browse files
committed
Test P5 named captures
Issue: rakudo/rakudo#1269 NQP fix: Raku/nqp@10e392477975168a0a9f53c0
1 parent dcb982a commit fe86784

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

S05-modifier/perl5_10.t

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
use v6;
2+
use Test;
3+
4+
plan 1;
5+
6+
unless "a" ~~ rx:P5/a/ {
7+
skip-rest "skipped tests - P5 regex support appears to be missing";
8+
exit;
9+
}
10+
11+
subtest 'named captures' => { plan 7;
12+
sub test-cap (\c, \v, $desc) {
13+
subtest $desc => { plan 2;
14+
isa-ok c, Capture, 'correct type';
15+
is c, v, 'correct value';
16+
}
17+
}
18+
19+
subtest 'one named (?<>) capture' => { plan 2;
20+
ok 'foo' ~~ m:P5/(?<meow>.+)/, 'matched';
21+
test-cap $<meow>, 'foo', 'named capture';
22+
}
23+
subtest 'two named (?<>) captures' => { plan 3;
24+
ok 'fooBAR' ~~ m:P5/(?<meow>[a-z]+)(?<moo>[A-Z]+)/, 'matched';
25+
test-cap $<meow>, 'foo', 'first named capture';
26+
test-cap $<moo>, 'BAR', 'second named capture';
27+
}
28+
subtest 'two named (?<>) + one positional captures' => { plan 4;
29+
ok 'foo42BAR' ~~ m:P5/(?<meow>[a-z]+)(\d+)(?<moo>[A-Z]+)/, 'matched';
30+
test-cap $/[0], '42', 'positional capture';
31+
test-cap $<meow>, 'foo', 'first named capture';
32+
test-cap $<moo>, 'BAR', 'second named capture';
33+
}
34+
35+
subtest one named (?'') capture => { plan 2;
36+
ok 'foo' ~~ m:P5/(?'meow'.+)/, 'matched';
37+
test-cap $<meow>, 'foo', 'named capture';
38+
}
39+
subtest two named (?'') captures => { plan 3;
40+
ok 'fooBAR' ~~ m:P5/(?'meow'[a-z]+)(?'moo'[A-Z]+)/, 'matched';
41+
test-cap $<meow>, 'foo', 'first named capture';
42+
test-cap $<moo>, 'BAR', 'second named capture';
43+
}
44+
subtest two named (?'') + one positional captures => { plan 4;
45+
ok 'foo42BAR' ~~ m:P5/(?'meow'[a-z]+)(\d+)(?'moo'[A-Z]+)/, 'matched';
46+
test-cap $/[0], '42', 'positional capture';
47+
test-cap $<meow>, 'foo', 'first named capture';
48+
test-cap $<moo>, 'BAR', 'second named capture';
49+
}
50+
51+
subtest named (?'') + named (?<>) + one positional captures => { plan 4;
52+
ok 'foo42BAR' ~~ m:P5/(?<meow>[a-z]+)(\d+)(?'moo'[A-Z]+)/, 'matched';
53+
test-cap $/[0], '42', 'positional capture';
54+
test-cap $<meow>, 'foo', 'first named (?<>) capture';
55+
test-cap $<moo>, 'BAR', second named (?'') capture;
56+
}
57+
}
58+
59+
# vim: ft=perl6

0 commit comments

Comments
 (0)