File: 10_oo.t

package info (click to toggle)
libconfig-merge-perl 1.01-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 440 kB
  • ctags: 36
  • sloc: perl: 804; makefile: 2
file content (136 lines) | stat: -rw-r--r-- 3,744 bytes parent folder | download | duplicates (4)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
use strict;
use warnings FATAL => 'all', NONFATAL => 'redefine';

use File::Spec;
use Test::More 'tests' => 30;

BEGIN { use_ok('Config::Merge'); }

my $config;
ok(         $config = Config::Merge->new( get_path('empty') ),
            'OO - Load empty dir' );

ok(         $config = Config::Merge->new( get_path('perl') ),
            'OO - Load perl dir' );

is(         $config->C('global.domain'),
            'www.test.com',
            'OO - Simple lookup' );

is(         $config->('global.domain'),
            'www.test.com',
            'OO - Overload lookup' );

is_deeply(  scalar $config->C('global.db.hosts.session'),
            [qw(host1 host2 host3)],
            'OO - Array ref lookup' );

is_deeply(  [ $config->C('global.db.hosts.session') ],
            [qw(host1 host2 host3)],
            'OO - Array lookup' );

is(         $config->C('global.db.hosts.image.1'),
            'host5',
            'OO - Array element lookup' );

ok(         $config = Config::Merge->new( get_path('perlmulti') ),
            'OO - Load perl dir' );

my @list;
ok(         @list = $config->C('global.testsub'),
            'OO - Retrieve code');
is(         scalar @list,
            1,
            'OO - CODE ref list context');

is(         ref $list[0],
            'CODE',
            'OO - CODE ref');

is(         ref scalar $config->C('global.testsub'),
            'CODE',
            'OO - CODE ref scalar context');

ok(         @list = $config->C('global.testregex'),
            'OO - Retrieve regepx');
is(         scalar @list,
            1,
            'OO - Regexp ref list context');

is(         ref $list[0],
            'Regexp',
            'OO - Regexp ref');

is(         ref scalar $config->C('global.testregex'),
            'Regexp',
            'OO - Regexp ref scalar context');

ok(         @list = $config->C('global.testobj'),
            'OO - Retrieve object');
is(         scalar @list,
            1,
            'OO - Object list context');

is(         ref $list[0],
            'ABC',
            'OO - Object ref');

is(         ref scalar $config->C('global.testobj'),
            'ABC',
            'OO - Object scalar context');

is(         $config->C('global.db.hosts.image.1'),
            'host5',
            'OO - Directory lookup' );

is(         $config->C('global.db.hosts.image.1'),
            'host5',
            'OO - Directory lookup' );

is(         defined eval{$config->C('global.db3.hosts.image.1')} ? 1 : 0,
            0,
            'OO - Directory lookup - fail overwritten' );

is(         $config->C('global.db3.different'),
            'data',
            'OO - Directory lookup - succeed overwritten' );

is(         $config->C('global.engine'),
            'Oracle',
            'OO - Local override' );

is(         $config->C('global.db2.hosts.session.0'),
            'local1',
            'OO - Local override deep' );

$config->clear_cache();
my $data = $config->C('global.db.hosts');
$data->{session} = '123';
is(         $config->C('global.db.hosts.session'),
            '123',
            'OO - Overwrite original' );

$data = $config->clone('global.db.hosts');
$data->{image} = '123';
isnt(       $config->C('global.db.hosts.image'),
            '123',
            'OO - Overwrite clone' );

$config->load_config();
isnt(       $config->C('global.db.hosts.session'),
            '123',
            'OO - Reload data' );


#===================================
sub get_path {
#===================================
    my ($vol,$path) = File::Spec->splitpath(
                   File::Spec->rel2abs($0)
            );
    $path = File::Spec->catdir(
        File::Spec->splitdir($path),
        'data',@_
    );
    return File::Spec->catpath($vol,$path,'');
}