Skip to content

Commit

Permalink
More better unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
nfg committed Apr 7, 2015
1 parent c717629 commit 191823b
Showing 1 changed file with 14 additions and 26 deletions.
40 changes: 14 additions & 26 deletions t/bug/rt-41141.t
Expand Up @@ -4,39 +4,27 @@ use strict;
use warnings;

use Test::More;
use Test::Deep;

use YAML::Syck;
use Data::Dumper;

# Carrier returns after c-indicators aren't being handled properly.

my %tests = (
'ends with carriage return' => "?\r",
'number ends with carrier return' => "42\r",
# From the original bug report. Seems to have been fixed already.
'42\\r' => "42\r",

# These all produced bad YAML.
'?\\r' => "?\r",
'-\\r\\r' => "-\r\r",
',\\r\\r\\r' => ",\r\r\r",
);

plan tests => 3 * scalar keys %tests;
plan tests => scalar keys %tests;
while (my ($test, $value) = each (%tests))
{
my $test_hash = { key => $value };
my $yaml = YAML::Syck::Dump($test_hash);
my $decoded = YAML::Syck::Load($yaml);

cmp_deeply(
$decoded,
$test_hash,
"hash: $test",
);

$yaml = YAML::Syck::Dump($value);
$decoded = YAML::Syck::Load($yaml);
is($value, $decoded, "scalar: $test");

$yaml = YAML::Syck::Dump([$value]);
$decoded = YAML::Syck::Load($yaml);
cmp_deeply(
[ $value ],
$decoded,
"array: $test",
);
my $yaml = YAML::Syck::Dump($value);
my $decoded = eval { YAML::Syck::Load($yaml); };
is($decoded, $value, "Produces valid YAML: $test");
}

note 'Done!';
Expand Down

0 comments on commit 191823b

Please sign in to comment.