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