Skip to content

Commit

Permalink
more tests, including a failure
Browse files Browse the repository at this point in the history
  • Loading branch information
rjbs committed May 14, 2009
1 parent cdb7740 commit 926fdd5
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
16 changes: 16 additions & 0 deletions t/array.t
@@ -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) ]",
);
34 changes: 34 additions & 0 deletions t/hash.t
@@ -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");
}
}

0 comments on commit 926fdd5

Please sign in to comment.