]> git.vpit.fr Git - perl/modules/re-engine-Plugin.git/blob - t/flags.t
Importing re-engine-Plugin-0.01.tar.gz
[perl/modules/re-engine-Plugin.git] / t / flags.t
1 =pod
2
3 Test the B<flags> method
4
5 =cut
6
7 use strict;
8
9 use feature ':5.10';
10
11 use Test::More tests => 28;
12
13 my @tests = (
14     sub { cmp_ok shift, 'eq', '', => 'no flags' },
15     sub { like shift, qr/c/ => '/c' },
16     sub { cmp_ok shift, 'eq', 'g' => '/g' },
17     sub { cmp_ok shift, 'eq', 'i' => '/i' },
18     sub { cmp_ok shift, 'eq', 'm' => '/m' },
19     sub { cmp_ok shift, 'eq', ''  => '/o' },
20     sub { cmp_ok shift, 'eq', 's' => '/s' },
21     sub { cmp_ok shift, 'eq', 'x' => '/x' },
22     sub { cmp_ok shift, 'eq', 'p' => '/p' },
23     sub { like $_[0], qr/$_/ => "/$_ in $_[0]" for unpack "(A)*", "xi" },
24     sub { like $_[0], qr/$_/ => "/$_ in $_[0]" for unpack "(A)*", "xs" },
25     sub { like $_[0], qr/$_/ => "/$_ in $_[0]" for unpack "(A)*", "cgimsxp" },
26     sub { like $_[0], qr/$_/ => "/$_ in $_[0]" for unpack "(A)*", "e" },
27     sub { like $_[0], qr/$_/ => "/$_ in $_[0]" for unpack "(A)*", "egimsxp" },
28 );
29
30 use re::engine::Plugin (
31     exec => sub {
32         my ($re, $str) = @_;
33
34         my $t = shift @tests;
35
36         $t->($re->flags);
37     }
38 );
39
40 # Provide a pattern that can match to avoid running into regexp
41 # optimizations that won't call exec on C<"" =~ //>;
42
43 "" =~ /x/;
44 "" =~ /x/cg; # meaningless without /g
45 "" =~ /x/g;
46 "" =~ /x/i;
47 "" =~ /x/m;
48 "" =~ /x/o;
49 "" =~ /x/s;
50 "" =~ /x/x;
51 "" =~ /x/p;
52 "" =~ /x/xi;
53 "" =~ /x/xs;
54 "" =~ /x/cgimosxp;
55
56 my $_ = "";
57
58 $_ =~ s/1/2/e;
59 $_ =~ s/1/2/egimosxp;