0.10
[gitmo/Class-C3.git] / t / 21_C3_with_overload.t
CommitLineData
680100b1 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 8;
7
8BEGIN {
9 use_ok('Class::C3');
10}
11
12{
13 package BaseTest;
14 use strict;
15 use warnings;
16 use Class::C3;
17
18 package OverloadingTest;
19 use strict;
20 use warnings;
21 use Class::C3;
22 use base 'BaseTest';
23 use overload '""' => sub { ref(shift) . " stringified" },
24 fallback => 1;
25
26 sub new { bless {} => shift }
27
28 package InheritingFromOverloadedTest;
29 use strict;
30 use warnings;
31 use base 'OverloadingTest';
32 use Class::C3;
33}
34
35my $x = InheritingFromOverloadedTest->new();
36isa_ok($x, 'InheritingFromOverloadedTest');
37
38my $y = OverloadingTest->new();
39isa_ok($y, 'OverloadingTest');
40
41is("$x", 'InheritingFromOverloadedTest stringified', '... got the right value when stringifing');
42is("$y", 'OverloadingTest stringified', '... got the right value when stringifing');
43
44ok(($y eq 'OverloadingTest stringified'), '... eq was handled correctly');
45
46my $result;
47eval {
48 $result = $x eq 'InheritingFromOverloadedTest stringified'
49};
50ok(!$@, '... this should not throw an exception');
51ok($result, '... and we should get the true value');
52
53#use Data::Dumper;
54#diag Dumper { Class::C3::_dump_MRO_table }