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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
use strict;
use warnings;
use Test::More;
use Test::Differences;
use Test::Exception;
use autobox::Core;
use lib "lib";
use autobox::Transform;
subtest "array_to_ref" => sub {
my $array = [ 1, 2 ];
my @array = @$array;
eq_or_diff(
[ @array->to_ref ],
[ $array ],
"Array to_ref in list context works",
);
eq_or_diff(
[ $array->to_ref ],
[ $array ],
"ArrayRef to_ref in list context works",
);
};
subtest "hash_to_ref" => sub {
my $hash = { 1 => 2, 2 => 3 };
my %hash = %$hash;
eq_or_diff(
[ %hash->to_ref ],
[ $hash ],
"Hash to_ref in list context works",
);
eq_or_diff(
[ $hash->to_ref ],
[ $hash ],
"HashRef to_ref in list context works",
);
};
subtest "array_to_array" => sub {
my $array = [ 1, 2 ];
my @array = @$array;
eq_or_diff(
[ @array->to_array ],
[ @array ],
"Array to_array in list context works",
);
eq_or_diff(
[ $array->to_array ],
[ @array ],
"ArrayRef to_array in list context works",
);
};
subtest "array_to_hash" => sub {
my $array = [ 1, 2 ];
my @array = @$array;
eq_or_diff(
@array->to_hash->to_ref,
{ 1 => 2 },
"Array to_hash works",
);
throws_ok(
sub { [ 1, 2, "c" ]->to_hash },
qr/\@array->to_hash on an array with an odd number of elements \(3\) at/,
"Array to_hash with an odd number of items goes *boom*",
);
};
subtest "hash_to_hash" => sub {
my $hash = { a => 1, b => 2 };
my %hash = %$hash;
eq_or_diff(
{ %hash->to_hash },
{ %hash },
"Hash to_hash in list context works",
);
eq_or_diff(
{ $hash->to_hash },
{ %hash },
"HashRef to_hash in list context works",
);
};
subtest "hash_to_array" => sub {
my $hash = { z => 1, a => 1, b => 2 };
eq_or_diff(
[ $hash->to_array ],
[ a => 1, b => 2, z => 1 ],
"Hash to_array works",
);
};
done_testing();
|