File: 040_wide_characters.t

package info (click to toggle)
libunicode-utf8-perl 0.62-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 492 kB
  • sloc: perl: 2,365; sh: 6; makefile: 3
file content (42 lines) | stat: -rwxr-xr-x 984 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
39
40
41
42
#!perl

use strict;
use warnings;
use lib 't';

use Test::More  tests => 7;
use Test::Fatal qw[lives_ok];
use Util        qw[throws_ok];

BEGIN {
    use_ok('Unicode::UTF8', qw[ decode_utf8
                                valid_utf8 ]);
}

{
    my $got;
    utf8::decode(my $exp = "blåbär är gött!");
    utf8::upgrade(my $octets = "blåbär är gött!");
    lives_ok { $got = decode_utf8($octets); } 'decode_utf8() upgraded UTF-8 octets';
    is($got, $exp, "Got expected string");
}

{
    my $got;
    utf8::upgrade(my $octets = "blåbär är gött!");
    lives_ok { $got = valid_utf8($octets); } 'valid_utf8() upgraded UTF-8 octets';
    ok($got, 'Got expected result');
}

{
    use utf8;
    my $str = "\x{26C7}";
    throws_ok { decode_utf8($str); } qr/Can't decode a wide character string/, 'wide character string';
}

{
    use utf8;
    my $str = "\x{26C7}";
    throws_ok { valid_utf8($str); } qr/Can't validate a wide character string/, 'wide character string';
}