File: 51-ini.t

package info (click to toggle)
libconfig-any-perl 0.23-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 340 kB
  • sloc: perl: 1,578; xml: 28; makefile: 2
file content (57 lines) | stat: -rw-r--r-- 1,656 bytes parent folder | download | duplicates (3)
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
use strict;
use warnings;

use Test::More;
use Config::Any::INI;

if ( !Config::Any::INI->is_supported ) {
    plan skip_all => 'INI format not supported';
}
else {
    plan tests => 13;
}

{
    my $config = Config::Any::INI->load( 't/conf/conf.ini' );
    ok( $config, 'config loaded' );
    is( $config->{ name }, 'TestApp', "toplevel key lookup succeeded" );
    is( $config->{ Component }->{ 'Controller::Foo' }->{ foo },
        'bar', "nested hashref hack lookup succeeded" );
}

{
    my $config = Config::Any::INI->load( 't/conf/conf2.ini' );
    ok( $config, 'config loaded' );
    is( $config->{ name }, 'TestApp', "toplevel key lookup succeeded" );
    is( $config->{ 'Controller::Foo' }->{ foo },
        'bar', "nested hashref hack lookup succeeded" );
}

{
    local $Config::Any::INI::MAP_SECTION_SPACE_TO_NESTED_KEY = 0;
    my $config = Config::Any::INI->load( 't/conf/conf.ini' );
    ok( $config, 'config loaded (no-map-space mode)' );
    is( $config->{ name }, 'TestApp', "toplevel key lookup succeeded" );
    is( $config->{ 'Component Controller::Foo' }->{ foo },
        'bar', "unnested key lookup succeeded" );
}

{
    my $config = Config::Any::INI->load( 't/conf/subsections.ini' );

    my %expected
        = ( section1 =>
            { a => 1, subsection1 => { b => 2 }, subsection2 => { c => 3 } }
        );
    ok( $config, 'config loaded' );
    is_deeply( $config, \%expected, 'subsections parsed properly' );
}

# test invalid config
{
    my $file = 't/invalid/conf.ini';
    my $config = eval { Config::Any::INI->load( $file ) };

    ok( !$config, 'config load failed' );
    ok( $@,       "error thrown ($@)" );
}