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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
|
use vars qw /$TESTS/;
use Test::More tests => 2 + ($TESTS= 9);
BEGIN { use_ok('Data::Dump::Streamer', qw(:undump Dump)); }
use strict;
use warnings;
# imports same()
require "./t/test_helper.pl";
# use this one for simple, non evalable tests. (GLOB)
# same ( $got,$expected,$name,$obj )
#
# use this one for eval checks and dumper checks but NOT for GLOB's
# same ( $name,$obj,$expected,@args )
my $dump;
my $o= Data::Dump::Streamer->new();
isa_ok($o, 'Data::Dump::Streamer');
SKIP: {
skip "No locked hashes before 5.8.0", $TESTS
if $] < 5.008;
skip "Can't tell which keys are locked before 5.8.1", $TESTS
if $] == 5.008;
{
my %h= ('a0' .. 'a9');
lock_keys(%h);
test_dump({
name => "locked_ref_keys",
verbose => 1
},
$o,
(\%h),
<<'EXPECT',);
$HASH1 = lock_ref_keys( {
a0 => 'a1',
a2 => 'a3',
a4 => 'a5',
a6 => 'a7',
a8 => 'a9'
} );
EXPECT
delete(@h{qw(a2 a6)});
test_dump({
name => "locked_ref_keys_plus",
verbose => 1
},
$o,
(\%h),
<<'EXPECT',);
$HASH1 = lock_ref_keys_plus( {
a0 => 'a1',
a4 => 'a5',
a8 => 'a9'
}, 'a2', 'a6' );
EXPECT
}
{
my %h= ('a0' .. 'a9');
lock_keys(%h);
test_dump({
name => "locked_keys",
verbose => 1
},
$o->Names('*h'),
(\%h),
<<'EXPECT',);
%h = (
a0 => 'a1',
a2 => 'a3',
a4 => 'a5',
a6 => 'a7',
a8 => 'a9'
);
lock_keys( %h );
EXPECT
delete(@h{qw(a2 a6)});
test_dump({
name => "locked_keys_plus",
verbose => 1
},
$o,
(\%h),
<<'EXPECT',);
%h = (
a0 => 'a1',
a4 => 'a5',
a8 => 'a9'
);
lock_keys_plus( %h, 'a2', 'a6');
EXPECT
$o->Names();
}
{
my $h= bless { 'a0' .. 'a9' }, 'locked';
lock_keys(%$h);
test_dump({
name => "blessed locked_ref_keys",
verbose => 1
},
$o,
(\%$h),
<<'EXPECT',);
$locked1 = lock_ref_keys( bless( {
a0 => 'a1',
a2 => 'a3',
a4 => 'a5',
a6 => 'a7',
a8 => 'a9'
}, 'locked' ) );
EXPECT
delete(@$h{qw(a2 a6)});
test_dump({
name => "blessed locked_ref_keys_plus",
verbose => 1
},
$o,
(\%$h),
<<'EXPECT',);
$locked1 = lock_ref_keys_plus( bless( {
a0 => 'a1',
a4 => 'a5',
a8 => 'a9'
}, 'locked' ), 'a2', 'a6' );
EXPECT
}
{
my $h= bless { 'a0' .. 'a9' }, 'locked';
lock_keys(%$h);
test_dump({
name => "blessed locked_keys",
verbose => 1
},
$o->Names('*h'),
($h, $h),
<<'EXPECT',);
%h = (
a0 => 'a1',
a2 => 'a3',
a4 => 'a5',
a6 => 'a7',
a8 => 'a9'
);
$locked1 = bless( \%h, 'locked' );
lock_keys( %h );
EXPECT
delete(@$h{qw(a2 a6)});
test_dump({
name => "blessed locked_keys_plus",
verbose => 1
},
$o,
($h, $h),
<<'EXPECT',);
%h = (
a0 => 'a1',
a4 => 'a5',
a8 => 'a9'
);
$locked1 = bless( \%h, 'locked' );
lock_keys_plus( %h, 'a2', 'a6');
EXPECT
$o->Names();
}
{
my $x= 0;
my %hashes=
map { $_ => lock_ref_keys_plus({ foo => $_ }, $x++) } 1 .. 10;
lock_keys_plus(%hashes, 10 .. 19);
test_dump({
name => "blessed locked_keys_plus",
verbose => 1
},
$o,
(\%hashes),
<<'EXPECT',);
$HASH1 = lock_ref_keys_plus( {
1 => lock_ref_keys_plus( { foo => 1 }, 0 ),
2 => lock_ref_keys_plus( { foo => 2 }, 1 ),
3 => lock_ref_keys_plus( { foo => 3 }, 2 ),
4 => lock_ref_keys_plus( { foo => 4 }, 3 ),
5 => lock_ref_keys_plus( { foo => 5 }, 4 ),
6 => lock_ref_keys_plus( { foo => 6 }, 5 ),
7 => lock_ref_keys_plus( { foo => 7 }, 6 ),
8 => lock_ref_keys_plus( { foo => 8 }, 7 ),
9 => lock_ref_keys_plus( { foo => 9 }, 8 ),
10 => lock_ref_keys_plus( { foo => 10 }, 9 )
}, 11, 12, 13, 14, 15, 16, 17, 18, 19 );
EXPECT
}
} # SKIP
__END__
# with eval testing
{
same( "", $o, <<'EXPECT', ( ) );
EXPECT
}
# without eval testing
{
same( $dump = $o->Data()->Out, <<'EXPECT', "", $o );
EXPECT
}
|