| 1 |
use strict; |
| 2 |
use warnings; |
| 3 |
|
| 4 |
use lib 't/lib'; |
| 5 |
|
| 6 |
use Test::Fatal; |
| 7 |
use Test::MaxMind::DB::Common::Data qw( test_cases_for ); |
| 8 |
use Test::MaxMind::DB::Writer::Serializer qw( test_encoding_of_type ); |
| 9 |
use Test::More; |
| 10 |
|
| 11 |
use Math::Int128 qw( uint128 ); |
| 12 |
use MaxMind::DB::Writer::Serializer; |
| 13 |
|
| 14 |
test_encoding_of_type( uint64 => test_cases_for('uint64') ); |
| 15 |
|
| 16 |
{ |
| 17 |
my $serializer = MaxMind::DB::Writer::Serializer->new( |
| 18 |
map_key_type_callback => sub { } ); |
| 19 |
|
| 20 |
like( |
| 21 |
exception { $serializer->_encode_uint64(undef) }, |
| 22 |
qr/\QYou cannot encode undef as an unsigned 64-bit integer./, |
| 23 |
q{cannot encode undef as an unsigned integer} |
| 24 |
); |
| 25 |
|
| 26 |
like( |
| 27 |
exception { $serializer->_encode_uint64('foo') }, |
| 28 |
qr/\QYou cannot encode foo as an unsigned 64-bit integer. It is not an unsigned integer number./, |
| 29 |
q{cannot encode "foo" as an unsigned integer} |
| 30 |
); |
| 31 |
|
| 32 |
like( |
| 33 |
exception { $serializer->_encode_uint64(-1) }, |
| 34 |
qr/\QYou cannot encode -1 as an unsigned 64-bit integer. It is not an unsigned integer number./, |
| 35 |
'cannot encode -1 as an unsigned integer' |
| 36 |
); |
| 37 |
|
| 38 |
like( |
| 39 |
exception { |
| 40 |
$serializer->_encode_uint64( uint128('36893488147419103232') ); |
| 41 |
}, |
| 42 |
qr/\QYou cannot encode \E[\dA-F]+\Q as an unsigned 64-bit integer. It is too big./, |
| 43 |
'cannot encode 2**65 as an unsigned 64 bit integer' |
| 44 |
); |
| 45 |
} |
| 46 |
|
| 47 |
done_testing(); |