| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
use Test::More tests => 19; |
| 7 |
|
| 8 |
use Config::IniFiles; |
| 9 |
|
| 10 |
use lib "./t/lib"; |
| 11 |
|
| 12 |
use Config::IniFiles::TestPaths; |
| 13 |
|
| 14 |
my $ors = $\ || "\n"; |
| 15 |
|
| 16 |
my ( $ini, $value ); |
| 17 |
|
| 18 |
# |
| 19 |
# Import tests added by JW/WADG |
| 20 |
# |
| 21 |
|
| 22 |
# test 1 |
| 23 |
# print "Import a file .................... "; |
| 24 |
my $en = Config::IniFiles->new( -file => t_file('en.ini') ); |
| 25 |
|
| 26 |
# TEST |
| 27 |
ok( $en, "IniEn was initialized." ); |
| 28 |
|
| 29 |
# test 2 |
| 30 |
my $es = Config::IniFiles->new( -file => t_file('es.ini'), -import => $en ); |
| 31 |
|
| 32 |
# TEST |
| 33 |
ok( $es, "Ini es was initialized." ); |
| 34 |
|
| 35 |
# test 3 |
| 36 |
# Imported values are good |
| 37 |
my $en_sn = $en->val( 'x', 'ShortName' ); |
| 38 |
my $es_sn = $es->val( 'x', 'ShortName' ); |
| 39 |
my $en_ln = $en->val( 'x', 'LongName' ); |
| 40 |
my $es_ln = $es->val( 'x', 'LongName' ); |
| 41 |
my $en_dn = $en->val( 'm', 'DataName' ); |
| 42 |
my $es_dn = $es->val( 'm', 'DataName' ); |
| 43 |
|
| 44 |
# TEST |
| 45 |
is( $en_sn, 'GENERAL', "en_sn is GENERAL" ); |
| 46 |
|
| 47 |
# TEST |
| 48 |
is( $es_sn, 'GENERAL', "es_sn is GENERAL too" ); |
| 49 |
|
| 50 |
# TEST |
| 51 |
is( $en_ln, 'General Summary', "en_ln is OK." ); |
| 52 |
|
| 53 |
# TEST |
| 54 |
is( $es_ln, 'Resumen general', "es_ln is in Spanish" ); |
| 55 |
|
| 56 |
# TEST |
| 57 |
is( $en_dn, 'Month', "dn is in English" ); |
| 58 |
|
| 59 |
# TEST |
| 60 |
is( $es_dn, 'Mes', "es_dn is in Spanish" ); |
| 61 |
|
| 62 |
# test 4 |
| 63 |
# Import another level |
| 64 |
my $ca = Config::IniFiles->new( -file => t_file('ca.ini'), -import => $es ); |
| 65 |
|
| 66 |
# TEST |
| 67 |
is( $en_sn, $ca->val( 'x', 'ShortName' ), "en_sn is OK." ); |
| 68 |
|
| 69 |
# TEST |
| 70 |
is( $es_sn, $ca->val( 'x', 'ShortName' ), "es_sn is OK." ); |
| 71 |
|
| 72 |
# TEST |
| 73 |
is( $ca->val( 'x', 'LongName' ), 'Resum general', "LongName is OK." ); |
| 74 |
|
| 75 |
# TEST |
| 76 |
is( $ca->val( 'm', 'DataName' ), 'Mes', "DateName is OK." ); |
| 77 |
|
| 78 |
# test 5 |
| 79 |
# Try creating a config file that imports from a hand-built object |
| 80 |
my $ini_a = Config::IniFiles->new(); |
| 81 |
$ini_a->AddSection('alpha'); |
| 82 |
$ini_a->AddSection('x'); |
| 83 |
$ini_a->newval( 'x', 'x', 1 ); |
| 84 |
$ini_a->newval( 'x', 'LongName', 1 ); |
| 85 |
$ini_a->newval( 'm', 'z', 1 ); |
| 86 |
|
| 87 |
# TEST |
| 88 |
is( $ini_a->val( 'x', 'x' ), 1, "x/x" ); |
| 89 |
|
| 90 |
# TEST |
| 91 |
is( $ini_a->val( 'x', 'LongName' ), 1, "x/LongName" ); |
| 92 |
|
| 93 |
# TEST |
| 94 |
is( $ini_a->val( 'm', 'z' ), 1, "m/z" ); |
| 95 |
|
| 96 |
# test 6 |
| 97 |
## show that importing a file-less object into a file-based one works |
| 98 |
my $ini_b = |
| 99 |
Config::IniFiles->new( -file => t_file('ca.ini'), -import => $ini_a ); |
| 100 |
|
| 101 |
# TEST |
| 102 |
is( $ini_b->val( 'x', 'LongName' ), 'Resum general', "x/Longname" ); |
| 103 |
|
| 104 |
# TEST |
| 105 |
is( $ini_b->val( 'x', 'x', 0 ), 1, "x/x" ); |
| 106 |
|
| 107 |
# TEST |
| 108 |
is( $ini_b->val( 'm', 'z', 0 ), 1, "m/z" ); |
| 109 |
|
| 110 |
# TEST |
| 111 |
is( $ini_b->val( 'm', 'LongName' ), 'Resum mensual', "m/LongName" ); |