move pod tests to xt
[gitmo/Algorithm-C3.git] / t / 002_merge.t
CommitLineData
c0b91998 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 7;
7
8BEGIN {
9 use_ok('Algorithm::C3');
10}
11
12=pod
13
14This example is take from: http://www.python.org/2.3/mro.html
15
16"My first example"
17class O: pass
18class F(O): pass
19class E(O): pass
20class D(O): pass
21class C(D,F): pass
22class B(D,E): pass
23class A(B,C): pass
24
25
26 6
27 ---
28Level 3 | O | (more general)
29 / --- \
30 / | \ |
31 / | \ |
32 / | \ |
33 --- --- --- |
34Level 2 3 | D | 4| E | | F | 5 |
35 --- --- --- |
36 \ \ _ / | |
37 \ / \ _ | |
38 \ / \ | |
39 --- --- |
40Level 1 1 | B | | C | 2 |
41 --- --- |
42 \ / |
43 \ / \ /
44 ---
45Level 0 0 | A | (more specialized)
46 ---
47
48=cut
49
50{
51 package Test::O;
52
53 sub supers {
54 no strict 'refs';
55 @{$_[0] . '::ISA'};
56 }
57
58 package Test::F;
59 use base 'Test::O';
60
61 package Test::E;
62 use base 'Test::O';
63
64 package Test::D;
65 use base 'Test::O';
66
67 package Test::C;
68 use base ('Test::D', 'Test::F');
69
70 package Test::B;
71 use base ('Test::D', 'Test::E');
72
73 package Test::A;
74 use base ('Test::B', 'Test::C');
75}
76
77is_deeply(
78 [ Algorithm::C3::merge('Test::F', 'supers') ],
79 [ qw(Test::F Test::O) ],
80 '... got the right C3 merge order for Test::F');
81
82is_deeply(
83 [ Algorithm::C3::merge('Test::E', 'supers') ],
84 [ qw(Test::E Test::O) ],
85 '... got the right C3 merge order for Test::E');
86
87is_deeply(
88 [ Algorithm::C3::merge('Test::D', 'supers') ],
89 [ qw(Test::D Test::O) ],
90 '... got the right C3 merge order for Test::D');
91
92is_deeply(
93 [ Algorithm::C3::merge('Test::C', 'supers') ],
94 [ qw(Test::C Test::D Test::F Test::O) ],
95 '... got the right C3 merge order for Test::C');
96
97is_deeply(
98 [ Algorithm::C3::merge('Test::B', 'supers') ],
99 [ qw(Test::B Test::D Test::E Test::O) ],
100 '... got the right C3 merge order for Test::B');
101
102is_deeply(
103 [ Algorithm::C3::merge('Test::A', 'supers') ],
104 [ qw(Test::A Test::B Test::C Test::D Test::E Test::F Test::O) ],
105 '... got the right C3 merge order for Test::A');
106
107