2 # t/seen.t - Test Seen()
6 require Config; import Config;
8 if ($Config{'extensions'} !~ /\bData\/Dumper\b/) {
9 print "1..0 # Skip: Data::Dumper was not built\n";
18 use Test::More tests => 10;
19 use lib qw( ./t/lib );
20 use Testing qw( _dumptostr );
24 my (@e, %f, @rv, @g, %h, $k);
25 @e = ( qw| alpha beta gamma | );
26 %f = ( epsilon => 'zeta', eta => 'theta' );
27 @g = ( qw| iota kappa lambda | );
28 %h = ( mu => 'nu', omicron => 'pi' );
29 sub j { print "Hello world\n"; }
30 $k = 'just another scalar';
34 local $SIG{__WARN__} = sub { $warning = $_[0] };
36 $obj = Data::Dumper->new( [ \@e, \%f ]);
37 @rv = $obj->Seen( { mark => 'snark' } );
39 qr/^Only refs supported, ignoring non-ref item \$mark/,
40 "Got expected warning for non-ref item");
45 local $SIG{__WARN__} = sub { $warning = $_[0] };
47 $obj = Data::Dumper->new( [ \@e, \%f ]);
48 @rv = $obj->Seen( { mark => undef } );
50 qr/^Value of ref must be defined; ignoring undefined item \$mark/,
51 "Got expected warning for undefined value of item");
55 $obj = Data::Dumper->new( [ \@e, \%f ]);
56 @rv = $obj->Seen( undef );
57 is(@rv, 0, "Seen(undef) returned empty array");
61 $obj = Data::Dumper->new( [ \@e, \%f ]);
62 @rv = $obj->Seen( [ qw| mark snark | ] );
63 is(@rv, 0, "Seen(ref other than hashref) returned empty array");
67 $obj = Data::Dumper->new( [ \@e, \%f ]);
68 @rv = $obj->Seen( { '*samba' => \@g } );
69 is_deeply($rv[0], $obj, "Got the object back: value array ref");
73 $obj = Data::Dumper->new( [ \@e, \%f ]);
74 @rv = $obj->Seen( { '*canasta' => \%h } );
75 is_deeply($rv[0], $obj, "Got the object back: value hash ref");
79 $obj = Data::Dumper->new( [ \@e, \%f ]);
80 @rv = $obj->Seen( { '*pinochle' => \&j } );
81 is_deeply($rv[0], $obj, "Got the object back: value code ref");
85 $obj = Data::Dumper->new( [ \@e, \%f ]);
86 @rv = $obj->Seen( { '*poker' => \$k } );
87 is_deeply($rv[0], $obj, "Got the object back: value ref to scalar");
92 $obj = Data::Dumper->new( [ \@e, \%f ]);
93 @rv = $obj->Seen( { $l => \$k } );
94 is_deeply($rv[0], $obj, "Got the object back: value ref to scalar");
99 $obj = Data::Dumper->new( [ \@e, \%f ]);
100 @rv = $obj->Seen( { $l => \$k } );
101 is_deeply($rv[0], $obj, "Got the object back: value ref to scalar");