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