| 1 | #!perl |
| 2 | |
| 3 | use warningsscip-perl cpan Redis-Fast 0.37 warnings/; |
| 4 | use strictscip-perl cpan Redis-Fast 0.37 strict/; |
| 5 | use Test::Morescip-perl cpan Redis-Fast 0.37 Test/More/; |
| 6 | use Test::Deepscip-perl cpan Redis-Fast 0.37 Test/Deep/; |
| 7 | use Redis::Fast::Hashscip-perl cpan Redis-Fast 0.37 Redis/Fast/Hash/; |
| 8 | use libscip-perl cpan Redis-Fast 0.37 lib/ 't/tlib'; |
| 9 | use Test::SpawnRedisServerscip-perl cpan Redis-Fast 0.37 Test/SpawnRedisServer/; |
| 10 | |
| 11 | use constantscip-perl cpan Redis-Fast 0.37 constant/ SSL_AVAILABLEscip-perl cpan Redis-Fast 0.37 main/SSL_AVAILABLE(). => eval { requirescip-perl cpan Redis-Fast 0.37 main/require(). IO::Socket::SSL }; |
| 12 | |
| 13 | my ($c, $t, $srv) = redisscip-perl cpan Redis-Fast 0.37 main/redis().(); |
| 14 | my $use_ssl = $t ? SSL_AVAILABLE : 0; |
| 15 | |
| 16 | END { |
| 17 | $c->()scip-perl cpan Redis-Fast 0.37 main/`->()`(). if $c; |
| 18 | $t->()scip-perl cpan Redis-Fast 0.37 main/`->()`(). if $t; |
| 19 | } |
| 20 | |
| 21 | ## Setup |
| 22 | my %my_hash; |
| 23 | okscip-perl cpan Redis-Fast 0.37 main/ok().(my $redis = tie(%my_hash, 'Redis::Fast::Hash', 'my_hash', server => $srv, ssl => $use_ssl, SSL_verify_mode => 0), 'tied to our test redis-server'); |
| 24 | okscip-perl cpan Redis-Fast 0.37 main/ok().($redis->pingscip-perl cpan Redis-Fast 0.37 main/ping()., 'pinged fine'); |
| 25 | isa_okscip-perl cpan Redis-Fast 0.37 main/isa_ok().($redis, 'Redis::Fast::Hash'); |
| 26 | |
| 27 | |
| 28 | ## Direct access |
| 29 | subtestscip-perl cpan Redis-Fast 0.37 main/subtest(). 'direct access' => sub { |
| 30 | %my_hash = (); |
| 31 | cmp_deeplyscip-perl cpan Redis-Fast 0.37 main/cmp_deeply().(\%my_hash, {}, 'empty list ok'); |
| 32 | |
| 33 | %my_hash = (a => 'foo', b => 'bar', c => 'baz'); |
| 34 | cmp_deeplyscip-perl cpan Redis-Fast 0.37 main/cmp_deeply().(\%my_hash, { a => 'foo', b => 'bar', c => 'baz' }, 'Set multiple values ok'); |
| 35 | |
| 36 | $my_hash{b} = 'BAR'; |
| 37 | cmp_deeplyscip-perl cpan Redis-Fast 0.37 main/cmp_deeply().(\%my_hash, { a => 'foo', b => 'BAR', c => 'baz' }, 'Set single value ok'); |
| 38 | |
| 39 | isscip-perl cpan Redis-Fast 0.37 main/is().($my_hash{c}++, 'baz', 'get single value ok'); |
| 40 | isscip-perl cpan Redis-Fast 0.37 main/is().(++$my_hash{c}, 'bbb', '... even with post/pre-increments'); |
| 41 | }; |
| 42 | |
| 43 | |
| 44 | ## Hash functions |
| 45 | subtestscip-perl cpan Redis-Fast 0.37 main/subtest(). 'hash functions' => sub { |
| 46 | okscip-perl cpan Redis-Fast 0.37 main/ok().(my @keys = keysscip-perl cpan Redis-Fast 0.37 main/keys().(%my_hash), 'keys ok'); |
| 47 | cmp_deeplyscip-perl cpan Redis-Fast 0.37 main/cmp_deeply().(\@keys, bagscip-perl cpan Redis-Fast 0.37 main/bag().(qw( a b c )), '... resulting list as expected'); |
| 48 | |
| 49 | okscip-perl cpan Redis-Fast 0.37 main/ok().(my @values = valuesscip-perl cpan Redis-Fast 0.37 main/values().(%my_hash), 'values ok'); |
| 50 | cmp_deeplyscip-perl cpan Redis-Fast 0.37 main/cmp_deeply().(\@values, bagscip-perl cpan Redis-Fast 0.37 main/bag().(qw( foo BAR bbb )), '... resulting list as expected'); |
| 51 | |
| 52 | %my_hash = reversescip-perl cpan Redis-Fast 0.37 main/reverse(). %my_hash; |
| 53 | cmp_deeplyscip-perl cpan Redis-Fast 0.37 main/cmp_deeply().(\%my_hash, { foo => 'a', BAR => 'b', bbb => 'c' }, 'reverse() worked'); |
| 54 | }; |
| 55 | |
| 56 | |
| 57 | ## Cleanup |
| 58 | %my_hash = (); |
| 59 | cmp_deeplyscip-perl cpan Redis-Fast 0.37 main/cmp_deeply().(\%my_hash, {}, 'empty list ok'); |
| 60 | |
| 61 | done_testingscip-perl cpan Redis-Fast 0.37 main/done_testing().(); |