forked from bobtfish/perl-smartmatch-tests
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Tests where the right-hand side of ~~ is an array or arrayref. | ||
use strict; | ||
use warnings; | ||
use 5.010001; | ||
use Test::More 'no_plan'; | ||
|
||
ok( | ||
{ a => 1, b => 2 } ~~ [ qw(a b) ], | ||
"{ a => 1, b => 2 } ~~ [ qw(a b) ]", | ||
); | ||
|
||
# make sure that we don't care if the key appears many times in rhs | ||
ok( | ||
{ a => 1, b => 2 } ~~ [ qw(a a a b) ], | ||
"{ a => 1, b => 2 } ~~ [ qw(a a a b) ]", | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Tests where the right-hand side of ~~ is an hash or hashref. | ||
use strict; | ||
use warnings; | ||
use 5.010001; | ||
use Test::More 'no_plan'; | ||
|
||
use Tie::RefHash; | ||
|
||
{ | ||
package Smartmatch::Thingie; | ||
use overload '""' => sub { 'a' }, fallback => 1; | ||
} | ||
{ | ||
my $x = bless {} => 'Smartmatch::Thingie'; | ||
|
||
{ | ||
my $ok = eval { my $sm = $x ~~ $x; 1 }; | ||
my $err = $@; | ||
like($err, qr{non-overloaded object}, "can't ~~ two non-OL objects"); | ||
} | ||
|
||
{ | ||
tie my %h, 'Tie::RefHash'; | ||
$h{ $x } = 0; | ||
|
||
my ($key) = keys %h; | ||
isa_ok($key, 'Smartmatch::Thingie'); # key is still an obj | ||
|
||
my $ok = eval { my $sm = %h ~~ %h; 1 }; | ||
my $err = $@; | ||
ok(!$ok, q{can't %h~~%h if keys include non-OL objects}); | ||
like($err, qr{non-overloaded object}, "can't %h~~%h with non-OL obj keys"); | ||
} | ||
} |