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