remove extraneous garbage from tests
[gitmo/Class-C3.git] / t / 21_C3_with_overload.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 8;
7
8 {
9     package BaseTest;
10     use strict;
11     use warnings;
12     use Class::C3;
13     
14     package OverloadingTest;
15     use strict;
16     use warnings;
17     use Class::C3;
18     use base 'BaseTest';        
19     use overload '""' => sub { ref(shift) . " stringified" },
20                  fallback => 1;
21     
22     sub new { bless {} => shift }    
23     
24     package InheritingFromOverloadedTest;
25     use strict;
26     use warnings;
27     use base 'OverloadingTest';
28     use Class::C3;
29
30     package BaseTwo;
31     use overload (
32         q{fallback} => 1,
33         q{""}       => 'str', ### character
34     );
35     sub str {
36         return 'BaseTwo str';
37     }
38
39     package OverloadInheritTwo;
40     use Class::C3;
41     use base qw/BaseTwo/;
42
43 }
44
45 Class::C3::initialize();
46
47 my $x = InheritingFromOverloadedTest->new();
48 isa_ok($x, 'InheritingFromOverloadedTest');
49
50 my $y = OverloadingTest->new();
51 isa_ok($y, 'OverloadingTest');
52
53 is("$x", 'InheritingFromOverloadedTest stringified', '... got the right value when stringifing');
54 is("$y", 'OverloadingTest stringified', '... got the right value when stringifing');
55
56 ok(($y eq 'OverloadingTest stringified'), '... eq was handled correctly');
57
58 my $result;
59 eval { 
60     $result = $x eq 'InheritingFromOverloadedTest stringified' 
61 };
62 ok(!$@, '... this should not throw an exception');
63 ok($result, '... and we should get the true value');
64
65 eval {
66     my $obj = bless {}, 'OverloadInheritTwo';
67 };
68 is($@, '', "Overloading to method name string");
69
70 #use Data::Dumper;
71 #diag Dumper { Class::C3::_dump_MRO_table }