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
|
#!/usr/bin/perl
use strict;
use Test;
use Data::Dumper;
use lib '../lib';
BEGIN { plan tests => 8 }
use Asterisk::config;
my $file = "t/array_hash.conf";
open TRUNCATED_FILE, ">$file";
close TRUNCATED_FILE;
my $conf = new Asterisk::config(file => $file);
$conf->assign_addsection(section=>"test-array");
$conf->assign_append(section=>"test-array", point=>"foot",
data=> [
"a = b",
"var = value",
]);
$conf->assign_addsection(section=>"test-hash");
$conf->assign_append(section=>"test-hash", point=>"foot",
data=> {
a => "b",
var => "value",
});
#$conf->assign_addsection(section=>"[unsection]");
$conf->assign_append(point=>"up",
data=> [
"a = b",
"var = value",
]);
#$conf->assign_addsection(section=>"[unsection]");
$conf->assign_append(point=>"up",
data=> {
a1 => "b",
var1 => "value",
});
$conf->save_file();
$conf->reload();
ok(@{$conf->fetch_values_arrayref(section=>'test-array', key=>'a' )}[0] eq 'b' );
ok(@{$conf->fetch_values_arrayref(section=>'test-array', key=>'var')}[0] eq 'value');
ok(@{$conf->fetch_values_arrayref(section=>'test-hash', key=>'a' )}[0] eq 'b' );
ok(@{$conf->fetch_values_arrayref(section=>'test-array', key=>'var')}[0] eq 'value');
ok(@{$conf->fetch_values_arrayref(section=>'[unsection]',key=>'a' )}[0] eq 'b' );
ok(@{$conf->fetch_values_arrayref(section=>'[unsection]',key=>'var' )}[0] eq 'value');
ok(@{$conf->fetch_values_arrayref(section=>'[unsection]',key=>'a1' )}[0] eq 'b' );
ok(@{$conf->fetch_values_arrayref(section=>'[unsection]',key=>'var1')}[0] eq 'value');
|