Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
make capture aliasing tests valid and add more tests
  • Loading branch information
FROGGS committed May 6, 2015
1 parent 0fd0e30 commit 7e8dc19
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions S05-capture/alias.t
Expand Up @@ -12,14 +12,15 @@ be valid perl6.
=end pod

plan 26;
plan 30;

# L<S05/Named scalar aliasing to subpatterns/If a named scalar alias is applied>

ok("abcd" ~~ m/a $<foo>=(..) d/, 'Hypothetical variable capture');
is(~$/<foo>, "bc", 'Hypothetical variable captured');

my $foo;
#?rakudo 2 skip 'Package variable capture RT #125122'
ok("abcd" ~~ m/a $foo=(..) d/, 'Package variable capture');
is(~$foo, "bc", 'Package variable captured');

Expand All @@ -30,13 +31,14 @@ is(~$0, "c", '$0 captured');
is(~$1, "b", '$1 captured');

# L<S05/Named scalar aliases applied to non-capturing brackets/If a named scalar alias>
regex two {..}
my regex two {..}

ok("abcd" ~~ m/a $<foo>=[<two>] d/, 'Compound hypothetical capture');
is(~$/<two>, "bc", 'Implicit hypothetical variable captured');
is(~$/<foo>, "bc", 'Explicit hypothetical variable captured');

$foo = "";
#?rakudo 3 skip 'Package variable capture RT #125122'
ok("abcd" ~~ m/a $foo=[<two>] d/, 'Mixed capture');
is(~$/<two>, "bc", 'Implicit hypothetical variable captured');
is($foo, "bc", 'Explicit package variable captured');
Expand All @@ -48,7 +50,7 @@ is(~$/<ident>, "cat_O_9_tails", 'Captured <?ident>' );
ok("Jon Lee" ~~ m:s/$<first>=(<.ident>) $<family>=(<ident>)/, 'Repeated standard captures' );
is(~$/<first>, "Jon", 'Captured $first' );
is(~$/<family>, "Lee", 'Captured $family' );
is(~$/<ident>, "Lee", 'Captured <ident>' );
is(~$/<family><ident>, "Lee", 'Captured <ident>' );

ok("foo => 22" ~~ m:s/$0=(foo) '=>' (\d+) | $1=(\d+) '<=' $0=(foo) /, 'Pair match' );
is(~$0, 'foo', 'Key match' );
Expand All @@ -58,4 +60,9 @@ ok("22 <= foo" ~~ m:s/$0=(foo) '=>' (\d+) | $1=(\d+) '<=' $0=(foo) /, 'Pair matc
is(~$0, 'foo', 'Reverse key match');
is(~$1, '22', 'Reverse value match');

ok("foobar" ~~ m/$42=. (..) (...) /, 'Capture starting at non-zero');
is(~$42, 'f', 'Capture starting at non-zero, explicit');
is(~$43, 'oo', 'Capture starting at non-zero, incremented once');
is(~$44, 'bar', 'Capture starting at non-zero, incremented twice');

# vim: ft=perl6

0 comments on commit 7e8dc19

Please sign in to comment.