Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 53 lines (43 sloc) 1.201 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
use v6;
use Test;

plan 13;

#L<S05/Modifiers/"The :c">

my regex simple { . a };
my $string = "1a2a3a";

{
    $string ~~ m:c/<&simple>/;
    is(~$/, '1a', "match first 'a'");
    $string ~~ m:c/<&simple>/;
    is(~$/, '2a', "match second 'a'");
    $string ~~ m:c/<&simple>/;
    is(~$/, '3a', "match third 'a'");
    $string ~~ m:c/<&simple>/;
    is(~$/, '', "no more 'a's to match");
}

{
    my $m = $string.match(/.a/);
    is(~$m, '1a', "match first 'a'");
    $m = $string.match(/.a/, :c(2));
    is(~$m, '2a', "match second 'a'");
    $m = $string.match(/.a/, :c(4));
    is(~$m, '3a', "match third 'a'");
}

# this batch not starting on the exact point, and out of order
{
    my $m = $string.match(/.a/, :c(0));
    is(~$m, '1a', "match first 'a'");
    $m = $string.match(/.a/, :c(3));
    is(~$m, '3a', "match third 'a'");
    $m = $string.match(/.a/, :c(1));
    is(~$m, '2a', "match second 'a'");
}

{
    my $m = $string.match(/.a/);
    is(~$m, '1a', "match first 'a'");
    $m = $string.match(/.a/, :continue(2));
    is(~$m, '2a', "match second 'a'");
    $m = $string.match(/.a/, :continue(4));
    is(~$m, '3a', "match third 'a'");
}

done;

# vim: syn=perl6 sw=4 ts=4 expandtab
Something went wrong with that request. Please try again.