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