This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Support Unicode properties Identifier_(Status|Type)
[perl5.git] / lib / Tie / ExtraHash.t
1 #!./perl
2
3 use strict;
4 use warnings;
5 use Test::More tests => 11;
6 use_ok('Tie::Hash');
7
8 tie my %tied, 'Tie::ExtraHash';
9 %tied = (apple => 'tree', cow => 'field');
10 my %hash = (apple => 'tree', cow => 'field');
11
12 # TIEHASH
13 is_deeply(\%hash, \%tied, "TIEHASH");
14 ok(tied(%tied), "TIEHASH really does tie");
15
16 # FIRST/NEXTKEY
17 is_deeply([sort keys %hash], [sort keys %tied], "FIRSTKEY/NEXTKEY");
18 is_deeply([sort values %hash], [sort values %tied], "FIRSTKEY/NEXTKEY");
19
20 # EXISTS
21 ok(exists($tied{apple}) && exists($hash{apple}),
22    'EXISTS works when it exists');
23
24 # DELETE and !EXISTS
25 delete($tied{apple}); delete($hash{apple});
26 ok(!exists($tied{apple}) && !exists($hash{apple}),
27    'EXISTS works when it doesn\'t exist (as does DELETE)');
28
29 # STORE and FETCH
30 $tied{house} = $hash{house} = 'town';
31 ok($tied{house} eq 'town' && $tied{house} eq $hash{house},
32    'STORE and FETCH');
33
34 # CLEAR
35 %tied = (); %hash = ();
36 ok(tied(%tied), "still tied after CLEAR");
37 is_deeply(\%tied, \%hash, "CLEAR");
38
39 # SCALAR
40 is(scalar(%tied), scalar(%hash), "SCALAR");
41