xref: /openbsd-src/gnu/usr.bin/perl/lib/Tie/ExtraHash.t (revision 256a93a44f36679bee503f12e49566c2183f6181)
1898184e3Ssthen#!./perl
2898184e3Ssthen
3898184e3Ssthenuse strict;
4898184e3Ssthenuse warnings;
5*256a93a4Safresh1use Test::More;
6898184e3Ssthenuse_ok('Tie::Hash');
7898184e3Ssthen
8898184e3Ssthentie my %tied, 'Tie::ExtraHash';
9898184e3Ssthen%tied = (apple => 'tree', cow => 'field');
10898184e3Ssthenmy %hash = (apple => 'tree', cow => 'field');
11898184e3Ssthen
12898184e3Ssthen# TIEHASH
13898184e3Ssthenis_deeply(\%hash, \%tied, "TIEHASH");
14898184e3Ssthenok(tied(%tied), "TIEHASH really does tie");
15898184e3Ssthen
16898184e3Ssthen# FIRST/NEXTKEY
17898184e3Ssthenis_deeply([sort keys %hash], [sort keys %tied], "FIRSTKEY/NEXTKEY");
18898184e3Ssthenis_deeply([sort values %hash], [sort values %tied], "FIRSTKEY/NEXTKEY");
19898184e3Ssthen
20898184e3Ssthen# EXISTS
21898184e3Ssthenok(exists($tied{apple}) && exists($hash{apple}),
22898184e3Ssthen   'EXISTS works when it exists');
23898184e3Ssthen
24898184e3Ssthen# DELETE and !EXISTS
25898184e3Ssthendelete($tied{apple}); delete($hash{apple});
26898184e3Ssthenok(!exists($tied{apple}) && !exists($hash{apple}),
27898184e3Ssthen   'EXISTS works when it doesn\'t exist (as does DELETE)');
28898184e3Ssthen
29898184e3Ssthen# STORE and FETCH
30898184e3Ssthen$tied{house} = $hash{house} = 'town';
31898184e3Ssthenok($tied{house} eq 'town' && $tied{house} eq $hash{house},
32898184e3Ssthen   'STORE and FETCH');
33898184e3Ssthen
34898184e3Ssthen# CLEAR
35898184e3Ssthen%tied = (); %hash = ();
36898184e3Ssthenok(tied(%tied), "still tied after CLEAR");
37898184e3Ssthenis_deeply(\%tied, \%hash, "CLEAR");
38898184e3Ssthen
39898184e3Ssthen# SCALAR
40898184e3Ssthenis(scalar(%tied), scalar(%hash), "SCALAR");
41898184e3Ssthen
42*256a93a4Safresh1done_testing();
43