File: 11-eval.t

package info (click to toggle)
libconfig-scoped-perl 0.12-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 752 kB
  • ctags: 73
  • sloc: perl: 10,347; makefile: 42
file content (55 lines) | stat: -rw-r--r-- 1,161 bytes parent folder | download | duplicates (6)
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
# vim: cindent ft=perl sm sw=4

use warnings;
use strict;

use Test::More tests => 5;

BEGIN { use_ok('Config::Scoped') }
my ( $p, $cfg );

my $text = <<'eot';
foo { sec = eval{ 3600 * 24 }};
bar { min = perl_code{ 60 * 24 }};
eot

my $expected = {
    'foo' => { 'sec' => 86400 },
    'bar' => { 'min' => 1440 },
};

isa_ok( $p = Config::Scoped->new(), 'Config::Scoped' );
is_deeply( $p->parse( text => $text ), $expected, 'eval test' );


$text = <<'eot';
foo { list = eval{ [1..9] }};
bar { hash = perl_code{ {red => '#FF0000', green => '#00FF00', blue => '#0000FF'}}};
eot

$expected = {
    'foo' => { 'list' => [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] },
    'bar' => {
        'hash' => {
            'red'   => '#FF0000',
            'green' => '#00FF00',
            'blue'  => '#0000FF',
        }
    },
};

$p = Config::Scoped->new;
is_deeply( $p->parse( text => $text ), $expected, 'eval test' );

$text = <<'eot';
%macro IF_LIST 'eth1,eth2,eth3';
if {
    list = eval { [IF_LIST] };
}
eot

$expected = { 'if' => { 'list' => [ 'eth1', 'eth2', 'eth3' ] } };


$p = Config::Scoped->new;
is_deeply( $p->parse( text => $text ), $expected, 'macro exp. in eval' );