/[Redis.pre-github]/t/01-Redis.t
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /t/01-Redis.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 27 - (hide annotations)
Sun Mar 22 13:44:19 2009 UTC (10 years, 4 months ago) by dpavlin
File MIME type: application/x-troff
File size: 3028 byte(s)
lpop, rpop
1 dpavlin 2 #!/usr/bin/perl
2    
3     use warnings;
4     use strict;
5    
6 dpavlin 27 use Test::More tests => 71;
7 dpavlin 2
8     use lib 'lib';
9    
10     BEGIN {
11     use_ok( 'Redis' );
12     }
13    
14     ok( my $o = Redis->new(), 'new' );
15    
16     ok( $o->ping, 'ping' );
17    
18 dpavlin 5 ok( $o->set( foo => 'bar' ), 'set foo => bar' );
19 dpavlin 3
20 dpavlin 5 eval { $o->set( foo => 'bar', 1 ) };
21     ok( $@, 'set foo => bar new again failed' );
22    
23     cmp_ok( $o->get( 'foo' ), 'eq', 'bar', 'get foo = bar' );
24    
25     ok( $o->set( foo => 'baz' ), 'set foo => baz' );
26    
27     cmp_ok( $o->get( 'foo' ), 'eq', 'baz', 'get foo = baz' );
28    
29 dpavlin 10 $o->del('non-existant');
30    
31 dpavlin 9 ok( ! $o->exists( 'non-existant' ), 'exists non-existant' );
32 dpavlin 4 ok( ! $o->get( 'non-existant' ), 'get non-existant' );
33    
34 dpavlin 7 ok( $o->set('key-next' => 0), 'key-next = 0' );
35    
36     my $key_next = 3;
37    
38 dpavlin 8 ok( $o->set('key-left' => $key_next), 'key-left' );
39    
40 dpavlin 12 my @keys;
41    
42 dpavlin 7 foreach ( 0 .. $key_next ) {
43 dpavlin 12 my $key = 'key-' . $_;
44     push @keys, $key;
45     ok( $o->set( $key => $_ ), "set $key" );
46     ok( $o->exists( $key ), "exists $key" );
47     cmp_ok( $o->get( $key ), 'eq', $_, "get $key" );
48 dpavlin 7 cmp_ok( $o->incr( 'key-next' ), '==', $_ + 1, 'incr' );
49 dpavlin 8 cmp_ok( $o->decr( 'key-left' ), '==', $key_next - $_ - 1, 'decr' );
50 dpavlin 4 }
51    
52 dpavlin 7 cmp_ok( $o->get( 'key-next' ), '==', $key_next + 1, 'key-next' );
53    
54     ok( $o->set('test-incrby', 0), 'test-incrby' );
55 dpavlin 8 ok( $o->set('test-decrby', 0), 'test-decry' );
56 dpavlin 7 foreach ( 1 .. 3 ) {
57     cmp_ok( $o->incr('test-incrby', 3), '==', $_ * 3, 'incrby 3' );
58 dpavlin 8 cmp_ok( $o->decr('test-decrby', 7), '==', -( $_ * 7 ), 'decrby 7' );
59 dpavlin 7 }
60    
61 dpavlin 12 ok( $o->del( $_ ), "del $_" ) foreach map { "key-$_" } ( 'next', 'left' );
62     ok( ! $o->del('non-existing' ), 'del non-existing' );
63 dpavlin 10
64 dpavlin 11 cmp_ok( $o->type('foo'), 'eq', 'string', 'type' );
65    
66 dpavlin 12 cmp_ok( $o->keys('key-*'), '==', $key_next + 1, 'key-*' );
67     is_deeply( [ $o->keys('key-*') ], [ @keys ], 'keys' );
68    
69 dpavlin 13 ok( my $key = $o->randomkey, 'randomkey' );
70     diag "key: $key";
71    
72 dpavlin 16 ok( $o->rename( 'test-incrby', 'test-renamed' ), 'rename' );
73 dpavlin 14 ok( $o->exists( 'test-renamed' ), 'exists test-renamed' );
74    
75 dpavlin 16 eval { $o->rename( 'test-decrby', 'test-renamed', 1 ) };
76 dpavlin 14 ok( $@, 'rename to existing key' );
77    
78 dpavlin 17 ok( my $nr_keys = $o->dbsize, 'dbsize' );
79     diag "dbsize: $nr_keys";
80    
81 dpavlin 18 diag "Commands operating on lists";
82    
83 dpavlin 22 my $list = 'test-list';
84 dpavlin 18
85 dpavlin 22 $o->del($list) && diag "cleanup $list from last run";
86 dpavlin 18
87 dpavlin 22 ok( $o->rpush( $list => "r$_" ), 'rpush' ) foreach ( 1 .. 3 );
88 dpavlin 18
89 dpavlin 22 ok( $o->lpush( $list => "l$_" ), 'lpush' ) foreach ( 1 .. 2 );
90 dpavlin 18
91 dpavlin 25 cmp_ok( $o->type($list), 'eq', 'list', 'type' );
92 dpavlin 22 cmp_ok( $o->llen($list), '==', 5, 'llen' );
93    
94     is_deeply( [ $o->lrange( $list, 0, 1 ) ], [ 'l2', 'l1' ], 'lrange' );
95    
96 dpavlin 23 ok( $o->ltrim( $list, 1, 2 ), 'ltrim' );
97 dpavlin 22 cmp_ok( $o->llen($list), '==', 2, 'llen after ltrim' );
98    
99 dpavlin 23 cmp_ok( $o->lindex( $list, 0 ), 'eq', 'l1', 'lindex' );
100     cmp_ok( $o->lindex( $list, 1 ), 'eq', 'r1', 'lindex' );
101    
102 dpavlin 24 ok( $o->lset( $list, 0, 'foo' ), 'lset' );
103     cmp_ok( $o->lindex( $list, 0 ), 'eq', 'foo', 'verified' );
104    
105 dpavlin 26 ok( $o->lrem( $list, 1, 'foo' ), 'lrem' );
106     cmp_ok( $o->llen( $list ), '==', 1, 'llen after lrem' );
107    
108 dpavlin 27 cmp_ok( $o->lpop( $list ), 'eq', 'r1', 'lpop' );
109    
110     ok( ! $o->rpop( $list ), 'rpop' );
111    
112 dpavlin 2 ok( $o->quit, 'quit' );

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26