]> git.vpit.fr Git - perl/modules/re-engine-Plugin.git/blob - t/usage/scope.t
Put all tests into a subdirectory
[perl/modules/re-engine-Plugin.git] / t / usage / scope.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 6 * 2;
7
8 my @comp = (0, 0);
9 my @exec = (0, 0);
10
11 my $rx;
12
13 {
14  use re::engine::Plugin comp => sub { ++$comp[0] },
15                         exec => sub { ++$exec[0]; 0 };
16
17  eval '$rx = qr/foo/';
18  is "@comp", '1 0', 'is compiled with the first engine';
19  is "@exec", '0 0', 'not executed yet';
20 }
21
22 "abc" =~ /$rx/;
23 is "@comp", '1 0', 'was compiled with the first engine';
24 is "@exec", '1 0', 'is executed with the first engine';
25
26 {
27  use re::engine::Plugin comp => sub { ++$comp[1] },
28                         exec => sub { ++$exec[1]; 0 };
29
30  "def" =~ /$rx/;
31  is "@comp", '1 0', 'was still compiled with the first engine';
32  is "@exec", '2 0', 'is executed with the first engine again';
33
34  eval '$rx = qr/bar/';
35  is "@comp", '1 1', 'is compiled with the second engine';
36  is "@exec", '2 0', 'not executed since last time';
37 }
38
39 "ghi" =~ /$rx/;
40 is "@comp", '1 1', 'was compiled with the second engine';
41 is "@exec", '2 1', 'is executed with the second engine';
42
43 {
44  use re 'debug';
45
46  "jkl" =~ /$rx/;
47  is "@comp", '1 1', 'was still compiled with the second engine';
48  is "@exec", '2 2', 'is executed with the second engine again (and not with "re \'debug\'")';
49 }