Upgrade to Test-Simple-0.82.
[p5sagit/p5-mst-13.2.git] / lib / Test / Simple / t / circular_data.t
1 #!/usr/bin/perl -w
2 # $Id: /mirror/googlecode/test-more/t/circular_data.t 57943 2008-08-18T02:09:22.275428Z brooklyn.kid51  $
3
4 # Test is_deeply and friends with circular data structures [rt.cpan.org 7289]
5
6 BEGIN {
7     if( $ENV{PERL_CORE} ) {
8         chdir 't';
9         @INC = ('../lib', 'lib');
10     }
11     else {
12         unshift @INC, 't/lib';
13     }
14 }
15
16 use strict;
17 use Test::More tests => 11;
18
19 my $a1 = [ 1, 2, 3 ];
20 push @$a1, $a1;
21 my $a2 = [ 1, 2, 3 ];
22 push @$a2, $a2;
23
24 is_deeply $a1, $a2;
25 ok( eq_array ($a1, $a2) );
26 ok( eq_set   ($a1, $a2) );
27
28 my $h1 = { 1=>1, 2=>2, 3=>3 };
29 $h1->{4} = $h1;
30 my $h2 = { 1=>1, 2=>2, 3=>3 };
31 $h2->{4} = $h2;
32
33 is_deeply $h1, $h2;
34 ok( eq_hash  ($h1, $h2) );
35
36 my ($r, $s);
37
38 $r = \$r;
39 $s = \$s;
40
41 ok( eq_array ([$s], [$r]) );
42
43
44 {
45     # Classic set of circular scalar refs.
46     my($a,$b,$c);
47     $a = \$b;
48     $b = \$c;
49     $c = \$a;
50
51     my($d,$e,$f);
52     $d = \$e;
53     $e = \$f;
54     $f = \$d;
55
56     is_deeply( $a, $a );
57     is_deeply( $a, $d );
58 }
59
60
61 {
62     # rt.cpan.org 11623
63     # Make sure the circular ref checks don't get confused by a reference 
64     # which is simply repeating.
65     my $a = {};
66     my $b = {};
67     my $c = {};
68
69     is_deeply( [$a, $a], [$b, $c] );
70     is_deeply( { foo => $a, bar => $a }, { foo => $b, bar => $c } );
71     is_deeply( [\$a, \$a], [\$b, \$c] );
72 }