| 1 |
#!/usr/bin/perl |
| 2 |
use strict; |
| 3 |
use warnings; |
| 4 |
|
| 5 |
# Should be 10. |
| 6 |
use Test::More tests => 10; |
| 7 |
|
| 8 |
use Config::IniFiles; |
| 9 |
|
| 10 |
use lib "./t/lib"; |
| 11 |
|
| 12 |
use Config::IniFiles::Debug; |
| 13 |
use Config::IniFiles::TestPaths; |
| 14 |
|
| 15 |
my ( $value, @value ); |
| 16 |
umask 0000; |
| 17 |
|
| 18 |
my $ini = Config::IniFiles->new( -file => t_file("test.ini") ); |
| 19 |
$ini->_assert_invariants(); |
| 20 |
t_unlink("test01.ini"); |
| 21 |
$ini->SetFileName( t_file("test01.ini") ); |
| 22 |
$ini->SetWriteMode("0666"); |
| 23 |
|
| 24 |
# TEST |
| 25 |
ok( $ini, "Loading from a file" ); |
| 26 |
|
| 27 |
$value = $ini->val( 'test1', 'one' ); |
| 28 |
$ini->_assert_invariants(); |
| 29 |
|
| 30 |
# TEST |
| 31 |
is( $value, 'value1', "Reading a single value in scalar context" ); |
| 32 |
|
| 33 |
@value = $ini->val( 'test1', 'one' ); |
| 34 |
$ini->_assert_invariants(); |
| 35 |
|
| 36 |
# TEST |
| 37 |
is( $value[0], 'value1', "Reading a single value in list context" ); |
| 38 |
|
| 39 |
$value = $ini->val( 'test1', 'mult' ); |
| 40 |
|
| 41 |
# TEST |
| 42 |
is( $value, "one$/two$/three", "Reading a multiple value in scalar context" ); |
| 43 |
|
| 44 |
@value = $ini->val( 'test1', 'mult' ); |
| 45 |
$value = join "|", @value; |
| 46 |
|
| 47 |
# TEST |
| 48 |
is_deeply( |
| 49 |
\@value, |
| 50 |
[ "one", "two", "three" ], |
| 51 |
"Reading a multiple value in list context", |
| 52 |
); |
| 53 |
|
| 54 |
@value = ( "one", "two", "three" ); |
| 55 |
$ini->newval( 'test1', 'eight', @value ); |
| 56 |
$ini->_assert_invariants(); |
| 57 |
$value = $ini->val( 'test1', 'eight' ); |
| 58 |
|
| 59 |
# TEST |
| 60 |
is( $value, "one$/two$/three", "Creating a new multiple value", ); |
| 61 |
|
| 62 |
$ini->newval( 'test1', 'seven', 'value7' ); |
| 63 |
$ini->_assert_invariants(); |
| 64 |
$ini->RewriteConfig; |
| 65 |
$ini->ReadConfig; |
| 66 |
$ini->_assert_invariants(); |
| 67 |
$value = ''; |
| 68 |
$value = $ini->val( 'test1', 'seven' ); |
| 69 |
$ini->_assert_invariants(); |
| 70 |
|
| 71 |
# TEST |
| 72 |
is( $value, 'value7', "Creating a new value", ); |
| 73 |
|
| 74 |
$ini->delval( 'test1', 'seven' ); |
| 75 |
$ini->_assert_invariants(); |
| 76 |
$ini->RewriteConfig; |
| 77 |
$ini->ReadConfig; |
| 78 |
$ini->_assert_invariants(); |
| 79 |
$value = ''; |
| 80 |
$value = $ini->val( 'test1', 'seven' ); |
| 81 |
|
| 82 |
# TEST |
| 83 |
ok( !defined($value), "Deleting a value" ); |
| 84 |
|
| 85 |
$value = $ini->val( 'test1', 'not a real parameter name', '12345' ); |
| 86 |
|
| 87 |
# TEST |
| 88 |
is( $value, '12345', "Reading a default values from existing section" ); |
| 89 |
|
| 90 |
$value = |
| 91 |
$ini->val( 'not a real section', 'no parameter by this name', '12345' ); |
| 92 |
|
| 93 |
# TEST |
| 94 |
is( $value, '12345', "Reading a default values from non-existent section" ); |
| 95 |
|
| 96 |
# Clean up when we're done |
| 97 |
t_unlink("test01.ini"); |
| 98 |
|