X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FConfig-Any.git;a=blobdiff_plain;f=t%2F51-ini.t;h=6848004d51bca8f03aa0b8a3c93d907b85c9b4d1;hp=17b5bcd351d03a57fd2616cc9cf53f649fc358d5;hb=aa7bd7c30e544ebbb418c2a0508523800e790836;hpb=8587679b9219b55bb8189772981387b0cd70b685 diff --git a/t/51-ini.t b/t/51-ini.t index 17b5bcd..6848004 100644 --- a/t/51-ini.t +++ b/t/51-ini.t @@ -1,17 +1,57 @@ -use Test::More tests => 6; - -use Config::Any::INI; - -my $config = eval { Config::Any::INI->load( 't/conf/conf.ini' ) }; -my $simpleconfig = eval { Config::Any::INI->load( 't/conf/conf2.ini' ) }; - -SKIP: { - skip "Couldn't Load INI plugin", 6 if $@; - ok( $config ); - is( $config->{ name }, 'TestApp' ); - is( $config->{Component}->{Controller::Foo}->{foo}, 'bar'); - - ok( $simpleconfig ); - is( $simpleconfig->{ name }, 'TestApp' ); - is( $simpleconfig->{Controller::Foo}->{foo}, 'bar' ); -} +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 ($@)" ); +}