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';
15 use Test::More tests => 15;
21 q{eq} => sub { $_[0]->{string} },
22 q{==} => sub { $_[0]->{num} },
23 q{""} => sub { $_[0]->{stringfy}++; $_[0]->{string} },
24 q{0+} => sub { $_[0]->{numify}++; $_[0]->{num} }
40 local $SIG{__DIE__} = sub {
41 my($call_file, $call_line) = (caller)[1,2];
42 fail("SIGDIE accidentally called");
43 diag("From $call_file at $call_line");
46 my $obj = Overloaded->new('foo', 42);
47 isa_ok $obj, 'Overloaded';
49 is $obj, 'foo', 'is() with string overloading';
50 cmp_ok $obj, 'eq', 'foo', 'cmp_ok() ...';
51 is $obj->{stringify}, 0, 'cmp_ok() eq does not stringify';
52 cmp_ok $obj, '==', 42, 'cmp_ok() with number overloading';
53 is $obj->{numify}, 0, 'cmp_ok() == does not numify';
55 is_deeply [$obj], ['foo'], 'is_deeply with string overloading';
56 ok eq_array([$obj], ['foo']), 'eq_array ...';
57 ok eq_hash({foo => $obj}, {foo => 'foo'}), 'eq_hash ...';
60 is_deeply $obj, 'foo', 'is_deeply with string overloading at the top';
62 Test::More->builder->is_num($obj, 42);
63 Test::More->builder->is_eq ($obj, "foo");
69 use overload q{""} => sub { ::fail("This should not be called") };
72 ::is_deeply(['TestPackage'], ['TestPackage']);
73 ::is_deeply({'TestPackage' => 'TestPackage'},
74 {'TestPackage' => 'TestPackage'});
75 ::is_deeply('TestPackage', 'TestPackage');