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
92
93
|
package JWebmail::Test::INI;
use v5.24;
use warnings;
use utf8;
use Test2::Bundle::More;
use Test2::Require::Module 'Config::Tiny';
use JWebmail::Plugin::INIConfig;
local $/;
my $data = <DATA>;
close DATA;
my $ct = Config::Tiny->new;
my $conf = $ct->read_string($data);
ok(not $ct->errstr) or diag $ct->errstr;
SKIP: {
skip 'only for debuging';
diag explain $conf;
}
subtest 'flat' => sub {
is $conf->{'_'}{a}, 'b';
is $conf->{section}{d}, 'e';
is $conf->{section}{1}, 'a';
is $conf->{'nested::section'}{a}, 'info';
is $conf->{array_section}{0}, 'a';
is $conf->{'nested::array_section'}{0}, 'a';
};
subtest 'processed' => sub {
my $conf2 = JWebmail::Plugin::INIConfig::_process_config($conf);
is $conf2->{a}, 'b';
is $conf2->{section}{d}, 'e';
is $conf2->{section}{1}, 'a';
is $conf2->{nested}{section}{a}, 'info';
is $conf2->{nested}{section}{deeply}{x}, 'deeply';
is $conf2->{array_section}[0], 'a';
is $conf2->{nested}{array_section}[0], 'a';
};
done_testing;
__DATA__
# example file
# [global_section alias _]
a = b ; line comment
[section]
d = e
f = e # not a comment
"ha llo , = &f" = 'nic a = %& xa'
1 = a
2 = b
x =
y =
[othersection]
long = my very long value
[nested::section]
a = info
[nested::section::deeply]
x = deeply
[array_section]
0 = a
1 = b
2 = c
3 = d
4 = e
[nested::array_section]
0 = a
#[nested::array_section::1::deeply]
#key = val
|