Upgrade to Test-Simple-0.82.
[p5sagit/p5-mst-13.2.git] / lib / Test / Simple / t / circular_data.t
CommitLineData
7483b81c 1#!/usr/bin/perl -w
ccbd73a4 2# $Id: /mirror/googlecode/test-more/t/circular_data.t 57943 2008-08-18T02:09:22.275428Z brooklyn.kid51 $
7483b81c 3
4# Test is_deeply and friends with circular data structures [rt.cpan.org 7289]
5
6BEGIN {
7 if( $ENV{PERL_CORE} ) {
8 chdir 't';
9 @INC = ('../lib', 'lib');
10 }
11 else {
12 unshift @INC, 't/lib';
13 }
14}
15
16use strict;
5143c659 17use Test::More tests => 11;
7483b81c 18
19my $a1 = [ 1, 2, 3 ];
20push @$a1, $a1;
21my $a2 = [ 1, 2, 3 ];
22push @$a2, $a2;
23
24is_deeply $a1, $a2;
25ok( eq_array ($a1, $a2) );
26ok( eq_set ($a1, $a2) );
27
28my $h1 = { 1=>1, 2=>2, 3=>3 };
29$h1->{4} = $h1;
30my $h2 = { 1=>1, 2=>2, 3=>3 };
31$h2->{4} = $h2;
32
33is_deeply $h1, $h2;
34ok( eq_hash ($h1, $h2) );
5143c659 35
36my ($r, $s);
37
38$r = \$r;
39$s = \$s;
40
41ok( 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}