changelog
[p5sagit/Config-Any.git] / t / 51-ini.t
CommitLineData
5a2e0210 1use strict;
2use warnings;
41f47406 3
5a2e0210 4use Test::More;
67a1cd50 5use Config::Any;
41f47406 6use Config::Any::INI;
7
c2a19f63 8if ( !Config::Any::INI->is_supported && !$ENV{RELEASE_TESTING} ) {
5a2e0210 9 plan skip_all => 'INI format not supported';
10}
11else {
67a1cd50 12 plan tests => 15;
5a2e0210 13}
41f47406 14
5a2e0210 15{
16 my $config = Config::Any::INI->load( 't/conf/conf.ini' );
17 ok( $config, 'config loaded' );
41f47406 18 is( $config->{ name }, 'TestApp', "toplevel key lookup succeeded" );
5a2e0210 19 is( $config->{ Component }->{ 'Controller::Foo' }->{ foo },
92a04e78 20 'bar', "nested hashref hack lookup succeeded" );
5a2e0210 21}
92a04e78 22
5a2e0210 23{
24 my $config = Config::Any::INI->load( 't/conf/conf2.ini' );
25 ok( $config, 'config loaded' );
26 is( $config->{ name }, 'TestApp', "toplevel key lookup succeeded" );
27 is( $config->{ 'Controller::Foo' }->{ foo },
92a04e78 28 'bar', "nested hashref hack lookup succeeded" );
41f47406 29}
30
5a2e0210 31{
32 local $Config::Any::INI::MAP_SECTION_SPACE_TO_NESTED_KEY = 0;
33 my $config = Config::Any::INI->load( 't/conf/conf.ini' );
34 ok( $config, 'config loaded (no-map-space mode)' );
35 is( $config->{ name }, 'TestApp', "toplevel key lookup succeeded" );
36 is( $config->{ 'Component Controller::Foo' }->{ foo },
92a04e78 37 'bar', "unnested key lookup succeeded" );
41f47406 38}
5a2e0210 39
40{
41 my $config = Config::Any::INI->load( 't/conf/subsections.ini' );
42
43 my %expected
44 = ( section1 =>
45 { a => 1, subsection1 => { b => 2 }, subsection2 => { c => 3 } }
46 );
47 ok( $config, 'config loaded' );
48 is_deeply( $config, \%expected, 'subsections parsed properly' );
49}
5770ffc0 50
51# test invalid config
52{
77f14cda 53 my $file = 't/invalid/conf.ini';
5770ffc0 54 my $config = eval { Config::Any::INI->load( $file ) };
55
e0186698 56 is $config, undef, 'config load failed';
57 isnt $@, '', 'error thrown';
5770ffc0 58}
67a1cd50 59
60# parse error generated on invalid config
61{
62 my $file = 't/invalid/conf.ini';
63 my $config = eval { Config::Any->load_files( { files => [$file], use_ext => 1} ) };
64
e0186698 65 is $config, undef, 'config load failed';
66 isnt $@, '', 'error thrown';
67a1cd50 67}