|
| 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