summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/perl/dist/Storable/t/utf8.t
blob: a8dd6cd31746f5b65ace593b42a570ca38a1cca5 (plain) (blame)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!./perl -w
#
#  Copyright (c) 1995-2000, Raphael Manfredi
#  
#  You may redistribute only under the same terms as Perl 5, as specified
#  in the README file that comes with the distribution.
#

sub BEGIN {
    if ($] < 5.006) {
	print "1..0 # Skip: no utf8 support\n";
	exit 0;
    }
    unshift @INC, 't';
    unshift @INC, 't/compat' if $] < 5.006002;
    require Config; import Config;
    if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) {
        print "1..0 # Skip: Storable was not built\n";
        exit 0;
    }
}

use strict;

use Storable qw(thaw freeze);
use Test::More tests => 6;

my $x = chr(1234);
is($x, ${thaw freeze \$x});

# Long scalar
$x = join '', map {chr $_} (0..1023);
is($x, ${thaw freeze \$x});

# Char in the range 127-255 (probably) in utf8.  This just won't work for
# EBCDIC for early Perls.
$x = ($] lt 5.007_003) ? chr(175) : chr(utf8::unicode_to_native(175))
   . chr (256);
chop $x;
is($x, ${thaw freeze \$x});

# Storable needs to cope if a frozen string happens to be internal utf8
# encoded

$x = chr 256;
my $data = freeze \$x;
is($x, ${thaw $data});

$data .= chr 256;
chop $data;
is($x, ${thaw $data});


$data .= chr 256;
# This definitely isn't valid
eval {thaw $data};
like($@, qr/corrupt.*characters outside/);