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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
# vim: cindent ft=perl sm sw=4
use warnings;
use strict;
use Test::More tests => 8;
BEGIN { use_ok('Config::Scoped') }
my ( $p, $cfg );
my $text = <<'eot';
{ #1
{ #2
{ #3
a=3
}
a=2
}
a=1
}
foo{}
eot
my $expected = { foo => {} };
isa_ok( $p = Config::Scoped->new(), 'Config::Scoped' );
is_deeply( $p->parse( text => $text ), $expected, 'lexically scoped' );
$text = <<'eot';
{ #1
{ #2
{ #3
a=3
foo{}
}
a=2
bar{}
}
a=1
baz{}
}
eot
$expected = {
'foo' => { 'a' => '3' },
'bar' => { 'a' => '2' },
'baz' => { 'a' => '1' },
};
$p = Config::Scoped->new;
is_deeply( $p->parse( text => $text ), $expected, 'lexically scoped' );
$text = <<'eot';
a = default;
foo { %warnings param off; a = 1 }
bar { }
eot
$expected = {
'foo' => { 'a' => '1' },
'bar' => { 'a' => 'default' },
};
$p = Config::Scoped->new;
is_deeply( $p->parse( text => $text ), $expected, 'parameter redefinition' );
$text = <<'eot';
a = default;
foo { a = 1 }
bar { }
eot
$p = Config::Scoped->new;
eval { $p->parse( text => $text ) };
isa_ok($@, 'Config::Scoped::Error::Validate::Parameter');
like($@, qr/redefinition/i, "$@");
$text = <<'eot';
LowerCase = 'Values dont convert'
eot
$expected = { _GLOBAL => { 'lowercase' => 'Values dont convert', }, };
$p = Config::Scoped->new(lc => 1);
is_deeply( $p->parse( text => $text ), $expected, 'lowercase conversion' );
|