Commit | Line | Data |
c0b91998 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More tests => 4; |
7 | |
8 | BEGIN { |
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; |
50 | our @ISA = ('My::G', 'My::F'); |
51 | } |
52 | |
53 | { |
54 | my @merged = Algorithm::C3::merge('My::H', 'supers'); |
55 | |
56 | is_deeply( |
57 | \@merged, |
58 | [ qw/My::H My::G My::F My::E/ ], |
59 | '... merged the lists correctly'); |
60 | } |
61 | |
62 | eval { |
63 | Algorithm::C3::merge( |
64 | 'My::H', |
65 | 'this_method_does_not_exist' |
66 | ); |
67 | }; |
68 | ok($@, '... this died as we expected'); |
69 | |
70 | |