refactor fetcher and add a test for 100% coverage
[gitmo/Algorithm-C3.git] / t / 001_merge.t
CommitLineData
c0b91998 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
aeed4a60 6use Test::More tests => 5;
c0b91998 7
8BEGIN {
9 use_ok('Algorithm::C3');
10}
11
12{
13 package My::A;
14 package My::C;
15 our @ISA = ('My::A');
16 package My::B;
17 our @ISA = ('My::A');
18 package My::D;
19 our @ISA = ('My::B', 'My::C');
20}
21
22{
23 my @merged = Algorithm::C3::merge(
24 'My::D',
25 sub {
26 no strict 'refs';
27 @{$_[0] . '::ISA'};
28 }
29 );
30
31 is_deeply(
32 \@merged,
33 [ qw/My::D My::B My::C My::A/ ],
34 '... merged the lists correctly');
35}
36
37{
38 package My::E;
39
40 sub supers {
41 no strict 'refs';
42 @{$_[0] . '::ISA'};
43 }
44
45 package My::F;
46 our @ISA = ('My::E');
47 package My::G;
48 our @ISA = ('My::E');
49 package My::H;
aeed4a60 50 our @ISA = ('My::G', 'My::F');
51 sub method_exists_only_in_H { @ISA }
c0b91998 52}
53
54{
55 my @merged = Algorithm::C3::merge('My::H', 'supers');
56
57 is_deeply(
58 \@merged,
59 [ qw/My::H My::G My::F My::E/ ],
60 '... merged the lists correctly');
61}
62
63eval {
64 Algorithm::C3::merge(
65 'My::H',
66 'this_method_does_not_exist'
67 );
68};
69ok($@, '... this died as we expected');
70
aeed4a60 71eval {
72 Algorithm::C3::merge(
73 'My::H',
74 'method_exists_only_in_H'
75 );
76};
77ok($@, '... this died as we expected');