X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=t%2F10-usage%2Fintegrate.t;fp=t%2F10-usage%2Fintegrate.t;h=f2eae227478ae36e455f2ba9abed3a4b24ccb262;hb=386630c145754930ffc3a3b0988dd0108f4394db;hp=0000000000000000000000000000000000000000;hpb=36958ebe8b4c296f858f6b5df8f629cdb341812d;p=perl%2Fmodules%2Fre-engine-Plugin.git diff --git a/t/10-usage/integrate.t b/t/10-usage/integrate.t new file mode 100644 index 0000000..f2eae22 --- /dev/null +++ b/t/10-usage/integrate.t @@ -0,0 +1,51 @@ +=pod + +Test that lexical importing works, check BEGIN-ish stuff etc. + +=cut + +use strict; +use Test::More tests => 8; +use re::engine::Plugin (); + +like "a", qr/^a$/, "import didn't run, perl's regex engine in effect"; + +BEGIN { + re::engine::Plugin->import( + exec => sub { $_[0]->pattern eq $_[1] } + ); +} + +ok "^hello" =~ /^hello/ => "regex modified to match a literal pattern"; + +{ + BEGIN { + re::engine::Plugin->import( + exec => sub { $_[0]->pattern ne $_[1] } + ); + } + + ok "^hello" !~ /^hello/ => "regex modified not to match a literal pattern"; + { + BEGIN { + re::engine::Plugin->import( + exec => sub { $_[0]->pattern eq '^[abc]$' } + ); + } + ok "whatever" =~ /^[abc]$/ => "regex modified to match some exact nonsense"; + BEGIN { re::engine::Plugin->unimport }; + ok "whatever" !~ /^[abc]$/ => "regex modified to match some exact nonsense unimported"; + } + ok "^hello" !~ /^hello/ => "regex modified not to match a literal pattern"; +} + +ok "^hello" =~ /^hello/ => "regex modified to match a literal pattern"; + +# Another import at the same scope +BEGIN { + re::engine::Plugin->import( + exec => sub { $_[0]->pattern ne $_[1] } + ); +} + +ok "^hello" !~ /^hello/ => "regex modified not to match a literal pattern";