Config-General

 view release on metacpan or  search on metacpan

t/run.t  view on Meta::CPAN

  $ostr50 .= " 'luck${counter}'";
}
$ostr50 =~ s{\A }{};
my $cfgsrc50 = 'test_single_many ' . $ostr50;
$cfg50 =  new Config::General( -String => $cfgsrc50, -InterPolateVars => 1 );
%hash50 = $cfg50->getall();
is($hash50{test_single_many}, $ostr50, "value with single-quote strings is as expected" );


# check for escaped chars
my $cfg51  =  new Config::General( -ConfigFile => "t/cfg.51" );
my %hash51 = $cfg51->getall();
is($hash51{dollar},    '$foo',                 "keep escaped dollar character");
is($hash51{backslash}, 'contains \ backslash', "keep escaped backslash character");
is($hash51{prize},     '18 $',                 "keep un-escaped dollar character");
is($hash51{hostparam}, q("'wsh.dir'"),         "keep escaped quote character");
is($hash51{bgcolor},   '#fff',                 "keep escaped number sign");

# now save it to a file and re-read it in and see if everything remains escaped
$cfg51->save_file("t/cfg.51.out");
$cfg51  =  new Config::General( -ConfigFile => "t/cfg.51.out", -InterPolateVars => 1 );
my %hash51new = $cfg51->getall();
is_deeply(\%hash51, \%hash51new, "compare saved config containing escaped chars");


# check if forced single value arrays remain
my $cfg52  = new Config::General( -String => "habeas = [ corpus ]", -ForceArray => 1);
my %hash52 = $cfg52->getall();
my @array52 = qw(corpus);
is_deeply($hash52{habeas}, \@array52, "check -ForceArray single value arrays");
$cfg52->save_file("t/cfg.52.out");
$cfg52 = new Config::General( -ConfigFile => "t/cfg.52.out", -ForceArray => 1);
my %hash52new = $cfg52->getall();
is_deeply(\%hash52new, \%hash52, "check -ForceArray single value arrays during save()");

my $cfg53 = new Config::General(-AllowSingleQuoteInterpolation => 1, -String => "got = 1\nhave = '\$got'", -InterPolateVars => 1 );
my %hash53 = $cfg53->getall();
is($hash53{have}, "'1'", "check -AllowSingleQuoteInterpolation");


# Make sure no warnings were seen during the test.
ok( !@WARNINGS_FOUND, "No unexpected warnings seen" );

# check if disabling escape chars does work
my $cfg54 = new Config::General(-NoEscape => 1, -String => qq(val = \\\$notavar:\\blah\n));
my %hash54 = $cfg54->getall();
is($hash54{val}, qq(\\\$notavar:\\blah), "check -NoEscape");

# check for line continuation followed by empty line (rt.cpan.org#39814)
my $cfg55 = new Config::General( -ConfigFile => "t/cfg.55" );
my %hash55 = $cfg55->getall();
is($hash55{b}, "nochop", "check continuation followed by empty line");

my $cfg56 = Config::General->new();
eval {
  $cfg56->save_file("t/56.out", { "new\nline" => 9, "brack<t" => 8 });
};
ok($@, "catch special chars in keys");


# UTF8[BOM] tests
my $cfg57 = "t/utf8_bom/foo.cfg";
my $expected57 = {foo => {"\x{e9}" => "\x{e8}", bar => {"\x{f4}" => "\x{ee}"}}};

for my $bool (0, 1) {
  my $conf = Config::General->new(-ConfigFile      => $cfg57,
                                  -IncludeRelative => 1,
                                  -UTF8            => $bool);
  my %hash = $conf->getall;
  is_deeply \%hash, $expected57, "-UTF8 => $bool";
}

# IFDEF tests
my $cfg58 = "t/cfg.58";
my $expected58 = { level => "debug" };
my %defs = (
            scalar => 'TEST',
            array  => ['TEST'],
            hash   => {'TEST' => 1}
          );

foreach my $def (keys %defs) {
  my $conf = Config::General->new(-ConfigFile         => $cfg58,
                                  -UseApacheIfDefine => 1,
                                  -Define             => $defs{$def});
  my %hash = $conf->getall();
  is_deeply \%hash, $expected58, "UseApacheIfDefine, -Define => $def";
}

# force quoting
my $cfg59 = "t/cfg.59";
my $expected59 = qq(foo   "bar baz"
); # newline is important here, as we check write output
my $conf59 = Config::General->new(
    -ConfigFile        => $cfg59,
    -AlwaysQuoteOutput => 1);
my $got59 = $conf59->save_string();
is_deeply \$expected59, \$got59, "quotes";



( run in 0.634 second using v1.01-cache-2.11-cpan-39bf76dae61 )