This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Replaced 'unlink' with 'unlink_all' in t/op/magic.t
[perl5.git] / t / re / re.t
1 #!./perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = '../lib';
6     require './test.pl';
7 }
8
9 use strict;
10 use warnings;
11
12 use re qw(is_regexp regexp_pattern
13           regname regnames regnames_count);
14 {
15     use feature 'unicode_strings';  # Force 'u' pat mod
16     my $qr=qr/foo/pi;
17     no feature 'unicode_strings';
18     my $rx = $$qr;
19
20     ok(is_regexp($qr),'is_regexp(REGEXP ref)');
21     ok(is_regexp($rx),'is_regexp(REGEXP)');
22     ok(!is_regexp(''),'is_regexp("")');
23
24     is((regexp_pattern($qr))[0],'foo','regexp_pattern[0] (ref)');
25     is((regexp_pattern($qr))[1],'uip','regexp_pattern[1] (ref)');
26     is(regexp_pattern($qr),'(?^upi:foo)','scalar regexp_pattern (ref)');
27
28     is((regexp_pattern($rx))[0],'foo','regexp_pattern[0] (bare REGEXP)');
29     is((regexp_pattern($rx))[1],'uip','regexp_pattern[1] (bare REGEXP)');
30     is(regexp_pattern($rx),'(?^upi:foo)', 'scalar regexp_pattern (bare REGEXP)');
31
32     ok(!regexp_pattern(''),'!regexp_pattern("")');
33 }
34
35 if ('1234'=~/(?:(?<A>\d)|(?<C>!))(?<B>\d)(?<A>\d)(?<B>\d)/){
36     my @names = sort +regnames();
37     is("@names","A B","regnames");
38     @names = sort +regnames(0);
39     is("@names","A B","regnames");
40     my $names = regnames();
41     is($names, "B", "regnames in scalar context");
42     @names = sort +regnames(1);
43     is("@names","A B C","regnames");
44     is(join("", @{regname("A",1)}),"13");
45     is(join("", @{regname("B",1)}),"24");
46     {
47         if ('foobar'=~/(?<foo>foo)(?<bar>bar)/) {
48             is(regnames_count(),2);
49         } else {
50             ok(0); ok(0);
51         }
52     }
53     is(regnames_count(),3);
54 }
55
56     { # Keep these tests last, as whole script will be interrupted if times out
57         # Bug #72998; this can loop 
58         watchdog(2);
59         eval '"\x{100}\x{FB00}" =~ /\x{100}\N{U+66}+/i';
60         pass("Didn't loop");
61
62         # Bug #78058; this can loop
63         watchdog(2);
64         no warnings;    # Because the 8 may be warned on
65         eval 'qr/\18/';
66         pass("qr/\18/ didn't loop");
67     }
68
69 # New tests above this line, don't forget to update the test count below!
70 BEGIN { plan tests => 20 }
71 # No tests here!