Browse files

[t/spec] tests for external aliases in regexes

git-svn-id: c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information...
1 parent dccdaef commit a9ca9d7f3d343eb184e9ccd02f7ef619d92c299a moritz committed May 3, 2009
Showing with 30 additions and 0 deletions.
  1. +30 −0 S05-capture/external-aliasing.t
@@ -0,0 +1,30 @@
+use v6;
+use Test;
+plan 12;
+# L<S05/External aliasing/>
+my $x;
+our $y;
+ok 'ab cd ef' ~~ m/:s <ident> $OUTER::x=<ident> $OUTER::y=<ident>/,
+ 'regex matched';
+isa_ok $x, Match, 'stored a match object in outer lexical var';
+isa_ok $y, Match, 'stored a match object in outer package var';
+isa_ok $<ident>, Match, '... the normal capture also is a Match object';
+is ~$<ident>, 'ab', 'normal match object still works';
+is ~$x, 'cd', 'outer lexical var got the right value';
+is ~$y, 'ef', 'outer package var got the right value';
+# this is a bit guesswork here on how outer vars interact with .caps and
+# .chunks. It seems sane to assume that .caps will ignore those parts that
+# are bound to external variables (since it knows nothing about them)
+is +$/.caps, 'one capture';
+is ~$/.caps.[0].value, 'ab', 'right value in .caps';
+is +$/.chunks, 2, 'two chunks';
+is $/{.key}).join('|'), 'ident|~', 'right keys of .chunks';
+is $/{.value}).join('|'), 'ab| cd ef', 'right values of .chunks';
+# vim: ft=perl6

0 comments on commit a9ca9d7

Please sign in to comment.