This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
dist/Storable/t/utf8.t: Fix to run under EBCDIC
[perl5.git] / dist / Storable / t / utf8.t
CommitLineData
e16e2ff8 1#!./perl -w
dd19458b 2#
e16e2ff8
NC
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.
dd19458b 7#
dd19458b
JH
8
9sub BEGIN {
10 if ($] < 5.006) {
11 print "1..0 # Skip: no utf8 support\n";
12 exit 0;
13 }
48c887dd 14 unshift @INC, 't';
1afdebce 15 unshift @INC, 't/compat' if $] < 5.006002;
dd19458b 16 require Config; import Config;
0c384302 17 if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) {
dd19458b
JH
18 print "1..0 # Skip: Storable was not built\n";
19 exit 0;
20 }
dd19458b
JH
21}
22
e16e2ff8 23use strict;
dd19458b
JH
24
25use Storable qw(thaw freeze);
dddb60fc 26use Test::More tests => 6;
dd19458b 27
e16e2ff8 28my $x = chr(1234);
dddb60fc 29is($x, ${thaw freeze \$x});
dd19458b 30
e16e2ff8
NC
31# Long scalar
32$x = join '', map {chr $_} (0..1023);
dddb60fc 33is($x, ${thaw freeze \$x});
e16e2ff8
NC
34
35# Char in the range 127-255 (probably) in utf8
81d8a247 36$x = chr(utf8::unicode_to_native(175)) . chr (256);
e16e2ff8 37chop $x;
dddb60fc 38is($x, ${thaw freeze \$x});
fa523c3a 39
c4a6f826 40# Storable needs to cope if a frozen string happens to be internal utf8
fa523c3a
NC
41# encoded
42
43$x = chr 256;
44my $data = freeze \$x;
dddb60fc 45is($x, ${thaw $data});
fa523c3a
NC
46
47$data .= chr 256;
48chop $data;
dddb60fc 49is($x, ${thaw $data});
fa523c3a
NC
50
51
52$data .= chr 256;
c4a6f826 53# This definitely isn't valid
fa523c3a 54eval {thaw $data};
dddb60fc 55like($@, qr/corrupt.*characters outside/);