xref: /openbsd/gnu/usr.bin/perl/dist/Storable/t/utf8.t (revision 4cfece93)
1#!./perl -w
2#
3#  Copyright (c) 1995-2000, Raphael Manfredi
4#
5#  You may redistribute only under the same terms as Perl 5, as specified
6#  in the README file that comes with the distribution.
7#
8
9sub BEGIN {
10    if ($] < 5.006) {
11	print "1..0 # Skip: no utf8 support\n";
12	exit 0;
13    }
14    unshift @INC, 't';
15    unshift @INC, 't/compat' if $] < 5.006002;
16    require Config; import Config;
17    if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) {
18        print "1..0 # Skip: Storable was not built\n";
19        exit 0;
20    }
21}
22
23use strict;
24
25use Storable qw(thaw freeze);
26use Test::More tests => 6;
27
28my $x = chr(1234);
29is($x, ${thaw freeze \$x});
30
31# Long scalar
32$x = join '', map {chr $_} (0..1023);
33is($x, ${thaw freeze \$x});
34
35# Char in the range 127-255 (probably) in utf8.  This just won't work for
36# EBCDIC for early Perls.
37$x = ($] lt 5.007_003) ? chr(175) : chr(utf8::unicode_to_native(175))
38   . chr (256);
39chop $x;
40is($x, ${thaw freeze \$x});
41
42# Storable needs to cope if a frozen string happens to be internal utf8
43# encoded
44
45$x = chr 256;
46my $data = freeze \$x;
47is($x, ${thaw $data});
48
49$data .= chr 256;
50chop $data;
51is($x, ${thaw $data});
52
53
54$data .= chr 256;
55# This definitely isn't valid
56eval {thaw $data};
57like($@, qr/corrupt.*characters outside/);
58