#!./perl
use_ok(
'Tie::Hash'
);
tie
my
%tied
,
'Tie::ExtraHash'
;
%tied
= (
apple
=>
'tree'
,
cow
=>
'field'
);
my
%hash
= (
apple
=>
'tree'
,
cow
=>
'field'
);
is_deeply(\
%hash
, \
%tied
,
"TIEHASH"
);
ok(
tied
(
%tied
),
"TIEHASH really does tie"
);
is_deeply([
sort
keys
%hash
], [
sort
keys
%tied
],
"FIRSTKEY/NEXTKEY"
);
is_deeply([
sort
values
%hash
], [
sort
values
%tied
],
"FIRSTKEY/NEXTKEY"
);
ok(
exists
(
$tied
{apple}) &&
exists
(
$hash
{apple}),
'EXISTS works when it exists'
);
delete
(
$tied
{apple});
delete
(
$hash
{apple});
ok(!
exists
(
$tied
{apple}) && !
exists
(
$hash
{apple}),
'EXISTS works when it doesn\'t exist (as does DELETE)'
);
$tied
{house} =
$hash
{house} =
'town'
;
ok(
$tied
{house} eq
'town'
&&
$tied
{house} eq
$hash
{house},
'STORE and FETCH'
);
%tied
= ();
%hash
= ();
ok(
tied
(
%tied
),
"still tied after CLEAR"
);
is_deeply(\
%tied
, \
%hash
,
"CLEAR"
);
is(
scalar
(
%tied
),
scalar
(
%hash
),
"SCALAR"
);
done_testing();