]> git.vpit.fr Git - perl/modules/re-engine-Plugin.git/blob - t/20-methods/mod.t
Silence an experimental warning by getting rid of a lexical $_
[perl/modules/re-engine-Plugin.git] / t / 20-methods / mod.t
1 =pod
2
3 Test the C<mod> or C<modifiers> method
4
5 =cut
6
7 use strict;
8 use Test::More tests => 25;
9
10 my @tests = (
11     sub { cmp_ok shift, 'eq', '', => 'no flags' },
12     sub { cmp_ok shift, 'eq', '', => '/c' },
13     sub { cmp_ok shift, 'eq', '' => '/g' },
14     sub { cmp_ok shift, 'eq', 'i' => '/i' },
15     sub { cmp_ok shift, 'eq', 'm' => '/m' },
16     sub { cmp_ok shift, 'eq', ''  => '/o' },
17     sub { cmp_ok shift, 'eq', 's' => '/s' },
18     sub { cmp_ok shift, 'eq', 'x' => '/x' },
19     sub { cmp_ok shift, 'eq', 'p' => '/p' },
20     sub { like $_[0], qr/$_/ => "/$_ in $_[0]" for unpack "(Z)*", "xi" },
21     sub { like $_[0], qr/$_/ => "/$_ in $_[0]" for unpack "(Z)*", "xs" },
22     sub {
23         for (unpack "(Z)*", "cgimsxp") {
24             /[cg]/ and next;
25             like $_[0], qr/$_/ => "/$_ in $_[0]"
26         }
27     },
28     sub { cmp_ok shift, 'eq', '', => '/e' },
29     sub {
30         for (unpack "(Z)*", "egimsxp") {
31             /[ge]/ and next;
32             like $_[0], qr/$_/ => "/$_ in $_[0]";
33         }
34     },
35
36     sub { cmp_ok shift, 'eq', ''  => '??' },
37     # Leave this as the last
38     ,sub { die "add more tests" }
39 );
40
41 use re::engine::Plugin (
42     exec => sub {
43         my ($re, $str) = @_;
44
45         my $t = shift @tests;
46
47         my %mod = $re->mod;
48
49         my $mod_str = join '', keys %mod;
50
51         $t->($mod_str);
52     }
53 );
54
55 # Provide a pattern that can match to avoid running into regexp
56 # optimizations that won't call exec on C<"" =~ //>;
57
58 "" =~ /x/;
59 "" =~ /x/cg; # meaningless without /g
60 "" =~ /x/g;
61 "" =~ /x/i;
62 "" =~ /x/m;
63 "" =~ /x/o;
64 "" =~ /x/s;
65 "" =~ /x/x;
66 "" =~ /x/p;
67 "" =~ /x/xi;
68 "" =~ /x/xs;
69 "" =~ /x/cgimosxp;
70
71 local $_ = "";
72
73 $_ =~ s/1/2/e;
74 $_ =~ s/1/2/egimosxp;
75 $_ =~ m??;