| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
# Originally: 9 |
| 7 |
use Test::More tests => 11; |
| 8 |
|
| 9 |
use Config::IniFiles; |
| 10 |
|
| 11 |
use lib "./t/lib"; |
| 12 |
|
| 13 |
use Config::IniFiles::TestPaths; |
| 14 |
|
| 15 |
my ( $en, $ini, $success ); |
| 16 |
|
| 17 |
# test 1 |
| 18 |
# print "Empty list when no groups ........ "; |
| 19 |
$en = Config::IniFiles->new( -file => t_file('en.ini') ); |
| 20 |
|
| 21 |
# TEST |
| 22 |
is( scalar( $en->Groups ), 0, "Empty list when no groups" ); |
| 23 |
|
| 24 |
# test 2 |
| 25 |
# print "Creating new object, no file ..... "; |
| 26 |
$ini = Config::IniFiles->new; |
| 27 |
|
| 28 |
# TEST |
| 29 |
ok( $ini, "Creating new object" ); |
| 30 |
|
| 31 |
# test 3 |
| 32 |
# print "Setting new file name ............."; |
| 33 |
# TEST |
| 34 |
ok( $ini->SetFileName( t_file('test06.ini') ), "Setting new file name" ); |
| 35 |
|
| 36 |
# test 4 |
| 37 |
# print "Saving under new file name ........"; |
| 38 |
# TEST |
| 39 |
ok( $ini->RewriteConfig() && ( -f t_file('test06.ini') ), |
| 40 |
"Saving under new file name ........" ); |
| 41 |
|
| 42 |
# test 5 |
| 43 |
# print "SetSectionComment ................."; |
| 44 |
$ini->newval( "Section1", "Parameter1", "Value1" ); |
| 45 |
my @section_comment = ( |
| 46 |
"Line 1 of section comment.", |
| 47 |
"Line 2 of section comment", |
| 48 |
"Line 3 of section comment" |
| 49 |
); |
| 50 |
|
| 51 |
# TEST |
| 52 |
ok( $ini->SetSectionComment( "Section1", @section_comment ), |
| 53 |
"SetSectionComment() was successful." ); |
| 54 |
|
| 55 |
# test 6 |
| 56 |
# print "GetSectionComment ................."; |
| 57 |
{ |
| 58 |
my @comment = $ini->GetSectionComment("Section1"); |
| 59 |
|
| 60 |
# TEST |
| 61 |
is_deeply( |
| 62 |
\@comment, |
| 63 |
[ |
| 64 |
"# Line 1 of section comment.", |
| 65 |
"# Line 2 of section comment", |
| 66 |
"# Line 3 of section comment", |
| 67 |
], |
| 68 |
"multi-line GetSectionComment", |
| 69 |
); |
| 70 |
} |
| 71 |
|
| 72 |
# test 7 |
| 73 |
# print "DeleteSectionComment .............."; |
| 74 |
$ini->DeleteSectionComment("Section1"); |
| 75 |
|
| 76 |
# TEST |
| 77 |
ok( |
| 78 |
!defined( $ini->GetSectionComment("Section1") ), |
| 79 |
"DeleteSectionComment was successful." |
| 80 |
); |
| 81 |
|
| 82 |
# test 8 |
| 83 |
# CopySection |
| 84 |
$ini->CopySection( 'Section1', 'Section2' ); |
| 85 |
|
| 86 |
# TEST |
| 87 |
ok( $ini->Parameters('Section2'), "CopySection was successful." ); |
| 88 |
|
| 89 |
# test 9 |
| 90 |
# DeleteSection |
| 91 |
$ini->DeleteSection('Section1'); |
| 92 |
|
| 93 |
# TEST |
| 94 |
ok( !$ini->Parameters('Section1'), "DeleteSection was successful." ); |
| 95 |
|
| 96 |
# test 10 |
| 97 |
# RenameSection |
| 98 |
$ini->RenameSection( 'Section2', 'Section1' ); |
| 99 |
|
| 100 |
# TEST |
| 101 |
ok( |
| 102 |
!$ini->Parameters('Section2') |
| 103 |
&& $ini->Parameters('Section1') |
| 104 |
&& $ini->val( 'Section1', 'Parameter1' ) eq 'Value1', |
| 105 |
"RenameSection was successful." |
| 106 |
); |
| 107 |
|
| 108 |
# test 11 |
| 109 |
# Delete entire config |
| 110 |
$ini->Delete(); |
| 111 |
|
| 112 |
# TEST |
| 113 |
ok( !$ini->Sections(), "Delete entire config" ); |
| 114 |
|
| 115 |
# Clean up when we're done |
| 116 |
t_unlink("test06.ini"); |
| 117 |
|