BERT
view release on metacpan or search on metacpan
t/02-perl.t view on Meta::CPAN
# hash
$perl = { os => 'linux' };
$bert = encode_bert($perl);
is_deeply([ unpack 'C*', $bert ],
[
131, 104, 3, 100, 0, 4, 98, 101, 114, 116, 100, 0, 4, 100, 105, 99, 116,
108, 0, 0, 0, 1, 104, 2, 109, 0, 0, 0, 2, 111, 115, 109, 0, 0, 0, 5, 108,
105, 110, 117, 120, 106
], 'hash encode');
my $decoded = decode_bert($bert);
isa_ok($decoded, 'BERT::Dict');
is_deeply($decoded, BERT::Dict->new([ os => 'linux' ]), 'hash decode');
my %decoded = @{ $decoded->value };
is_deeply(\%decoded, $perl, 'hash decode');
# ordered hash
SKIP: {
eval { require Tie::IxHash };
skip 'Tie::IxHash not install', 4 if $@;
tie(my %perl, 'Tie::IxHash', fname => 'Juan', lname => 'Tamad');
$perl = \%perl;
$bert = encode_bert($perl);
is_deeply([ unpack 'C*', $bert ],
[
131, 104, 3, 100, 0, 4, 98, 101, 114, 116, 100, 0, 4, 100, 105, 99, 116,
108, 0, 0, 0, 2, 104, 2, 109, 0, 0, 0, 5, 102, 110, 97, 109, 101, 109, 0,
0, 0, 4, 74, 117, 97, 110, 104, 2, 109, 0, 0, 0, 5, 108, 110, 97, 109,
101, 109, 0, 0, 0, 5, 84, 97, 109, 97, 100, 106
], 'ordered hash encode');
my $decoded = decode_bert($bert);
isa_ok($decoded, 'BERT::Dict');
is_deeply($decoded, BERT::Dict->new([ fname => 'Juan', lname => 'Tamad' ]), 'ordered hash decode');
my %decoded = @{ $decoded->value };
is_deeply(\%decoded, $perl, 'ordered hash decode');
}
( run in 0.364 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )