remove extraneous garbage from tests
[gitmo/Class-C3.git] / t / 31_next_method_skip.t
CommitLineData
5d5c86d9 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
ef29cd70 6use Test::More tests => 10;
5d5c86d9 7
8=pod
9
10This tests the classic diamond inheritence pattern.
11
12 <A>
13 / \
14<B> <C>
15 \ /
16 <D>
17
18=cut
19
20{
21 package Diamond_A;
ef29cd70 22 use Class::C3;
5d5c86d9 23 sub bar { 'Diamond_A::bar' }
24 sub baz { 'Diamond_A::baz' }
25}
26{
27 package Diamond_B;
28 use base 'Diamond_A';
ef29cd70 29 use Class::C3;
5d5c86d9 30 sub baz { 'Diamond_B::baz => ' . (shift)->next::method() }
31}
32{
33 package Diamond_C;
ef29cd70 34 use Class::C3;
5d5c86d9 35 use base 'Diamond_A';
36 sub foo { 'Diamond_C::foo' }
fa91a1c7 37 sub buz { 'Diamond_C::buz' }
38
39 sub woz { 'Diamond_C::woz' }
40 sub maybe { 'Diamond_C::maybe' }
5d5c86d9 41}
42{
43 package Diamond_D;
44 use base ('Diamond_B', 'Diamond_C');
ef29cd70 45 use Class::C3;
5d5c86d9 46 sub foo { 'Diamond_D::foo => ' . (shift)->next::method() }
47 sub bar { 'Diamond_D::bar => ' . (shift)->next::method() }
48 sub buz { 'Diamond_D::buz => ' . (shift)->baz() }
fa91a1c7 49 sub fuz { 'Diamond_D::fuz => ' . (shift)->next::method() }
50
51 sub woz { 'Diamond_D::woz can => ' . ((shift)->next::can() ? 1 : 0) }
52 sub noz { 'Diamond_D::noz can => ' . ((shift)->next::can() ? 1 : 0) }
53
54 sub maybe { 'Diamond_D::maybe => ' . ((shift)->maybe::next::method() || 0) }
55 sub moybe { 'Diamond_D::moybe => ' . ((shift)->maybe::next::method() || 0) }
5d5c86d9 56
57}
58
2ffffc6d 59Class::C3::initialize();
60
5d5c86d9 61is_deeply(
62 [ Class::C3::calculateMRO('Diamond_D') ],
63 [ qw(Diamond_D Diamond_B Diamond_C Diamond_A) ],
64 '... got the right MRO for Diamond_D');
65
66is(Diamond_D->foo, 'Diamond_D::foo => Diamond_C::foo', '... skipped B and went to C correctly');
67is(Diamond_D->bar, 'Diamond_D::bar => Diamond_A::bar', '... skipped B & C and went to A correctly');
68is(Diamond_D->baz, 'Diamond_B::baz => Diamond_A::baz', '... called B method, skipped C and went to A correctly');
69is(Diamond_D->buz, 'Diamond_D::buz => Diamond_B::baz => Diamond_A::baz', '... called D method dispatched to , different method correctly');
70eval { Diamond_D->fuz };
71like($@, qr/^No next::method 'fuz' found for Diamond_D/, '... cannot re-dispatch to a method which is not there');
72
322a5920 73is(Diamond_D->woz, 'Diamond_D::woz can => 1', '... can re-dispatch figured out correctly');
74is(Diamond_D->noz, 'Diamond_D::noz can => 0', '... cannot re-dispatch figured out correctly');
fa91a1c7 75
76is(Diamond_D->maybe, 'Diamond_D::maybe => Diamond_C::maybe', '... redispatched D to C when it exists');
77is(Diamond_D->moybe, 'Diamond_D::moybe => 0', '... quietly failed redispatch from D');