1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#!/usr/bin/perl -w
use strict;
use Test::More tests => 13;
use Test::Exception;
my $warning ="";
BEGIN {
chdir 't' if -d 't';
use lib '../blib/lib', 'lib/', '..';
}
my $mod = "Parse::DebControl";
use_ok($mod);
my $writer;
ok($writer = new Parse::DebControl);
throws_ok { $writer->write_mem() } 'Parse::DebControl::Error::IO', "write_mem should fail without data";
throws_ok { $writer->write_file() } 'Parse::DebControl::Error::IO', "write_file should fail without a filename or handle";
throws_ok { $writer->write_file('/fake/file') } 'Parse::DebControl::Error::IO', "write_file should fail without data";
ok($writer->write_mem({'foo' => 'bar'}) eq "foo: bar\n", "write_* should translate simple items correctly");
ok($writer->write_mem({'foo' => ''}) eq "foo:\n", "write_* should accept (begrudgingly) blank hashkeys");
ok($writer->write_mem({'foo' => undef}) eq "foo:\n", "write_* should correctly handle undef items");
SKIP: {
eval { require Tie::IxHash };
skip "Tie::IxHash is not installed", 3 if($@);
my $test1 = "Test: Item1\nTest2: Item2\nTest3: Item3\n";
my $test2 = "Test: Items\n Hello\n There\n .\n World\nAnother-item: world\n";
my $i = 1;
foreach($test1, $test2, "$test1\n$test2"){
ok($writer->write_mem($writer->parse_mem($_, {'useTieIxHash' => 1})) eq $_, "...Fidelity test $i");
$i++;
}
}
my $warnings = "";
local $SIG{__WARN__} = sub { $warnings = $_};
my $mem = $writer->write_mem([{}]);
ok($warnings eq "", "Writing blank hashrefs doesn't throw warnings"); #Version 1.6 fix
$mem = $writer->write_mem([]);
ok($warnings eq "", "Writing blank arrayrefs doesn't throw warnings"); #Version 1.9 fix
|