| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
# This script attempts to reproduce: |
| 4 |
# https://github.com/shlomif/perl-Config-IniFiles/issues/14 |
| 5 |
|
| 6 |
# " Could you please document whether Unicode is supported in the config |
| 7 |
# values? " |
| 8 |
|
| 9 |
# Written by Shlomi Fish. |
| 10 |
# This file is licensed under the MIT/Expat License. |
| 11 |
|
| 12 |
use strict; |
| 13 |
use warnings; |
| 14 |
use autodie; |
| 15 |
use utf8; |
| 16 |
|
| 17 |
use Test::More tests => 12; |
| 18 |
|
| 19 |
use lib "./t/lib"; |
| 20 |
|
| 21 |
use Config::IniFiles (); |
| 22 |
use Config::IniFiles::Slurp qw( slurp utf8_slurp utf8_spew ); |
| 23 |
use File::Spec (); |
| 24 |
|
| 25 |
use File::Temp qw(tempdir); |
| 26 |
|
| 27 |
{ |
| 28 |
my $dir_name = tempdir( CLEANUP => 1 ); |
| 29 |
my $filename = File::Spec->catfile( $dir_name, "utf8-test.ini" ); |
| 30 |
{ |
| 31 |
utf8_spew( $filename, <<'EOF' ); |
| 32 |
[section] |
| 33 |
|
| 34 |
mykey = tén |
| 35 |
|
| 36 |
EOF |
| 37 |
} |
| 38 |
|
| 39 |
{ |
| 40 |
open my $in, '<:encoding(utf8)', $filename |
| 41 |
or die "Cannot open '$filename' for slurping - $!"; |
| 42 |
|
| 43 |
my $ini = Config::IniFiles->new( -file => $in, ); |
| 44 |
close($in); |
| 45 |
|
| 46 |
# TEST |
| 47 |
ok( ($ini), "Ini was initialised" ); |
| 48 |
|
| 49 |
# TEST |
| 50 |
is( scalar(@Config::IniFiles::errors), 0, "There are no errors." ); |
| 51 |
|
| 52 |
# TEST |
| 53 |
ok( $ini->SectionExists('section'), "section exists" ); |
| 54 |
|
| 55 |
# TEST |
| 56 |
ok( $ini->exists( 'section', 'mykey' ), "section catches parameter" ); |
| 57 |
|
| 58 |
# TEST |
| 59 |
is( $ini->val( 'section', 'mykey' ), qq#tén#, "->val() parameter" ); |
| 60 |
|
| 61 |
$ini->setval( 'section', 'mykey', 'meö שלום' ); |
| 62 |
|
| 63 |
# TEST |
| 64 |
is( |
| 65 |
$ini->val( 'section', 'mykey' ), |
| 66 |
'meö שלום', |
| 67 |
"setval( ) ; ->val() parameter" |
| 68 |
); |
| 69 |
|
| 70 |
# TEST |
| 71 |
ok( scalar( $ini->WriteConfig( $filename, ) ), "WriteConfig" ); |
| 72 |
} |
| 73 |
|
| 74 |
{ |
| 75 |
open my $in, '<:encoding(utf8)', $filename |
| 76 |
or die "Cannot open '$filename' for slurping - $!"; |
| 77 |
|
| 78 |
my $ini = Config::IniFiles->new( -file => $in, ); |
| 79 |
close($in); |
| 80 |
|
| 81 |
# TEST |
| 82 |
ok( ($ini), "Ini was initialised" ); |
| 83 |
|
| 84 |
# TEST |
| 85 |
is( scalar(@Config::IniFiles::errors), 0, "There are no errors." ); |
| 86 |
|
| 87 |
# TEST |
| 88 |
ok( $ini->SectionExists('section'), "section exists" ); |
| 89 |
|
| 90 |
# TEST |
| 91 |
ok( $ini->exists( 'section', 'mykey' ), "section catches parameter" ); |
| 92 |
|
| 93 |
# TEST |
| 94 |
is( |
| 95 |
$ini->val( 'section', 'mykey' ), |
| 96 |
'meö שלום', |
| 97 |
"->val() parameter" |
| 98 |
); |
| 99 |
} |
| 100 |
} |