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