]> git.vpit.fr Git - perl/modules/re-engine-Plugin.git/blob - t/methods.t
Importing re-engine-Plugin-0.01.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 'no_plan';#tests => 6;
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         # flags
31         my $f = $re->flags;
32         like $f, qr/i/, 'str flags /i';
33         like $f, qr/x/, 'str flags /x';
34         like $f, 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         # This needs a less sucky name
43         #
44         # Pattern: ' foobar zoobar ', set $1 to "foobar" (if I counted this right:)
45 #        $re->offset_captures( [1, 7], ... ); 
46
47         # This name sucks as well
48 #        $re->named_captures2offset_captures( myNameIs => 0 ): # $+{myNameIs} = $1
49
50         # Pattern contains "foo", "bar" and "zoo", return a true
51         return $re->pattern =~ /zoo/;
52     }
53 );
54
55 my $re = qr< foobar zoobar >xi;
56
57 if ("input" =~ $re ) {
58     pass 'pattern matched';
59 } else {
60     fail "pattern didn't match";
61 }
62