]> git.vpit.fr Git - perl/modules/re-engine-Plugin.git/blobdiff - t/callbacks/exec.t
Introduce ->callbacks to specify the 'exec' callback individually
[perl/modules/re-engine-Plugin.git] / t / callbacks / exec.t
diff --git a/t/callbacks/exec.t b/t/callbacks/exec.t
new file mode 100644 (file)
index 0000000..d340ffe
--- /dev/null
@@ -0,0 +1,38 @@
+#!perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 4 * 2;
+
+my $count;
+
+use re::engine::Plugin comp => sub {
+ my ($re) = @_;
+
+ my $pat = $re->pattern;
+
+ $re->callbacks(
+  exec => sub {
+   my ($re, $str) = @_;
+
+   ++$count;
+
+   return $str eq $pat;
+  },
+ );
+};
+
+$count = 0;
+
+ok "foo"  =~ /foo/;
+is $count, 1;
+ok "fool" !~ /foo/;
+is $count, 2;
+
+my $rx = qr/bar/;
+
+ok "bar"  =~ $rx;
+is $count, 3;
+ok "foo"  !~ $rx;
+is $count, 4;