File: 04-macros.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 (91 lines) | stat: -rw-r--r-- 1,816 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
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
88
89
90
91
# vim: cindent ft=perl

use warnings;
use strict;

use Test::More tests => 8;
use File::Spec;

BEGIN { use_ok('Config::Scoped') }
my $macros_cfg = File::Spec->catfile( 't', 'files', 'macros.cfg' );
my ($p, $cfg);
isa_ok($p = Config::Scoped->new(file => $macros_cfg), 'Config::Scoped');
ok($p->set_warnings(name => 'perm', switch => 'off'), 'permission warnings off');
ok(eval {$cfg = $p->parse}, 'parsing macros');

my $text = <<'eot';
{
    %macro _M1 m1;    # lexically scoped
    {
	%macro _M2 m2;
	foo { _M1 = "_M1"; _M2 = "_M2" }
    }
    bar { _M1 = "_M1"; _M2 = "_M2" }
}
baz { _M1 = "_M1"; _M2 = "_M2" }
eot

my $expected = {
    'foo' => {
        '_M1' => 'm1',
        '_M2' => 'm2',
    },
    'bar' => {
        '_M1' => 'm1',
        '_M2' => '_M2',
    },
    'baz' => {
        '_M1' => '_M1',
        '_M2' => '_M2',
    },
};



$p = Config::Scoped->new;
is_deeply( $p->parse( text => $text ), $expected, 'macros lexically scoped' );

$text = <<'eot';
{
    %macro _M1 m1;    # lexically scoped
    foo { _M1 = "_M1" }
}
%macro _M1 'no redefinition';
bar { _M1 = "_M1" }
eot

$expected = {
    'foo' => { '_M1' => 'm1' },
    'bar' => { '_M1' => 'no redefinition' },
};


$p = Config::Scoped->new;
is_deeply( $p->parse( text => $text ), $expected, 'macros lexically scoped' );

# no metacharacters expansion
$text = <<'eot';
%macro _M. 'quote metacharacter .';
bar { _M1 = "_M1" }
eot

$expected = {
    'bar' => { '_M1' => '_M1' },
};

$p = Config::Scoped->new;
is_deeply( $p->parse( text => $text ), $expected, 'quoting meta-characters' );

$text = <<'eot';
%macro _M. 'quote metacharacter .';
foo { _M1 = "_M." }
eot

$expected = {
    'foo' => { '_M1' => 'quote metacharacter .' },
};

$p = Config::Scoped->new;
is_deeply( $p->parse( text => $text ), $expected, 'quoting meta-characters' );