File: dualvar.t

package info (click to toggle)
libbson-perl 1.10.2-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,152 kB
  • sloc: perl: 3,970; makefile: 2
file content (29 lines) | stat: -rw-r--r-- 625 bytes parent folder | download | duplicates (4)
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
use strict;
use warnings;

use Test::More;
use Test::Fatal;
use Scalar::Util 'dualvar';
use lib 't/lib';
use lib 't/pvtlib';
use CleanEnv;

use BSON;

# PERL-737 encoding of dual vars
# should look have an NV representation and be encoded as numbers

ok(my $c = BSON->new, 'got codec object');

my ($number, $str) = (5, 'hello');
my $dualvar = dualvar($number, $str);
ok($dualvar == $number, 'dual var is a number');
is($dualvar, $str, 'dual var is a string');

my $dualvar_bin = $c->encode_one({ dual => $dualvar });
ok(
    $c->decode_one($dualvar_bin)->{'dual'} == $number,
    'round trip for dual var'
);

done_testing;