File: Serializer-utf8-as-bytes.t

package info (click to toggle)
libmaxmind-db-writer-perl 0.300003-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,336 kB
  • sloc: ansic: 3,059; perl: 2,895; makefile: 5; sh: 4
file content (38 lines) | stat: -rw-r--r-- 768 bytes parent folder | download | duplicates (3)
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
30
31
32
33
34
35
36
37
38
use strict;
use warnings;
use utf8;

use Test::Builder;
use Test::Fatal;
use Test::More;

use Encode ();
use MaxMind::DB::Reader::Decoder;
use MaxMind::DB::Writer::Serializer;

{
    my $tb = Test::Builder->new();

    for ( $tb->output, $tb->failure_output, $tb->todo_output ) {
        binmode $_, ':encoding(UTF-8)' or die $!;
    }
}

my $input = "\x{4eba}";

ok(
    Encode::is_utf8($input),
    'input is marked as utf8 in Perl'
);

my $serializer
    = MaxMind::DB::Writer::Serializer->new( map_key_type_callback => sub { }
    );

like(
    exception { $serializer->store_data( bytes => $input ) },
    qr/\QYou attempted to store a characters string (人) as bytes/,
    'got an error when trying to serialize a character string as bytes'
);

done_testing();