Few more casts, need reported in
[p5sagit/p5-mst-13.2.git] / t / lib / st-dclone.t
CommitLineData
7a6a85bf 1#!./perl
2
3# $Id: dclone.t,v 0.7 2000/08/03 22:04:44 ram Exp $
4#
5# Copyright (c) 1995-2000, Raphael Manfredi
6#
7# You may redistribute only under the terms of the Artistic License,
8# as specified in the README file that comes with the distribution.
9#
10# $Log: dclone.t,v $
11# Revision 0.7 2000/08/03 22:04:44 ram
12# Baseline for second beta release.
13#
14
15sub BEGIN {
16 chdir('t') if -d 't';
17 unshift @INC, '../lib';
18 require 'lib/st-dump.pl';
19}
20
21
22use Storable qw(dclone);
23
24print "1..9\n";
25
26$a = 'toto';
27$b = \$a;
28$c = bless {}, CLASS;
29$c->{attribute} = 'attrval';
30%a = ('key', 'value', 1, 0, $a, $b, 'cvar', \$c);
31@a = ('first', undef, 3, -4, -3.14159, 456, 4.5,
32 $b, \$a, $a, $c, \$c, \%a);
33
34print "not " unless defined ($aref = dclone(\@a));
35print "ok 1\n";
36
37$dumped = &dump(\@a);
38print "ok 2\n";
39
40$got = &dump($aref);
41print "ok 3\n";
42
43print "not " unless $got eq $dumped;
44print "ok 4\n";
45
46package FOO; @ISA = qw(Storable);
47
48sub make {
49 my $self = bless {};
50 $self->{key} = \%main::a;
51 return $self;
52};
53
54package main;
55
56$foo = FOO->make;
57print "not " unless defined($r = $foo->dclone);
58print "ok 5\n";
59
60print "not " unless &dump($foo) eq &dump($r);
61print "ok 6\n";
62
63# Ensure refs to "undef" values are properly shared during cloning
64my $hash;
65push @{$$hash{''}}, \$$hash{a};
66print "not " unless $$hash{''}[0] == \$$hash{a};
67print "ok 7\n";
68
69my $cloned = dclone(dclone($hash));
70print "not " unless $$cloned{''}[0] == \$$cloned{a};
71print "ok 8\n";
72
73$$cloned{a} = "blah";
74print "not " unless $$cloned{''}[0] == \$$cloned{a};
75print "ok 9\n";
76