remove extraneous garbage from tests
[gitmo/Class-C3.git] / t / 21_C3_with_overload.t
CommitLineData
680100b1 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
ef29cd70 6use Test::More tests => 8;
680100b1 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;
030b48e2 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
680100b1 43}
44
2ffffc6d 45Class::C3::initialize();
46
680100b1 47my $x = InheritingFromOverloadedTest->new();
48isa_ok($x, 'InheritingFromOverloadedTest');
49
50my $y = OverloadingTest->new();
51isa_ok($y, 'OverloadingTest');
52
53is("$x", 'InheritingFromOverloadedTest stringified', '... got the right value when stringifing');
54is("$y", 'OverloadingTest stringified', '... got the right value when stringifing');
55
56ok(($y eq 'OverloadingTest stringified'), '... eq was handled correctly');
57
58my $result;
59eval {
60 $result = $x eq 'InheritingFromOverloadedTest stringified'
61};
62ok(!$@, '... this should not throw an exception');
63ok($result, '... and we should get the true value');
64
030b48e2 65eval {
66 my $obj = bless {}, 'OverloadInheritTwo';
67};
68is($@, '', "Overloading to method name string");
69
680100b1 70#use Data::Dumper;
71#diag Dumper { Class::C3::_dump_MRO_table }