Commit | Line | Data |
de8c5301 |
1 | #!./perl |
2 | |
3 | BEGIN { |
4 | chdir 't' if -d 't'; |
5 | @INC = '../lib'; |
6 | require Config; |
7 | if (($Config::Config{'extensions'} !~ /\bre\b/) ){ |
8 | print "1..0 # Skip -- Perl configured without re module\n"; |
9 | exit 0; |
10 | } |
11 | } |
12 | |
13 | use strict; |
08f18727 |
14 | use warnings; |
de8c5301 |
15 | |
256ddcd0 |
16 | use Test::More; # test count at bottom of file |
44a2ac75 |
17 | use re qw(is_regexp regexp_pattern regmust |
192b9cd1 |
18 | regname regnames regnames_count); |
bcdf7404 |
19 | { |
87e95b7f |
20 | my $qr=qr/foo/pi; |
bcdf7404 |
21 | ok(is_regexp($qr),'is_regexp($qr)'); |
22 | ok(!is_regexp(''),'is_regexp("")'); |
23 | is((regexp_pattern($qr))[0],'foo','regexp_pattern[0]'); |
87e95b7f |
24 | is((regexp_pattern($qr))[1],'ip','regexp_pattern[1]'); |
25 | is(regexp_pattern($qr),'(?pi-xsm:foo)','scalar regexp_pattern'); |
bcdf7404 |
26 | ok(!regexp_pattern(''),'!regexp_pattern("")'); |
27 | } |
256ddcd0 |
28 | { |
29 | my $qr=qr/here .* there/x; |
30 | my ($anchored,$floating)=regmust($qr); |
31 | is($anchored,'here',"Regmust anchored - qr//"); |
32 | is($floating,'there',"Regmust floating - qr//"); |
33 | my $foo='blah'; |
34 | ($anchored,$floating)=regmust($foo); |
35 | is($anchored,undef,"Regmust anchored - non ref"); |
36 | is($floating,undef,"Regmust anchored - non ref"); |
37 | my $bar=['blah']; |
38 | ($anchored,$floating)=regmust($foo); |
39 | is($anchored,undef,"Regmust anchored - ref"); |
40 | is($floating,undef,"Regmust anchored - ref"); |
41 | } |
42 | |
44a2ac75 |
43 | if ('1234'=~/(?:(?<A>\d)|(?<C>!))(?<B>\d)(?<A>\d)(?<B>\d)/){ |
28d8d7f4 |
44 | my @names = sort +regnames(); |
44a2ac75 |
45 | is("@names","A B","regnames"); |
08f18727 |
46 | @names = sort +regnames(0); |
192b9cd1 |
47 | is("@names","A B","regnames"); |
48 | my $names = regnames(); |
49 | is($names, "B", "regnames in scalar context"); |
28d8d7f4 |
50 | @names = sort +regnames(1); |
44a2ac75 |
51 | is("@names","A B C","regnames"); |
28d8d7f4 |
52 | is(join("", @{regname("A",1)}),"13"); |
53 | is(join("", @{regname("B",1)}),"24"); |
44a2ac75 |
54 | { |
28d8d7f4 |
55 | if ('foobar'=~/(?<foo>foo)(?<bar>bar)/) { |
44a2ac75 |
56 | is(regnames_count(),2); |
57 | } else { |
58 | ok(0); ok(0); |
59 | } |
60 | } |
61 | is(regnames_count(),3); |
44a2ac75 |
62 | } |
256ddcd0 |
63 | # New tests above this line, don't forget to update the test count below! |
192b9cd1 |
64 | use Test::More tests => 20; |
256ddcd0 |
65 | # No tests here! |