avoid needing . in @INC in dev mode
[gitmo/Algorithm-C3.git] / t / 008_cached_merge_unordered.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 12;
7
8 BEGIN {
9     use_ok('Algorithm::C3');
10 }
11
12 =pod
13
14 Just like 007_cached_merge, but test the MROs in some wierd order, rather
15 than alphabetical order.
16
17 This example is taken from: http://rt.cpan.org/Public/Bug/Display.html?id=20879
18
19                ---     ---     ---
20 Level 5     8 | A | 9 | B | A | C |    (More General)
21                ---     ---     ---       V
22                   \     |     /          |
23                    \    |    /           |
24                     \   |   /            |
25                      \  |  /             |
26                        ---               |
27 Level 4             7 | D |              |
28                        ---               |
29                       /   \              |
30                      /     \             |
31                   ---       ---          |
32 Level 3        4 | G |   6 | E |         |
33                   ---       ---          |
34                    |         |           |
35                    |         |           |
36                   ---       ---          |
37 Level 2        3 | H |   5 | F |         |
38                   ---       ---          |
39                       \   /  |           |
40                        \ /   |           |
41                         \    |           |
42                        / \   |           |
43                       /   \  |           |
44                   ---       ---          |
45 Level 1        1 | J |   2 | I |         |
46                   ---       ---          |
47                     \       /            |
48                      \     /             |
49                        ---               v
50 Level 0             0 | K |            (More Specialized)
51                        ---
52
53
54 0123456789A
55 KJIHGFEDABC
56
57 =cut
58
59 {
60     package Test::A;
61     sub x { 1 }
62
63     package Test::B;
64     sub x { 1 }
65
66     package Test::C;
67     sub x { 1 }
68
69     package Test::D;
70     use base qw/Test::A Test::B Test::C/;
71
72     package Test::E;
73     use base qw/Test::D/;
74
75     package Test::F;
76     use base qw/Test::E/;
77
78     package Test::G;
79     use base qw/Test::D/;
80
81     package Test::H;
82     use base qw/Test::G/;
83
84     package Test::I;
85     use base qw/Test::H Test::F/;
86
87     package Test::J;
88     use base qw/Test::F/;
89
90     package Test::K;
91     use base qw/Test::J Test::I/;
92 }
93
94 sub supers {
95     no strict 'refs';
96     @{$_[0] . '::ISA'};
97 }
98
99 my %cache;
100
101 is_deeply(
102     [ Algorithm::C3::merge('Test::J', \&supers, \%cache) ],
103     [ qw(Test::J Test::F Test::E Test::D Test::A Test::B Test::C) ],
104     '... got the right C3 merge order for Test::J');
105
106 is_deeply(
107     [ Algorithm::C3::merge('Test::G', \&supers, \%cache) ],
108     [ qw(Test::G Test::D Test::A Test::B Test::C) ],
109     '... got the right C3 merge order for Test::G');
110
111 is_deeply(
112     [ Algorithm::C3::merge('Test::B', \&supers, \%cache) ],
113     [ qw(Test::B) ],
114     '... got the right C3 merge order for Test::B');
115
116 is_deeply(
117     [ Algorithm::C3::merge('Test::D', \&supers, \%cache) ],
118     [ qw(Test::D Test::A Test::B Test::C) ],
119     '... got the right C3 merge order for Test::D');
120
121 is_deeply(
122     [ Algorithm::C3::merge('Test::C', \&supers, \%cache) ],
123     [ qw(Test::C) ],
124     '... got the right C3 merge order for Test::C');
125
126 is_deeply(
127     [ Algorithm::C3::merge('Test::I', \&supers, \%cache) ],
128     [ qw(Test::I Test::H Test::G Test::F Test::E Test::D Test::A Test::B Test::C) ],
129     '... got the right C3 merge order for Test::I');
130
131 is_deeply(
132     [ Algorithm::C3::merge('Test::K', \&supers, \%cache) ],
133     [ qw(Test::K Test::J Test::I Test::H Test::G Test::F Test::E Test::D Test::A Test::B Test::C) ],
134     '... got the right C3 merge order for Test::K');
135
136 is_deeply(
137     [ Algorithm::C3::merge('Test::E', \&supers, \%cache) ],
138     [ qw(Test::E Test::D Test::A Test::B Test::C) ],
139     '... got the right C3 merge order for Test::E');
140
141 is_deeply(
142     [ Algorithm::C3::merge('Test::F', \&supers, \%cache) ],
143     [ qw(Test::F Test::E Test::D Test::A Test::B Test::C) ],
144     '... got the right C3 merge order for Test::F');
145
146 is_deeply(
147     [ Algorithm::C3::merge('Test::A', \&supers, \%cache) ],
148     [ qw(Test::A) ],
149     '... got the right C3 merge order for Test::A');
150
151 is_deeply(
152     [ Algorithm::C3::merge('Test::H', \&supers, \%cache) ],
153     [ qw(Test::H Test::G Test::D Test::A Test::B Test::C) ],
154     '... got the right C3 merge order for Test::H');
155