~ubuntu-branches/ubuntu/natty/libconfig-inifiles-perl/natty-updates

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
#!/usr/bin/perl

use strict;
use warnings;

# Originally: 9
use Test::More tests => 9;

use Config::IniFiles;

use lib "./t/lib";

use Config::IniFiles::TestPaths;

my ($en, $ini, $success);

# test 1
# print "Empty list when no groups ........ ";
$en = Config::IniFiles->new( -file => t_file('en.ini') );
# TEST
is ( scalar($en->Groups), 0, "Empty list when no groups" );

# test 2
# print "Creating new object, no file ..... ";
$ini = Config::IniFiles->new;
# TEST
ok ($ini, "Creating new object");

# test 3
# print "Setting new file name .............";
# TEST
ok ($ini->SetFileName(t_file('test06.ini')), "Setting new file name");

# test 4
# print "Saving under new file name ........";
# TEST
ok ($ini->RewriteConfig() && (-f t_file('test06.ini')),
    "Saving under new file name ........"
);

# test 5
# print "SetSectionComment .................";
$ini->newval("Section1", "Parameter1", "Value1");
my @section_comment = ("Line 1 of section comment.", "Line 2 of section comment", "Line 3 of section comment");

# TEST
ok(
    $ini->SetSectionComment("Section1", @section_comment),
    "SetSectionComment() was successful."
);

# test 6
# print "GetSectionComment .................";
{
    my @comment = $ini->GetSectionComment("Section1");

    # TEST
    is_deeply(
        \@comment,
        [
            "# Line 1 of section comment.",
            "# Line 2 of section comment",
            "# Line 3 of section comment",
        ],
        "multi-line GetSectionComment",
        );
}

# test 7
# print "DeleteSectionComment ..............";
$ini->DeleteSectionComment("Section1");
# TEST
ok(!defined($ini->GetSectionComment("Section1")),
    "DeleteSectionComment was successful.");

# test 8
# DeleteSection
$ini->DeleteSection( 'Section1' );
# TEST
ok( ! $ini->Parameters( 'Section1' ), "DeleteSection was successful." );

# test 9
# Delete entire config
$ini->Delete();
# TEST
ok( ! $ini->Sections(), "Delete entire config");

# Clean up when we're done
t_unlink("test06.ini");