]> git.vpit.fr Git - perl/modules/re-engine-Plugin.git/blobdiff - t/usage/integrate.t
Put all tests into a subdirectory
[perl/modules/re-engine-Plugin.git] / t / usage / integrate.t
diff --git a/t/usage/integrate.t b/t/usage/integrate.t
new file mode 100644 (file)
index 0000000..f2eae22
--- /dev/null
@@ -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";