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    unshift @INC, 't';
11    unshift @INC, 't/compat' if $] < 5.006002;
12    require Config; import Config;
13    if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) {
14        print "1..0 # Skip: Storable was not built\n";
15        exit 0;
16    }
17}
18
19use strict;
20
21use Storable qw(thaw freeze);
22use Test::More tests => 6;
23
24my $x = chr(1234);
25is($x, ${thaw freeze \$x});
26
27# Long scalar
28$x = join '', map {chr $_} (0..1023);
29is($x, ${thaw freeze \$x});
30
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);
35chop $x;
36is($x, ${thaw freeze \$x});
37
38# Storable needs to cope if a frozen string happens to be internal utf8
39# encoded
40
41$x = chr 256;
42my $data = freeze \$x;
43is($x, ${thaw $data});
44
45$data .= chr 256;
46chop $data;
47is($x, ${thaw $data});
48
49
50$data .= chr 256;
51# This definitely isn't valid
52eval {thaw $data};
53like($@, qr/corrupt.*characters outside/);
54