Small optimisations, by Brandon Black
[p5sagit/p5-mst-13.2.git] / t / mro / complex_c3.t
CommitLineData
e1a479c5 1#!./perl
2
3use strict;
4use warnings;
5BEGIN {
6 unless (-d 'blib') {
7 chdir 't' if -d 't';
8 @INC = '../lib';
9 }
10}
11
12use Test::More tests => 12;
13
14=pod
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; use mro 'c3';
60
61 package Test::B; use mro 'c3';
62
63 package Test::C; use mro 'c3';
64
65 package Test::D; use mro 'c3';
66 use base qw/Test::A Test::B Test::C/;
67
68 package Test::E; use mro 'c3';
69 use base qw/Test::D/;
70
71 package Test::F; use mro 'c3';
72 use base qw/Test::E/;
73 sub testmeth { "wrong" }
74
75 package Test::G; use mro 'c3';
76 use base qw/Test::D/;
77
78 package Test::H; use mro 'c3';
79 use base qw/Test::G/;
80
81 package Test::I; use mro 'c3';
82 use base qw/Test::H Test::F/;
83 sub testmeth { "right" }
84
85 package Test::J; use mro 'c3';
86 use base qw/Test::F/;
87
88 package Test::K; use mro 'c3';
89 use base qw/Test::J Test::I/;
90 sub testmeth { shift->next::method }
91}
92
93is_deeply(
94 mro::get_linear_isa('Test::A'),
95 [ qw(Test::A) ],
96 '... got the right C3 merge order for Test::A');
97
98is_deeply(
99 mro::get_linear_isa('Test::B'),
100 [ qw(Test::B) ],
101 '... got the right C3 merge order for Test::B');
102
103is_deeply(
104 mro::get_linear_isa('Test::C'),
105 [ qw(Test::C) ],
106 '... got the right C3 merge order for Test::C');
107
108is_deeply(
109 mro::get_linear_isa('Test::D'),
110 [ qw(Test::D Test::A Test::B Test::C) ],
111 '... got the right C3 merge order for Test::D');
112
113is_deeply(
114 mro::get_linear_isa('Test::E'),
115 [ qw(Test::E Test::D Test::A Test::B Test::C) ],
116 '... got the right C3 merge order for Test::E');
117
118is_deeply(
119 mro::get_linear_isa('Test::F'),
120 [ qw(Test::F Test::E Test::D Test::A Test::B Test::C) ],
121 '... got the right C3 merge order for Test::F');
122
123is_deeply(
124 mro::get_linear_isa('Test::G'),
125 [ qw(Test::G Test::D Test::A Test::B Test::C) ],
126 '... got the right C3 merge order for Test::G');
127
128is_deeply(
129 mro::get_linear_isa('Test::H'),
130 [ qw(Test::H Test::G Test::D Test::A Test::B Test::C) ],
131 '... got the right C3 merge order for Test::H');
132
133is_deeply(
134 mro::get_linear_isa('Test::I'),
135 [ qw(Test::I Test::H Test::G Test::F Test::E Test::D Test::A Test::B Test::C) ],
136 '... got the right C3 merge order for Test::I');
137
138is_deeply(
139 mro::get_linear_isa('Test::J'),
140 [ qw(Test::J Test::F Test::E Test::D Test::A Test::B Test::C) ],
141 '... got the right C3 merge order for Test::J');
142
143is_deeply(
144 mro::get_linear_isa('Test::K'),
145 [ qw(Test::K Test::J Test::I Test::H Test::G Test::F Test::E Test::D Test::A Test::B Test::C) ],
146 '... got the right C3 merge order for Test::K');
147
148is(Test::K->testmeth(), "right", 'next::method working ok');