| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
|
| 4 |
use Test::More; |
| 5 |
use lib 't/lib'; |
| 6 |
use lib 't/pvtlib'; |
| 7 |
use CleanEnv; |
| 8 |
|
| 9 |
use BSON; |
| 10 |
use Tie::IxHash; |
| 11 |
|
| 12 |
my $c = BSON->new; |
| 13 |
|
| 14 |
# PERL-543 deflation to BSON then back (via database?) caused undef to be an empty string |
| 15 |
|
| 16 |
subtest 'tied Tie::IxHash' => sub { |
| 17 |
my %h; |
| 18 |
tie( %h, 'Tie::IxHash', h => undef ); |
| 19 |
|
| 20 |
my $bin = $c->encode_one( \%h ); |
| 21 |
my $doc = $c->decode_one( $bin ); |
| 22 |
|
| 23 |
is $doc->{h}, undef, 'round trip undef'; |
| 24 |
}; |
| 25 |
|
| 26 |
subtest 'OO Tie::IxHash' => sub { |
| 27 |
my $h = Tie::IxHash->new( h => undef ); |
| 28 |
|
| 29 |
my $bin = $c->encode_one( $h ); |
| 30 |
my $doc = $c->decode_one( $bin ); |
| 31 |
|
| 32 |
is $doc->{h}, undef, 'round trip undef'; |
| 33 |
}; |
| 34 |
|
| 35 |
subtest 'standard hash' => sub { |
| 36 |
my %doc = ( h => undef ); |
| 37 |
|
| 38 |
my $bin = $c->encode_one( \%doc ); |
| 39 |
my $doc = $c->decode_one( $bin ); |
| 40 |
|
| 41 |
is $doc->{h}, undef, 'round trip undef'; |
| 42 |
}; |
| 43 |
|
| 44 |
done_testing; |