From: Rafael Garcia-Suarez Date: Sat, 9 May 2009 13:50:25 +0000 (+0200) Subject: Add a test for object ~~ string, with stringification overload X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=90a32bcb5e6a686bec0d5726c12e209e6c769d92;p=p5sagit%2Fp5-mst-13.2.git Add a test for object ~~ string, with stringification overload --- diff --git a/t/op/smartmatch.t b/t/op/smartmatch.t index fa66de9..3124b7a 100644 --- a/t/op/smartmatch.t +++ b/t/op/smartmatch.t @@ -32,13 +32,14 @@ tie my %tied_hash, 'Tie::StdHash'; } { - package Test::Object::CopyOverload; + package Test::Object::WithOverload; sub new { bless { key => 'magic' } } use overload '~~' => sub { my %hash = %{ $_[0] }; $_[1] eq $hash{key} }; use overload '""' => sub { "stringified" }; + use overload 'eq' => sub {"$_[0]" eq "$_[1]"}; } -our $ov_obj = Test::Object::CopyOverload->new; +our $ov_obj = Test::Object::WithOverload->new; our $obj = Test::Object::NoOverload->new; my @keyandmore = qw(key and more); @@ -170,6 +171,7 @@ __DATA__ # object (overloaded or not) ~~ Any $obj qr/NoOverload/ $ov_obj qr/^stringified$/ + $ov_obj "stringified" # ~~ Coderef sub{0} sub { ref $_[0] eq "CODE" } @@ -204,7 +206,7 @@ __DATA__ ! [1] \&foo ! {a=>1} \&foo $obj sub { ref($_[0]) =~ /NoOverload/ } - $ov_obj sub { ref($_[0]) =~ /CopyOverload/ } + $ov_obj sub { ref($_[0]) =~ /WithOverload/ } # empty stuff matches, because the sub is never called: [] \&foo {} \&foo