File: 001_merge.t

package info (click to toggle)
libalgorithm-c3-perl 0.11-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 180 kB
  • sloc: perl: 88; makefile: 2
file content (73 lines) | stat: -rw-r--r-- 1,256 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use strict;
use warnings;

use Test::More tests => 4;

use Algorithm::C3;

{
    package My::A;
    package My::C;
    our @ISA = ('My::A');
    package My::B;
    our @ISA = ('My::A');
    package My::D;
    our @ISA = ('My::B', 'My::C');
}

{
    my @merged = Algorithm::C3::merge(
        'My::D',
        sub {
            no strict 'refs';
            @{$_[0] . '::ISA'};
        }
    );

    is_deeply(
        \@merged,
        [ qw/My::D My::B My::C My::A/ ],
        '... merged the lists correctly');
}

{
    package My::E;

    sub supers {
        no strict 'refs';
        @{$_[0] . '::ISA'};
    }

    package My::F;
    our @ISA = ('My::E');
    package My::G;
    our @ISA = ('My::E');
    package My::H;
    our @ISA = ('My::G', 'My::F');
    sub method_exists_only_in_H { @ISA }
}

{
    my @merged = Algorithm::C3::merge('My::H', 'supers');

    is_deeply(
        \@merged,
        [ qw/My::H My::G My::F My::E/ ],
        '... merged the lists correctly');
}

eval {
    Algorithm::C3::merge(
        'My::H',
        'this_method_does_not_exist'
    );
};
ok($@, '... this died as we expected');

eval {
    Algorithm::C3::merge(
        'My::H',
        'method_exists_only_in_H'
    );
};
ok($@, '... this died as we expected');