2 # $Id: /mirror/googlecode/test-more/t/overload.t 57943 2008-08-18T02:09:22.275428Z brooklyn.kid51 $
5 if( $ENV{PERL_CORE} ) {
7 @INC = ('../lib', 'lib');
10 unshift @INC, 't/lib';
18 if( !eval "require overload" ) {
19 plan skip_all => "needs overload.pm";
30 q{""} => sub { $_[0]->{string} },
31 q{0+} => sub { $_[0]->{num} };
35 bless { string => shift, num => shift }, $class;
41 local $SIG{__DIE__} = sub {
42 my($call_file, $call_line) = (caller)[1,2];
43 fail("SIGDIE accidentally called");
44 diag("From $call_file at $call_line");
47 my $obj = Overloaded->new('foo', 42);
48 isa_ok $obj, 'Overloaded';
50 is $obj, 'foo', 'is() with string overloading';
51 cmp_ok $obj, 'eq', 'foo', 'cmp_ok() ...';
52 cmp_ok $obj, '==', 42, 'cmp_ok() with number overloading';
54 is_deeply [$obj], ['foo'], 'is_deeply with string overloading';
55 ok eq_array([$obj], ['foo']), 'eq_array ...';
56 ok eq_hash({foo => $obj}, {foo => 'foo'}), 'eq_hash ...';
59 is_deeply $obj, 'foo', 'is_deeply with string overloading at the top';
61 Test::More->builder->is_num($obj, 42);
62 Test::More->builder->is_eq ($obj, "foo");
68 use overload q{""} => sub { ::fail("This should not be called") };
71 ::is_deeply(['TestPackage'], ['TestPackage']);
72 ::is_deeply({'TestPackage' => 'TestPackage'},
73 {'TestPackage' => 'TestPackage'});
74 ::is_deeply('TestPackage', 'TestPackage');