Clear up test based on line number differences between the core and the
[p5sagit/p5-mst-13.2.git] / lib / Test / Simple / t / overload.t
1 #!/usr/bin/perl -w
2
3 BEGIN {
4     if( $ENV{PERL_CORE} ) {
5         chdir 't';
6         @INC = ('../lib', 'lib');
7     }
8     else {
9         unshift @INC, 't/lib';
10     }
11 }
12
13 use strict;
14 use Test::More;
15
16 BEGIN {
17     if( !eval "require overload" ) {
18         plan skip_all => "needs overload.pm";
19     }
20     else {
21         plan tests => 13;
22     }
23 }
24
25
26 package Overloaded;
27
28 use overload
29         q{""}    => sub { $_[0]->{string} },
30         q{0+}    => sub { $_[0]->{num} };
31
32 sub new {
33     my $class = shift;
34     bless { string => shift, num => shift }, $class;
35 }
36
37
38 package main;
39
40 my $obj = Overloaded->new('foo', 42);
41 isa_ok $obj, 'Overloaded';
42
43 is $obj, 'foo',            'is() with string overloading';
44 cmp_ok $obj, 'eq', 'foo',  'cmp_ok() ...';
45 cmp_ok $obj, '==', 42,     'cmp_ok() with number overloading';
46
47 is_deeply [$obj], ['foo'],                 'is_deeply with string overloading';
48 ok eq_array([$obj], ['foo']),              'eq_array ...';
49 ok eq_hash({foo => $obj}, {foo => 'foo'}), 'eq_hash ...';
50
51 # rt.cpan.org 13506
52 is_deeply $obj, 'foo',        'is_deeply with string overloading at the top';
53
54 Test::More->builder->is_num($obj, 42);
55 Test::More->builder->is_eq ($obj, "foo");
56
57
58 {
59     # rt.cpan.org 14675
60     package TestPackage;
61     use overload q{""} => sub { ::fail("This should not be called") };
62
63     package Foo;
64     ::is_deeply(['TestPackage'], ['TestPackage']);
65     ::is_deeply({'TestPackage' => 'TestPackage'}, 
66                 {'TestPackage' => 'TestPackage'});
67     ::is_deeply('TestPackage', 'TestPackage');
68 }