| 1 | #!/usr/bin/perl |
| 2 | |
| 3 | # This test attempts to reproduce |
| 4 | # https://sourceforge.net/tracker/?func=detail&aid=3388382&group_id=6926&atid=106926 |
| 5 | |
| 6 | use strict; |
| 7 | use warnings; |
| 8 | |
| 9 | use Test::More tests => 4; |
| 10 | use File::Spec; |
| 11 | |
| 12 | use Config::IniFiles; |
| 13 | |
| 14 | my $ini_filename = |
| 15 | File::Spec->catfile( File::Spec->curdir(), "t", 'test31.ini' ); |
| 16 | |
| 17 | { |
| 18 | open my $ini_fh, '>', $ini_filename |
| 19 | or die "Cannot open '$ini_filename' - $!"; |
| 20 | print {$ini_fh} <<'EOT'; |
| 21 | [section] |
| 22 | value1 = xxx ; My Comment |
| 23 | value2 = xxx ; My_Comment |
| 24 | EOT |
| 25 | close($ini_fh); |
| 26 | } |
| 27 | |
| 28 | my $ini = Config::IniFiles->new( |
| 29 | -file => $ini_filename, |
| 30 | -handle_trailing_comment => 1, |
| 31 | -commentchar => ';', |
| 32 | -allowedcommentchars => ';#' |
| 33 | ); |
| 34 | |
| 35 | # TEST |
| 36 | is( $ini->val( 'section', 'value1' ), 'xxx' ); |
| 37 | |
| 38 | # TEST |
| 39 | is( $ini->GetParameterTrailingComment( 'section', 'value1' ), 'My Comment' ); |
| 40 | |
| 41 | # TEST |
| 42 | is( $ini->val( 'section', 'value2' ), 'xxx' ); |
| 43 | |
| 44 | # TEST |
| 45 | is( $ini->GetParameterTrailingComment( 'section', 'value2' ), 'My_Comment' ); |
| 46 | |
| 47 | unlink($ini_filename); |