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