This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
lex.t: Mangle obscenity (albeit euphemistic)
[perl5.git] / t / mro / complex_c3.t
CommitLineData
e1a479c5
BB
1#!./perl
2
3use strict;
4use warnings;
e1a479c5 5
c94dd5be 6require q(./test.pl); plan(tests => 12);
e1a479c5
BB
7
8=pod
9
10This example is taken from: http://rt.cpan.org/Public/Bug/Display.html?id=20879
11
12 --- --- ---
13Level 5 8 | A | 9 | B | A | C | (More General)
14 --- --- --- V
15 \ | / |
16 \ | / |
17 \ | / |
18 \ | / |
19 --- |
20Level 4 7 | D | |
21 --- |
22 / \ |
23 / \ |
24 --- --- |
25Level 3 4 | G | 6 | E | |
26 --- --- |
27 | | |
28 | | |
29 --- --- |
30Level 2 3 | H | 5 | F | |
31 --- --- |
32 \ / | |
33 \ / | |
34 \ | |
35 / \ | |
36 / \ | |
37 --- --- |
38Level 1 1 | J | 2 | I | |
39 --- --- |
40 \ / |
41 \ / |
42 --- v
43Level 0 0 | K | (More Specialized)
44 ---
45
46
470123456789A
48KJIHGFEDABC
49
50=cut
51
52{
53 package Test::A; use mro 'c3';
54
55 package Test::B; use mro 'c3';
56
57 package Test::C; use mro 'c3';
58
59 package Test::D; use mro 'c3';
60 use base qw/Test::A Test::B Test::C/;
61
62 package Test::E; use mro 'c3';
63 use base qw/Test::D/;
64
65 package Test::F; use mro 'c3';
66 use base qw/Test::E/;
67 sub testmeth { "wrong" }
68
69 package Test::G; use mro 'c3';
70 use base qw/Test::D/;
71
72 package Test::H; use mro 'c3';
73 use base qw/Test::G/;
74
75 package Test::I; use mro 'c3';
76 use base qw/Test::H Test::F/;
77 sub testmeth { "right" }
78
79 package Test::J; use mro 'c3';
80 use base qw/Test::F/;
81
82 package Test::K; use mro 'c3';
83 use base qw/Test::J Test::I/;
84 sub testmeth { shift->next::method }
85}
86
c94dd5be 87ok(eq_array(
e1a479c5 88 mro::get_linear_isa('Test::A'),
c94dd5be
RGS
89 [ qw(Test::A) ]
90), '... got the right C3 merge order for Test::A');
e1a479c5 91
c94dd5be 92ok(eq_array(
e1a479c5 93 mro::get_linear_isa('Test::B'),
c94dd5be
RGS
94 [ qw(Test::B) ]
95), '... got the right C3 merge order for Test::B');
e1a479c5 96
c94dd5be 97ok(eq_array(
e1a479c5 98 mro::get_linear_isa('Test::C'),
c94dd5be
RGS
99 [ qw(Test::C) ]
100), '... got the right C3 merge order for Test::C');
e1a479c5 101
c94dd5be 102ok(eq_array(
e1a479c5 103 mro::get_linear_isa('Test::D'),
c94dd5be
RGS
104 [ qw(Test::D Test::A Test::B Test::C) ]
105), '... got the right C3 merge order for Test::D');
e1a479c5 106
c94dd5be 107ok(eq_array(
e1a479c5 108 mro::get_linear_isa('Test::E'),
c94dd5be
RGS
109 [ qw(Test::E Test::D Test::A Test::B Test::C) ]
110), '... got the right C3 merge order for Test::E');
e1a479c5 111
c94dd5be 112ok(eq_array(
e1a479c5 113 mro::get_linear_isa('Test::F'),
c94dd5be
RGS
114 [ qw(Test::F Test::E Test::D Test::A Test::B Test::C) ]
115), '... got the right C3 merge order for Test::F');
e1a479c5 116
c94dd5be 117ok(eq_array(
e1a479c5 118 mro::get_linear_isa('Test::G'),
c94dd5be
RGS
119 [ qw(Test::G Test::D Test::A Test::B Test::C) ]
120), '... got the right C3 merge order for Test::G');
e1a479c5 121
c94dd5be 122ok(eq_array(
e1a479c5 123 mro::get_linear_isa('Test::H'),
c94dd5be
RGS
124 [ qw(Test::H Test::G Test::D Test::A Test::B Test::C) ]
125), '... got the right C3 merge order for Test::H');
e1a479c5 126
c94dd5be 127ok(eq_array(
e1a479c5 128 mro::get_linear_isa('Test::I'),
c94dd5be
RGS
129 [ qw(Test::I Test::H Test::G Test::F Test::E Test::D Test::A Test::B Test::C) ]
130), '... got the right C3 merge order for Test::I');
e1a479c5 131
c94dd5be 132ok(eq_array(
e1a479c5 133 mro::get_linear_isa('Test::J'),
c94dd5be
RGS
134 [ qw(Test::J Test::F Test::E Test::D Test::A Test::B Test::C) ]
135), '... got the right C3 merge order for Test::J');
e1a479c5 136
c94dd5be 137ok(eq_array(
e1a479c5 138 mro::get_linear_isa('Test::K'),
c94dd5be
RGS
139 [ qw(Test::K Test::J Test::I Test::H Test::G Test::F Test::E Test::D Test::A Test::B Test::C) ]
140), '... got the right C3 merge order for Test::K');
e1a479c5
BB
141
142is(Test::K->testmeth(), "right", 'next::method working ok');