Add ARM files
[dh-make-perl] / dev / arm / libtest-simple-perl / libtest-simple-perl-0.80 / 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 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");
44 };
45
46 my $obj = Overloaded->new('foo', 42);
47 isa_ok $obj, 'Overloaded';
48
49 is $obj, 'foo',            'is() with string overloading';
50 cmp_ok $obj, 'eq', 'foo',  'cmp_ok() ...';
51 cmp_ok $obj, '==', 42,     'cmp_ok() with number overloading';
52
53 is_deeply [$obj], ['foo'],                 'is_deeply with string overloading';
54 ok eq_array([$obj], ['foo']),              'eq_array ...';
55 ok eq_hash({foo => $obj}, {foo => 'foo'}), 'eq_hash ...';
56
57 # rt.cpan.org 13506
58 is_deeply $obj, 'foo',        'is_deeply with string overloading at the top';
59
60 Test::More->builder->is_num($obj, 42);
61 Test::More->builder->is_eq ($obj, "foo");
62
63
64 {
65     # rt.cpan.org 14675
66     package TestPackage;
67     use overload q{""} => sub { ::fail("This should not be called") };
68
69     package Foo;
70     ::is_deeply(['TestPackage'], ['TestPackage']);
71     ::is_deeply({'TestPackage' => 'TestPackage'}, 
72                 {'TestPackage' => 'TestPackage'});
73     ::is_deeply('TestPackage', 'TestPackage');
74 }