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