| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
# Should be 6. |
| 7 |
use Test::More tests => 6; |
| 8 |
|
| 9 |
use Config::IniFiles; |
| 10 |
|
| 11 |
use lib "./t/lib"; |
| 12 |
|
| 13 |
use Config::IniFiles::Debug; |
| 14 |
use Config::IniFiles::TestPaths; |
| 15 |
|
| 16 |
my ( $ini, $value ); |
| 17 |
|
| 18 |
$ini = Config::IniFiles->new( -file => t_file("test.ini") ); |
| 19 |
$ini->_assert_invariants(); |
| 20 |
$ini->SetFileName( t_file("test02.ini") ); |
| 21 |
$ini->SetWriteMode("0666"); |
| 22 |
|
| 23 |
# print "Weird characters in section name . "; |
| 24 |
$value = $ini->val( '[w]eird characters', 'multiline' ); |
| 25 |
$ini->_assert_invariants(); |
| 26 |
|
| 27 |
# TEST |
| 28 |
is( |
| 29 |
$value, |
| 30 |
"This$/is a multi-line$/value", |
| 31 |
"Weird characters in section name", |
| 32 |
); |
| 33 |
|
| 34 |
$ini->newval( "test7|anything", "exists", "yes" ); |
| 35 |
$ini->_assert_invariants(); |
| 36 |
$ini->RewriteConfig; |
| 37 |
$ini->ReadConfig; |
| 38 |
$ini->_assert_invariants(); |
| 39 |
$value = $ini->val( "test7|anything", "exists" ); |
| 40 |
|
| 41 |
# TEST |
| 42 |
is( $value, "yes", "More weird chars.", ); |
| 43 |
|
| 44 |
# Test 3/4 |
| 45 |
# Make sure whitespace after parameter name is not included in name |
| 46 |
# TEST |
| 47 |
is( |
| 48 |
$ini->val( 'test7', 'criterion' ), |
| 49 |
'price <= maximum', |
| 50 |
"Make sure whitespace after parameter name is not included in name", |
| 51 |
); |
| 52 |
|
| 53 |
# TEST |
| 54 |
ok( |
| 55 |
!defined $ini->val( 'test7', 'criterion ' ), |
| 56 |
"For criterion containing whitespace returns undef.", |
| 57 |
); |
| 58 |
|
| 59 |
# Test 5 |
| 60 |
# Build a file from scratch with tied interface for testing |
| 61 |
my %test; |
| 62 |
|
| 63 |
# TEST |
| 64 |
ok( ( tie %test, 'Config::IniFiles' ), "Tying is successful" ); |
| 65 |
tied(%test)->SetFileName( t_file('test02.ini') ); |
| 66 |
|
| 67 |
# Test 6 |
| 68 |
# Also with pipes when using tied interface using value of 0 |
| 69 |
$test{'2'} = {}; |
| 70 |
tied(%test)->_assert_invariants(); |
| 71 |
$test{'2'}{'test'} = "sleep"; |
| 72 |
tied(%test)->_assert_invariants(); |
| 73 |
my $sectionheader = "0|2"; |
| 74 |
$test{$sectionheader} = {}; |
| 75 |
tied(%test)->_assert_invariants(); |
| 76 |
$test{$sectionheader}{'vacation'} = 0; |
| 77 |
tied(%test)->_assert_invariants(); |
| 78 |
tied(%test)->RewriteConfig(); |
| 79 |
tied(%test)->ReadConfig; |
| 80 |
|
| 81 |
# TEST |
| 82 |
ok( scalar( $test{$sectionheader}{'vacation'} == 0 ), "Returned 0", ); |
| 83 |
|
| 84 |
# Clean up when we're done |
| 85 |
t_unlink("test02.ini"); |
| 86 |
|