test tweaks
[gitmo/Class-MOP.git] / t / 107_C3MethodDispatchOrder_test.t
CommitLineData
f3f5bd34 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
d89c0fad 6use Test::More;
f3f5bd34 7use File::Spec;
8
d89c0fad 9BEGIN {
10 eval "use Algorithm::C3";
11 plan skip_all => "Algorithm::C3 required for this test" if $@;
12 plan tests => 5;
13
f3f5bd34 14 use_ok('Class::MOP');
10dd437b 15 require_ok(File::Spec->catfile('examples', 'C3MethodDispatchOrder.pod'));
f3f5bd34 16}
17
18{
19 package Diamond_A;
20 use metaclass 'C3MethodDispatchOrder';
21
22 sub hello { 'Diamond_A::hello' }
23
24 package Diamond_B;
25 use metaclass 'C3MethodDispatchOrder';
26 __PACKAGE__->meta->superclasses('Diamond_A');
27
28 package Diamond_C;
29 use metaclass 'C3MethodDispatchOrder';
30 __PACKAGE__->meta->superclasses('Diamond_A');
31
32 sub hello { 'Diamond_C::hello' }
33
34 package Diamond_D;
35 use metaclass 'C3MethodDispatchOrder';
36 __PACKAGE__->meta->superclasses('Diamond_B', 'Diamond_C');
37}
38
39is_deeply(
40 [ Diamond_D->meta->class_precedence_list ],
41 [ qw(Diamond_D Diamond_B Diamond_C Diamond_A) ],
42 '... got the right MRO for Diamond_D');
43
44is(Diamond_D->hello, 'Diamond_C::hello', '... got the right dispatch order');
45is(Diamond_D->can('hello')->(), 'Diamond_C::hello', '... can(method) resolved itself as expected');
46
47