remove extraneous garbage from tests
[gitmo/Class-C3.git] / t / 01_MRO.t
CommitLineData
95bebf8c 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
ef29cd70 6use Test::More tests => 10;
95bebf8c 7
d401eda1 8=pod
9
10This tests the classic diamond inheritence pattern.
11
12 <A>
13 / \
14<B> <C>
15 \ /
16 <D>
17
18=cut
19
95bebf8c 20{
21 package Diamond_A;
22 use Class::C3;
23 sub hello { 'Diamond_A::hello' }
24}
25{
26 package Diamond_B;
27 use base 'Diamond_A';
28 use Class::C3;
29}
30{
31 package Diamond_C;
32 use Class::C3;
33 use base 'Diamond_A';
34
35 sub hello { 'Diamond_C::hello' }
36}
37{
38 package Diamond_D;
39 use base ('Diamond_B', 'Diamond_C');
40 use Class::C3;
41}
42
2ffffc6d 43Class::C3::initialize();
44
45
95bebf8c 46is_deeply(
47 [ Class::C3::calculateMRO('Diamond_D') ],
48 [ qw(Diamond_D Diamond_B Diamond_C Diamond_A) ],
49 '... got the right MRO for Diamond_D');
50
51is(Diamond_D->hello, 'Diamond_C::hello', '... method resolved itself as expected');
d0e2efe5 52
95bebf8c 53is(Diamond_D->can('hello')->(), 'Diamond_C::hello', '... can(method) resolved itself as expected');
d0e2efe5 54is(UNIVERSAL::can("Diamond_D", 'hello')->(), 'Diamond_C::hello', '... can(method) resolved itself as expected');
55
56# now undo the C3
57Class::C3::uninitialize();
58
59is(Diamond_D->hello, 'Diamond_A::hello', '... old method resolution has been restored');
60
61is(Diamond_D->can('hello')->(), 'Diamond_A::hello', '... can(method) resolution has been restored');
62is(UNIVERSAL::can("Diamond_D", 'hello')->(), 'Diamond_A::hello', '... can(method) resolution has been restored');
63
64Class::C3::initialize();
65
66is(Diamond_D->hello, 'Diamond_C::hello', '... C3 method restored itself as expected');
95bebf8c 67
d0e2efe5 68is(Diamond_D->can('hello')->(), 'Diamond_C::hello', '... C3 can(method) restored itself as expected');
69is(UNIVERSAL::can("Diamond_D", 'hello')->(), 'Diamond_C::hello', '... C3 can(method) restored itself as expected');