1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
#!./perl -w
# t/seen.t - Test Seen()
use strict;
use warnings;
use Data::Dumper;
use Test::More tests => 10;
use lib qw( ./t/lib );
use Testing qw( _dumptostr );
my ($obj, %dumps);
my (@e, %f, @rv, @g, %h, $k);
@e = ( qw| alpha beta gamma | );
%f = ( epsilon => 'zeta', eta => 'theta' );
@g = ( qw| iota kappa lambda | );
%h = ( mu => 'nu', omicron => 'pi' );
sub j { print "Hello world\n"; }
$k = 'just another scalar';
{
my $warning = '';
local $SIG{__WARN__} = sub { $warning = $_[0] };
$obj = Data::Dumper->new( [ \@e, \%f ]);
@rv = $obj->Seen( { mark => 'snark' } );
like($warning,
qr/^Only refs supported, ignoring non-ref item \$mark/,
"Got expected warning for non-ref item");
}
{
my $warning = '';
local $SIG{__WARN__} = sub { $warning = $_[0] };
$obj = Data::Dumper->new( [ \@e, \%f ]);
@rv = $obj->Seen( { mark => undef } );
like($warning,
qr/^Value of ref must be defined; ignoring undefined item \$mark/,
"Got expected warning for undefined value of item");
}
{
$obj = Data::Dumper->new( [ \@e, \%f ]);
@rv = $obj->Seen( undef );
is(@rv, 0, "Seen(undef) returned empty array");
}
{
$obj = Data::Dumper->new( [ \@e, \%f ]);
@rv = $obj->Seen( [ qw| mark snark | ] );
is(@rv, 0, "Seen(ref other than hashref) returned empty array");
}
{
$obj = Data::Dumper->new( [ \@e, \%f ]);
@rv = $obj->Seen( { '*samba' => \@g } );
is_deeply($rv[0], $obj, "Got the object back: value array ref");
}
{
$obj = Data::Dumper->new( [ \@e, \%f ]);
@rv = $obj->Seen( { '*canasta' => \%h } );
is_deeply($rv[0], $obj, "Got the object back: value hash ref");
}
{
$obj = Data::Dumper->new( [ \@e, \%f ]);
@rv = $obj->Seen( { '*pinochle' => \&j } );
is_deeply($rv[0], $obj, "Got the object back: value code ref");
}
{
$obj = Data::Dumper->new( [ \@e, \%f ]);
@rv = $obj->Seen( { '*poker' => \$k } );
is_deeply($rv[0], $obj, "Got the object back: value ref to scalar");
}
{
my $l = 'loo';
$obj = Data::Dumper->new( [ \@e, \%f ]);
@rv = $obj->Seen( { $l => \$k } );
is_deeply($rv[0], $obj, "Got the object back: value ref to scalar");
}
{
my $l = '$loo';
$obj = Data::Dumper->new( [ \@e, \%f ]);
@rv = $obj->Seen( { $l => \$k } );
is_deeply($rv[0], $obj, "Got the object back: value ref to scalar");
}
|