remove extraneous garbage from tests
[gitmo/Class-C3.git] / t / 31_next_method_skip.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 10;
7
8 =pod
9
10 This 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;
22     use Class::C3; 
23     sub bar { 'Diamond_A::bar' }        
24     sub baz { 'Diamond_A::baz' }
25 }
26 {
27     package Diamond_B;
28     use base 'Diamond_A';
29     use Class::C3;    
30     sub baz { 'Diamond_B::baz => ' . (shift)->next::method() }         
31 }
32 {
33     package Diamond_C;
34     use Class::C3;    
35     use base 'Diamond_A';     
36     sub foo { 'Diamond_C::foo' }   
37     sub buz { 'Diamond_C::buz' }     
38     
39     sub woz { 'Diamond_C::woz' }
40     sub maybe { 'Diamond_C::maybe' }         
41 }
42 {
43     package Diamond_D;
44     use base ('Diamond_B', 'Diamond_C');
45     use Class::C3; 
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() }  
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) }             
56
57 }
58
59 Class::C3::initialize();
60
61 is_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
66 is(Diamond_D->foo, 'Diamond_D::foo => Diamond_C::foo', '... skipped B and went to C correctly');
67 is(Diamond_D->bar, 'Diamond_D::bar => Diamond_A::bar', '... skipped B & C and went to A correctly');
68 is(Diamond_D->baz, 'Diamond_B::baz => Diamond_A::baz', '... called B method, skipped C and went to A correctly');
69 is(Diamond_D->buz, 'Diamond_D::buz => Diamond_B::baz => Diamond_A::baz', '... called D method dispatched to , different method correctly');
70 eval { Diamond_D->fuz };
71 like($@, qr/^No next::method 'fuz' found for Diamond_D/, '... cannot re-dispatch to a method which is not there');
72
73 is(Diamond_D->woz, 'Diamond_D::woz can => 1', '... can re-dispatch figured out correctly');
74 is(Diamond_D->noz, 'Diamond_D::noz can => 0', '... cannot re-dispatch figured out correctly');
75
76 is(Diamond_D->maybe, 'Diamond_D::maybe => Diamond_C::maybe', '... redispatched D to C when it exists');
77 is(Diamond_D->moybe, 'Diamond_D::moybe => 0', '... quietly failed redispatch from D');