File: 05-include.t

package info (click to toggle)
libconfig-scoped-perl 0.12-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 752 kB
  • ctags: 73
  • sloc: perl: 10,347; makefile: 42
file content (42 lines) | stat: -rw-r--r-- 900 bytes parent folder | download | duplicates (6)
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
# vim: cindent ft=perl

use warnings;
use strict;

use Test::More tests => 5;
use File::Spec;

BEGIN { use_ok('Config::Scoped') }
my $cfg_file = File::Spec->catfile( 't', 'files', 'include.cfg' );

my ( $p, $cfg );
my $text = "%include $cfg_file; foo{}";

isa_ok( $p = Config::Scoped->new( warnings => { perm => 'off' } ),
    'Config::Scoped' );
ok( eval { $cfg = $p->parse( text => $text ) }, 'include test' );

my $expected = {
    'foo' => {
        'scalar' => '1',
        'hash'   => {
            'c' => 'C',
            'a' => 'A',
            'b' => 'B'
        },
        'list' => [ 'a', 'b', 'c', 'd' ]
    }
};
is_deeply( $cfg, $expected, 'datastructure after include' );

$text = <<eot;
{
    %include $cfg_file
}
foo {}
eot

$expected = { foo => {} };

$p = Config::Scoped->new( warnings => { perm => 'off' } );
is_deeply( $p->parse( text => $text ), $expected, 'include in block' );