use
5.008001;
BEGIN {
$ENV
{PERL_BSON_BACKEND} =
undef
}
BEGIN {
$INC
{
"BSON/XS.pm"
} =
undef
}
use
BSON
qw/encode decode/
;
my
(
$hash
);
is( bson_decimal128(),
"0"
,
"empty bson_decimal128() is 0"
);
eval
{ BSON::Decimal128->new };
ok( $@,
"BSON::Decimal128->new throws"
);
is( bson_decimal128(
"3.14159"
),
"3.14159"
,
"overloading correct"
);
$hash
= decode( encode( {
A
=> bson_decimal128(
"3.14159"
) } ) );
is(
ref
(
$hash
->{A} ),
'BSON::Decimal128'
,
"BSON::Decimal128->BSON::Decimal128"
);
is(
$hash
->{A}->value,
"3.14159"
,
"value correct"
);
for
my
$s
(
qw/Infinity -Infinity NaN/
) {
$hash
= decode( encode( {
A
=> bson_decimal128(
$s
) } ) );
is(
$hash
->{A}->value,
$s
,
"$s value correct"
);
}
is( to_myjson( {
a
=> bson_decimal128(
"0.0"
) } ),
q[{"a":"0.0"}]
,
'bson_decimal128(0.0)'
);
is( to_myjson( {
a
=> bson_decimal128(
"42"
) } ),
q[{"a":"42"}]
,
'bson_decimal128(42)'
);
is( to_myjson( {
a
=> bson_decimal128(
"0.1"
) } ),
q[{"a":"0.1"}]
,
'bson_decimal128(0.1)'
);
is(
to_extjson( {
a
=> bson_decimal128(
"0.0"
) } ),
q[{"a":{"$numberDecimal":"0.0"}}]
,
'bson_decimal128(0.0)'
);
is(
to_extjson( {
a
=> bson_decimal128(
"12345678E678"
) } ),
q[{"a":{"$numberDecimal":"1.2345678E+685"}}]
,
'bson_decimal128(12345678E+678)'
);
done_testing;