3 |
use warnings; |
use warnings; |
4 |
use strict; |
use strict; |
5 |
|
|
6 |
use Test::More tests => 42; |
use Test::More tests => 66; |
7 |
|
|
8 |
use lib 'lib'; |
use lib 'lib'; |
9 |
|
|
26 |
|
|
27 |
cmp_ok( $o->get( 'foo' ), 'eq', 'baz', 'get foo = baz' ); |
cmp_ok( $o->get( 'foo' ), 'eq', 'baz', 'get foo = baz' ); |
28 |
|
|
29 |
|
$o->del('non-existant'); |
30 |
|
|
31 |
ok( ! $o->exists( 'non-existant' ), 'exists non-existant' ); |
ok( ! $o->exists( 'non-existant' ), 'exists non-existant' ); |
32 |
ok( ! $o->get( 'non-existant' ), 'get non-existant' ); |
ok( ! $o->get( 'non-existant' ), 'get non-existant' ); |
33 |
|
|
37 |
|
|
38 |
ok( $o->set('key-left' => $key_next), 'key-left' ); |
ok( $o->set('key-left' => $key_next), 'key-left' ); |
39 |
|
|
40 |
|
my @keys; |
41 |
|
|
42 |
foreach ( 0 .. $key_next ) { |
foreach ( 0 .. $key_next ) { |
43 |
ok( $o->set( "key-$_" => $_ ), "set key-$_" ); |
my $key = 'key-' . $_; |
44 |
ok( $o->exists( "key-$_" ), "exists key-$_" ); |
push @keys, $key; |
45 |
cmp_ok( $o->get( "key-$_" ), 'eq', $_, "get key-$_" ); |
ok( $o->set( $key => $_ ), "set $key" ); |
46 |
|
ok( $o->exists( $key ), "exists $key" ); |
47 |
|
cmp_ok( $o->get( $key ), 'eq', $_, "get $key" ); |
48 |
cmp_ok( $o->incr( 'key-next' ), '==', $_ + 1, 'incr' ); |
cmp_ok( $o->incr( 'key-next' ), '==', $_ + 1, 'incr' ); |
49 |
cmp_ok( $o->decr( 'key-left' ), '==', $key_next - $_ - 1, 'decr' ); |
cmp_ok( $o->decr( 'key-left' ), '==', $key_next - $_ - 1, 'decr' ); |
50 |
} |
} |
58 |
cmp_ok( $o->decr('test-decrby', 7), '==', -( $_ * 7 ), 'decrby 7' ); |
cmp_ok( $o->decr('test-decrby', 7), '==', -( $_ * 7 ), 'decrby 7' ); |
59 |
} |
} |
60 |
|
|
61 |
|
ok( $o->del( $_ ), "del $_" ) foreach map { "key-$_" } ( 'next', 'left' ); |
62 |
|
ok( ! $o->del('non-existing' ), 'del non-existing' ); |
63 |
|
|
64 |
|
cmp_ok( $o->type('foo'), 'eq', 'string', 'type' ); |
65 |
|
|
66 |
|
cmp_ok( $o->keys('key-*'), '==', $key_next + 1, 'key-*' ); |
67 |
|
is_deeply( [ $o->keys('key-*') ], [ @keys ], 'keys' ); |
68 |
|
|
69 |
|
ok( my $key = $o->randomkey, 'randomkey' ); |
70 |
|
diag "key: $key"; |
71 |
|
|
72 |
|
ok( $o->rename( 'test-incrby', 'test-renamed' ), 'rename' ); |
73 |
|
ok( $o->exists( 'test-renamed' ), 'exists test-renamed' ); |
74 |
|
|
75 |
|
eval { $o->rename( 'test-decrby', 'test-renamed', 1 ) }; |
76 |
|
ok( $@, 'rename to existing key' ); |
77 |
|
|
78 |
|
ok( my $nr_keys = $o->dbsize, 'dbsize' ); |
79 |
|
diag "dbsize: $nr_keys"; |
80 |
|
|
81 |
|
diag "Commands operating on lists"; |
82 |
|
|
83 |
|
my $list = 'test-list'; |
84 |
|
|
85 |
|
$o->del($list) && diag "cleanup $list from last run"; |
86 |
|
|
87 |
|
ok( $o->rpush( $list => "r$_" ), 'rpush' ) foreach ( 1 .. 3 ); |
88 |
|
|
89 |
|
ok( $o->lpush( $list => "l$_" ), 'lpush' ) foreach ( 1 .. 2 ); |
90 |
|
|
91 |
|
cmp_ok( $o->llen($list), '==', 5, 'llen' ); |
92 |
|
|
93 |
|
is_deeply( [ $o->lrange( $list, 0, 1 ) ], [ 'l2', 'l1' ], 'lrange' ); |
94 |
|
|
95 |
|
ok( $o->ltrim( $list, 1, 2 ), 'ltrim' ); |
96 |
|
cmp_ok( $o->llen($list), '==', 2, 'llen after ltrim' ); |
97 |
|
|
98 |
|
cmp_ok( $o->lindex( $list, 0 ), 'eq', 'l1', 'lindex' ); |
99 |
|
cmp_ok( $o->lindex( $list, 1 ), 'eq', 'r1', 'lindex' ); |
100 |
|
|
101 |
|
ok( $o->lset( $list, 0, 'foo' ), 'lset' ); |
102 |
|
cmp_ok( $o->lindex( $list, 0 ), 'eq', 'foo', 'verified' ); |
103 |
|
|
104 |
ok( $o->quit, 'quit' ); |
ok( $o->quit, 'quit' ); |