From: Graham Knop Date: Mon, 24 Feb 2014 04:12:42 +0000 (-0500) Subject: more thorough testing that overloads aren't overwritten X-Git-Tag: v1.003003~15 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c7260eec76c091b9d1107f5db54836634f87d88b;p=gitmo%2FRole-Tiny.git more thorough testing that overloads aren't overwritten --- diff --git a/t/overload.t b/t/overload.t index 41ab0c7..f4ce266 100644 --- a/t/overload.t +++ b/t/overload.t @@ -11,7 +11,7 @@ BEGIN { use overload '""' => \&as_string, '0+' => 'as_num', - bool => sub(){1}, + bool => sub(){0}, fallback => 1; } @@ -24,19 +24,30 @@ BEGIN { BEGIN { package MyClass2; - use overload fallback => 0; + use overload + fallback => 0, + '""' => 'class_string', + '0+' => sub { 42 }, + ; use Role::Tiny::With; with 'MyRole'; sub new { bless {}, shift } + sub class_string { 'yarp' } } -my $o = MyClass->new; -is "$o", 'welp', 'subref overload'; -is 0+$o, 219, 'method name overload'; -ok !!$o, 'anon subref overload'; +{ + my $o = MyClass->new; + is "$o", 'welp', 'subref overload'; + is sprintf('%d', $o), 219, 'method name overload'; + ok !$o, 'anon subref overload'; +} -my $o2 = MyClass2->new; -eval { my $f = 0+$o2 }; -like $@, qr/no method found/, 'fallback value not overwritten'; +{ + my $o = MyClass2->new; + eval { my $f = 0+$o }; + like $@, qr/no method found/, 'fallback value not overwritten'; + is "$o", 'yarp', 'method name overload not overwritten'; + is sprintf('%d', $o), 42, 'subref overload not overwritten'; +} done_testing;