| 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 MaxMind::DB::Writer::Serializer; |
| 12 |
|
| 13 |
test_encoding_of_type( uint32 => test_cases_for('uint32') ); |
| 14 |
|
| 15 |
{ |
| 16 |
my $serializer = MaxMind::DB::Writer::Serializer->new( |
| 17 |
map_key_type_callback => sub { } ); |
| 18 |
|
| 19 |
like( |
| 20 |
exception { $serializer->_encode_uint32(undef) }, |
| 21 |
qr/\QYou cannot encode undef as an unsigned 32-bit integer./, |
| 22 |
q{cannot encode undef as an unsigned integer} |
| 23 |
); |
| 24 |
|
| 25 |
like( |
| 26 |
exception { $serializer->_encode_uint32('foo') }, |
| 27 |
qr/\QYou cannot encode foo as an unsigned 32-bit integer. It is not an unsigned integer number/, |
| 28 |
q{cannot encode "foo" as an unsigned integer} |
| 29 |
); |
| 30 |
|
| 31 |
like( |
| 32 |
exception { $serializer->_encode_uint32(-1) }, |
| 33 |
qr/\QYou cannot encode -1 as an unsigned 32-bit integer. It is not an unsigned integer number./, |
| 34 |
'cannot encode -1 as an unsigned integer' |
| 35 |
); |
| 36 |
|
| 37 |
like( |
| 38 |
exception { $serializer->_encode_uint32( 2**33 ) }, |
| 39 |
qr/\QYou cannot encode \E\d+\Q as an unsigned 32-bit integer. It is too big./, |
| 40 |
'cannot encode 2**33 as an unsigned 32-bit integer' |
| 41 |
); |
| 42 |
} |
| 43 |
|
| 44 |
done_testing(); |