1 # Copyright (c) 2009-2012 Zmanda, Inc. All Rights Reserved.
3 # This program is free software; you can redistribute it and/or modify it
4 # under the terms of the GNU General Public License version 2 as published
5 # by the Free Software Foundation.
7 # This program is distributed in the hope that it will be useful, but
8 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
9 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 # You should have received a copy of the GNU General Public License along
13 # with this program; if not, write to the Free Software Foundation, Inc.,
14 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 # Contact information: Zmanda Inc, 465 S Mathlida Ave, Suite 300
17 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
19 use Test::More tests => 22;
23 use lib "@amperldir@";
24 use Amanda::Config::FoldingHash;
27 my $h = Amanda::Config::FoldingHash->new();
28 ok(!(exists $h->{'key'}), "key doesn't exist in new hash");
29 is_deeply([sort(keys(%$h))], [], "hash starts out with no keys");
32 ok((exists $h->{'key'}), "key exists after assignment");
33 is($h->{'key'}, 3, "can fetch value stored in simple key");
34 is($h->{'kEy'}, 3, "can fetch value stored in key via fold");
37 is($h->{'key'}, 4, "updating the one key works");
38 is_deeply([sort(keys(%$h))], [sort(qw(key))], "hash now has the one key");
41 ok(!(exists $h->{'key'}), "key doesn't exist after deletion");
42 is($h->{'key'}, undef, "got undef fetching deleted key");
45 ok((exists $h->{'kEY'}), "unfolded key exists after assignment");
46 ok((exists $h->{'key'}), "folded key exists after assignment");
47 is($h->{'key'}, 20, "can fetch value stored in folded key");
48 is_deeply([sort(keys(%$h))], [sort(qw(key))], "key is folded in list");
51 is($h->{'key'}, 92, "updated folded key");
54 is($h->{'key'}, 37, "updated key via fold");
56 $h->{'_some-OTHER_kEy_'} = undef;
57 ok((exists $h->{'_some-OTHER_kEy_'}), "longer key exists after assigning undef");
58 ok((exists $h->{'-some-other-key-'}), "longer folded key exists too");
59 ok((exists $h->{'-SOME_other_key_'}), "longer key exists via fold");
60 is_deeply([sort(keys(%$h))], [sort(qw(key -some-other-key-))], "keys list as folded");
63 ok(!(exists $h->{'key'}), "key doesn't exist after deletion via fold");
64 is($h->{'key'}, undef, "got undef fetching folded deleted key");
66 for my $k (qw(_ __ a-B Cf_ __g-h i__j-k L)) {
70 is_deeply([sort(keys(%$h))], [sort(qw(-some-other-key- - -- a-b cf- --g-h i--j-k l))],
71 "various keys are listed as folded");