]> git.vpit.fr Git - perl/modules/re-engine-Plugin.git/blob - t/methods.t
Importing re-engine-Plugin-0.02.tar.gz
[perl/modules/re-engine-Plugin.git] / t / methods.t
1 =pod
2
3 Tests methods on the re object
4
5 =cut
6
7 use strict;
8
9 use feature ':5.10';
10
11 use Test::More tests => 9;
12
13 use re::engine::Plugin (
14     comp => sub  {
15         my $re = shift;
16
17         # Use a stash to pass a single scalar value to each executing
18         # routine, references work perfectly a reference to anything
19         # can be passed as well
20         $re->stash( { x => 5, y => sub { 6 } } );
21
22         # Return value not used for now..
23     },
24     exec => sub {
25         my ($re, $str) = @_;
26
27         # pattern
28         cmp_ok($re->pattern, 'eq', ' foobar zoobar ' => '->pattern ok');
29
30         # modifiers
31         my %mod = $re->mod;
32         ok(exists $mod{i}, 'str flags /i');
33         ok(exists $mod{x}, 'str flags /i');
34         like(join('', keys %mod), qr/^[cgimosx]+$/, 'flags contain all-good characters');
35
36         # stash
37         cmp_ok($re->stash->{"x"}, '==', 5, "data correct in stash");
38         cmp_ok(ref $re->stash->{"y"}, 'eq', 'CODE', "data correct in stash");
39         cmp_ok(ref $re->stash->{"y"}, 'eq', 'CODE', "data correct in stash");
40         cmp_ok($re->stash->{"y"}->(), '==', 6, "data correct in stash");
41
42         # Pattern contains "foo", "bar" and "zoo", return a true
43         return $re->pattern =~ /zoo/;
44     }
45 );
46
47 my $re = qr< foobar zoobar >xi;
48
49 if ("input" =~ $re ) {
50     pass 'pattern matched';
51 } else {
52     fail "pattern didn't match";
53 }
54