summaryrefslogtreecommitdiff
path: root/t/op/whereis.t
diff options
context:
space:
mode:
authorZefram <zefram@fysh.org>2017-12-17 11:02:23 +0000
committerZefram <zefram@fysh.org>2017-12-17 11:02:23 +0000
commitda4e040f42421764ef069371d77c008e6b801f45 (patch)
treedad219b9c5a660c14705b6544fab2b3572bc2bd9 /t/op/whereis.t
parentb2cd5cb1d8b3c8a7a7f033784d5134d2fbd8cad8 (diff)
parentd6374f3d794e2a640258023e92e8d922409215ec (diff)
downloadperl-da4e040f42421764ef069371d77c008e6b801f45.tar.gz
merge branch zefram/dumb_match
Diffstat (limited to 't/op/whereis.t')
-rw-r--r--t/op/whereis.t78
1 files changed, 78 insertions, 0 deletions
diff --git a/t/op/whereis.t b/t/op/whereis.t
new file mode 100644
index 0000000000..522e7d8661
--- /dev/null
+++ b/t/op/whereis.t
@@ -0,0 +1,78 @@
+#!./perl
+
+BEGIN {
+ chdir 't' if -d 't';
+ require './test.pl';
+ set_up_inc('../lib');
+}
+use strict;
+use warnings;
+no warnings qw(uninitialized experimental::smartmatch);
+
+plan tests => 19;
+
+foreach(3) {
+ CORE::whereis(qr/\A3\z/) {
+ pass "CORE::whereis without feature flag";
+ }
+}
+
+use feature 'switch';
+
+foreach(3) {
+ CORE::whereis(qr/\A3\z/) {
+ pass "CORE::whereis with feature flag";
+ }
+}
+
+foreach(3) {
+ whereis(qr/\A3\z/) {
+ pass "whereis with feature flag";
+ }
+}
+
+package MatchAbc { use overload "~~" => sub { $_[1] eq "abc" }, fallback => 1; }
+my $matchabc = bless({}, "MatchAbc");
+my $regexpabc = qr/\Aabc\z/;
+
+foreach("abc") {
+ my $x = "foo";
+ is($x, "foo", "whereis lexical scope not started yet");
+ whereis(my $x = $matchabc) {
+ is($x, $matchabc, "whereis lexical scope starts");
+ }
+ is($x, "foo", "whereis lexical scope ends");
+}
+
+foreach my $matcher (undef, 0, 1, [], {}, sub { 1 }) {
+ my $res = eval {
+ my $r;
+ foreach("abc") {
+ whereis($matcher) {
+ $r = 1;
+ }
+ $r = 0;
+ }
+ $r;
+ };
+ like $@, qr/\ACannot smart match without a matcher object /;
+}
+
+foreach my $matcher ($matchabc, $regexpabc) {
+ foreach my $matchee (qw(abc xyz)) {
+ my $res = eval {
+ my $r;
+ foreach($matchee) {
+ whereis($matcher) {
+ $r = 1;
+ }
+ $r = 0;
+ }
+ $r;
+ };
+ is $@, "";
+ is !!$res, $matchee eq "abc";
+ }
+}
+
+1;