Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[t/spec]: S05 - Moved some capturing tests and added a few

git-svn-id: http://svn.pugscode.org/pugs@24716 c213334d-75ef-0310-aa23-eaa082d1ae64
  • Loading branch information...
commit fd56de2e9f74ee851042b7fbe32c413e6941384b 1 parent 81a7e46
unobe authored
Showing with 34 additions and 0 deletions.
  1. +34 −0 S05-match/capturing-contexts.t
View
34 S05-match/capturing-contexts.t
@@ -0,0 +1,34 @@
+use v6;
+
+use Test;
+
+plan 9;
+
+if !eval('("a" ~~ /a/)') {
+ skip_rest "skipped tests - rules support appears to be missing";
+ exit;
+}
+
+# L<< S05/Return values from matches/"A match always returns a Match object" >>
+{
+ my $match = 'abd' ~~ m/ (a) (b) c || (\w) b d /;
+ isa_ok( $match, 'Match', 'Match object returned');
+ isa_ok( $/, 'Match', 'Match object assigned to $/');
+ ok( $/ === $match, 'Same match objects');
+}
+
+# L<< S05/Return values from matches/"The array elements of a C<Match> object are referred to" >>
+{
+ 'abd' ~~ m/ (a) (b) c || (\w) b d /;
+ ok( $/[0] eq 'a', 'positional capture accessible');
+ ok( @($/).[0] eq 'a', 'array context - correct number of positional captures');
+ ok( @($/).elems == 1, 'array context - correct number of positional captures');
+}
+
+# L<< S05/Return values from matches/"When used as a hash, a C<Match> object" >>
+{
+ 'abd' ~~ m/ <alpha> <alpha> c || <alpha> b d /;
+ ok( $/<alpha> eq 'a', 'named capture accessible');
+ ok( %($/).keys == 1, 'hash context - correct number of named captures');
+ ok( %($/).<alpha> eq 'a', 'hash context - named capture accessible');
+}
Please sign in to comment.
Something went wrong with that request. Please try again.