X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2Fscope.t;fp=t%2Fscope.t;h=5ce67162aaff063a3e52cb370355aeb7a93c4fa2;hb=47afe57f6afc7b312d1da725bb38f99ae70b157a;hp=0000000000000000000000000000000000000000;hpb=3980906bcf044db0a6e8aa2680f4cc6b0737a9a9;p=perl%2Fmodules%2Fre-engine-Plugin.git diff --git a/t/scope.t b/t/scope.t new file mode 100644 index 0000000..5ce6716 --- /dev/null +++ b/t/scope.t @@ -0,0 +1,49 @@ +#!perl + +use strict; +use warnings; + +use Test::More tests => 6 * 2; + +my @comp = (0, 0); +my @exec = (0, 0); + +my $rx; + +{ + use re::engine::Plugin comp => sub { ++$comp[0] }, + exec => sub { ++$exec[0]; 0 }; + + eval '$rx = qr/foo/'; + is "@comp", '1 0', 'is compiled with the first engine'; + is "@exec", '0 0', 'not executed yet'; +} + +"abc" =~ /$rx/; +is "@comp", '1 0', 'was compiled with the first engine'; +is "@exec", '1 0', 'is executed with the first engine'; + +{ + use re::engine::Plugin comp => sub { ++$comp[1] }, + exec => sub { ++$exec[1]; 0 }; + + "def" =~ /$rx/; + is "@comp", '1 0', 'was still compiled with the first engine'; + is "@exec", '2 0', 'is executed with the first engine again'; + + eval '$rx = qr/bar/'; + is "@comp", '1 1', 'is compiled with the second engine'; + is "@exec", '2 0', 'not executed since last time'; +} + +"ghi" =~ /$rx/; +is "@comp", '1 1', 'was compiled with the second engine'; +is "@exec", '2 1', 'is executed with the second engine'; + +{ + use re 'debug'; + + "jkl" =~ /$rx/; + is "@comp", '1 1', 'was still compiled with the second engine'; + is "@exec", '2 2', 'is executed with the second engine again (and not with "re \'debug\'")'; +}