move pod tests to xt/
[p5sagit/Config-Any.git] / t / 51-ini.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5 use Config::Any;
6 use Config::Any::INI;
7
8 if ( !Config::Any::INI->is_supported ) {
9     plan skip_all => 'INI format not supported';
10 }
11 else {
12     plan tests => 15;
13 }
14
15 {
16     my $config = Config::Any::INI->load( 't/conf/conf.ini' );
17     ok( $config, 'config loaded' );
18     is( $config->{ name }, 'TestApp', "toplevel key lookup succeeded" );
19     is( $config->{ Component }->{ 'Controller::Foo' }->{ foo },
20         'bar', "nested hashref hack lookup succeeded" );
21 }
22
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 },
28         'bar', "nested hashref hack lookup succeeded" );
29 }
30
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 },
37         'bar', "unnested key lookup succeeded" );
38 }
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 }
50
51 # test invalid config
52 {
53     my $file = 't/invalid/conf.ini';
54     my $config = eval { Config::Any::INI->load( $file ) };
55
56     is $config, undef, 'config load failed';
57     isnt $@, '', 'error thrown';
58 }
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
65     is $config, undef, 'config load failed';
66     isnt $@, '', 'error thrown';
67 }