]> git.vpit.fr Git - perl/modules/re-engine-Plugin.git/blob - t/import.t
Importing re-engine-Plugin-0.02.tar.gz
[perl/modules/re-engine-Plugin.git] / t / import.t
1 =pod
2
3 Test that lexical importing works, check BEGIN-ish stuff etc.
4
5 =cut
6
7 use strict;
8 use Test::More tests => 8;
9 use re::engine::Plugin ();
10
11 like "a", qr/^a$/, "import didn't run, perl's regex engine in effect";
12
13 BEGIN {
14     re::engine::Plugin->import(
15         exec => sub { $_[0]->pattern eq $_[1] }
16     );
17 }
18
19 ok "^hello" =~ /^hello/ => "regex modified to match a literal pattern";
20
21 {
22     BEGIN {
23         re::engine::Plugin->import(
24             exec => sub { $_[0]->pattern ne $_[1] }
25         );
26     }
27
28     ok "^hello" !~ /^hello/ => "regex modified not to match a literal pattern";
29     {
30         BEGIN {
31             re::engine::Plugin->import(
32                 exec => sub { $_[0]->pattern eq '^[abc]$' }
33             );
34         }
35         ok "whatever" =~ /^[abc]$/ => "regex modified to match some exact nonsense";
36         BEGIN { re::engine::Plugin->unimport };
37         ok "whatever" !~ /^[abc]$/ => "regex modified to match some exact nonsense unimported";
38     }
39     ok "^hello" !~ /^hello/ => "regex modified not to match a literal pattern";
40 }
41
42 ok "^hello" =~ /^hello/ => "regex modified to match a literal pattern";
43
44 # Another import at the same scope
45 BEGIN {
46     re::engine::Plugin->import(
47         exec => sub { $_[0]->pattern ne $_[1] }
48     );
49 }
50
51 ok "^hello" !~ /^hello/ => "regex modified not to match a literal pattern";