This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Variants of several regression tests that run the actul tests inside
[perl5.git] / t / op / re.t
1 #!./perl
2
3 BEGIN {
4         chdir 't' if -d 't';
5         @INC = '../lib';
6 }
7
8 use strict;
9 use warnings;
10
11 use Test::More; # test count at bottom of file
12 use re qw(is_regexp regexp_pattern
13           regname regnames regnames_count);
14 {
15     my $qr=qr/foo/pi;
16     ok(is_regexp($qr),'is_regexp($qr)');
17     ok(!is_regexp(''),'is_regexp("")');
18     is((regexp_pattern($qr))[0],'foo','regexp_pattern[0]');
19     is((regexp_pattern($qr))[1],'ip','regexp_pattern[1]');
20     is(regexp_pattern($qr),'(?pi-xsm:foo)','scalar regexp_pattern');
21     ok(!regexp_pattern(''),'!regexp_pattern("")');
22 }
23
24 if ('1234'=~/(?:(?<A>\d)|(?<C>!))(?<B>\d)(?<A>\d)(?<B>\d)/){
25     my @names = sort +regnames();
26     is("@names","A B","regnames");
27     @names = sort +regnames(0);
28     is("@names","A B","regnames");
29     my $names = regnames();
30     is($names, "B", "regnames in scalar context");
31     @names = sort +regnames(1);
32     is("@names","A B C","regnames");
33     is(join("", @{regname("A",1)}),"13");
34     is(join("", @{regname("B",1)}),"24");
35     {
36         if ('foobar'=~/(?<foo>foo)(?<bar>bar)/) {
37             is(regnames_count(),2);
38         } else {
39             ok(0); ok(0);
40         }
41     }
42     is(regnames_count(),3);
43 }
44 # New tests above this line, don't forget to update the test count below!
45 use Test::More tests => 14;
46 # No tests here!