BERT

 view release on metacpan or  search on metacpan

t/02-perl.t  view on Meta::CPAN

#!/usr/bin/perl

use strict;
use warnings;

use Test::More tests => 18;
use BERT;

# unicode string
my $perl = 'fooåäöÅÄÖbar';
my $bert = encode_bert($perl);
is_deeply([ unpack 'C*', $bert ], 
          [
              131, 109, 0, 0, 0, 18, 102, 111, 111, 195, 165, 195, 164, 195, 182, 
              195, 133, 195, 132, 195, 150, 98, 97, 114
          ], 'unicode string encode');
is(decode_bert($bert), $perl, 'unicode string decode');

# empty string
$perl = '';
$bert = encode_bert($perl);
is_deeply([ unpack 'C*', $bert ], 
          [
              131, 109, 0, 0, 0, 0
          ], 'empty string encode');
is(decode_bert($bert), $perl, 'empty string decode');

t/03-erlang.t  view on Meta::CPAN

$bert = encode_bert($perl);
is_deeply([ unpack 'C*', $bert ], \@bytes, 'atom encode');


@bytes = (
    131, 100, 0, 12, 195, 165, 195, 164, 195, 182, 195, 133, 195, 132,
    195, 150
);
$perl = decode_bert(pack 'C*', @bytes);
isa_ok($perl, 'BERT::Atom');
is($perl, BERT::Atom->new('åäöÅÄÖ'), 'atom unicode decode');
$bert = encode_bert($perl);
is_deeply([ unpack 'C*', $bert ], \@bytes, 'atom unicode encode');

# float
@bytes = (
    131, 99, 50, 46, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 
    48, 48, 48, 48, 48, 48, 101, 43, 48, 48, 0, 0, 0, 0, 0
);
$perl = decode_bert(pack 'C*', @bytes);
cmp_ok($perl, '==', 2.0, 'float decode');
$bert = encode_bert($perl);
is_deeply([ unpack 'C*', $bert ], \@bytes, 'float encode');



( run in 0.272 second using v1.01-cache-2.11-cpan-88abd93f124 )