summaryrefslogtreecommitdiff
path: root/cpan/Test-Simple/t/Builder/maybe_regex.t
blob: d1927a56e5b14d804ae0b75279e3c8f3dcff131c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/perl -w

BEGIN {
    if( $ENV{PERL_CORE} ) {
        chdir 't';
        @INC = ('../lib', 'lib');
    }
    else {
        unshift @INC, 't/lib';
    }
}

use strict;
use Test::More tests => 16;

use Test::Builder;
my $Test = Test::Builder->new;

my $r = $Test->maybe_regex(qr/^FOO$/i);
ok(defined $r, 'qr// detected');
ok(('foo' =~ /$r/), 'qr// good match');
ok(('bar' !~ /$r/), 'qr// bad match');

SKIP: {
    skip "blessed regex checker added in 5.10", 3 if $] < 5.010;
    
    my $obj = bless qr/foo/, 'Wibble';
    my $re = $Test->maybe_regex($obj);
    ok( defined $re, "blessed regex detected" );
    ok( ('foo' =~ /$re/), 'blessed qr/foo/ good match' );
    ok( ('bar' !~ /$re/), 'blessed qr/foo/ bad math' );
}

{
	my $r = $Test->maybe_regex('/^BAR$/i');
	ok(defined $r, '"//" detected');
	ok(('bar' =~ m/$r/), '"//" good match');
	ok(('foo' !~ m/$r/), '"//" bad match');
};

{
	my $r = $Test->maybe_regex('not a regex');
	ok(!defined $r, 'non-regex detected');
};


{
	my $r = $Test->maybe_regex('/0/');
	ok(defined $r, 'non-regex detected');
	ok(('f00' =~ m/$r/), '"//" good match');
	ok(('b4r' !~ m/$r/), '"//" bad match');
};


{
	my $r = $Test->maybe_regex('m,foo,i');
	ok(defined $r, 'm,, detected');
	ok(('fOO' =~ m/$r/), '"//" good match');
	ok(('bar' !~ m/$r/), '"//" bad match');
};