Commit | Line | Data |
---|---|---|
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 | |
9 | sub 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 | 19 | use strict; |
dd19458b JH |
20 | |
21 | use Storable qw(thaw freeze); | |
dddb60fc | 22 | use Test::More tests => 6; |
dd19458b | 23 | |
e16e2ff8 | 24 | my $x = chr(1234); |
dddb60fc | 25 | is($x, ${thaw freeze \$x}); |
dd19458b | 26 | |
e16e2ff8 NC |
27 | # Long scalar |
28 | $x = join '', map {chr $_} (0..1023); | |
dddb60fc | 29 | is($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 | 35 | chop $x; |
dddb60fc | 36 | is($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; | |
42 | my $data = freeze \$x; | |
dddb60fc | 43 | is($x, ${thaw $data}); |
fa523c3a NC |
44 | |
45 | $data .= chr 256; | |
46 | chop $data; | |
dddb60fc | 47 | is($x, ${thaw $data}); |
fa523c3a NC |
48 | |
49 | ||
50 | $data .= chr 256; | |
c4a6f826 | 51 | # This definitely isn't valid |
fa523c3a | 52 | eval {thaw $data}; |
dddb60fc | 53 | like($@, qr/corrupt.*characters outside/); |