~ubuntu-branches/ubuntu/oneiric/libanyevent-redis-perl/oneiric

« back to all changes in this revision

Viewing changes to t/lrange.t

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghedini
  • Date: 2011-02-09 19:31:48 UTC
  • Revision ID: james.westby@ubuntu.com-20110209193148-asa3jeyaol6nikd2
Tags: upstream-0.23
ImportĀ upstreamĀ versionĀ 0.23

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
use strict;
 
2
use Test::More;
 
3
use t::Redis;
 
4
 
 
5
test_redis {
 
6
    my $r = shift;
 
7
 
 
8
    for my $n(1 .. 10) {
 
9
      my $key1 = "lrange_test1_$n";
 
10
      my $key2 = "lrange_test2_$n";
 
11
 
 
12
      $r->del($key1);
 
13
      $r->del($key2);
 
14
 
 
15
      for (1 .. 20) {
 
16
        $r->rpush($key1, join "\n", map {"A" x 100} (0 .. 3));
 
17
        $r->rpush($key2, join "\n", map {"B" x 100} (0 .. 3));
 
18
      }
 
19
      for (1 .. 20) {
 
20
        $r->rpush($key1, join "\n", map {"C" x 100} (0 .. 3));
 
21
        $r->rpush($key2, join "\n", map {"D" x 100} (0 .. 3));
 
22
      }
 
23
 
 
24
      $r->all_cv->begin;
 
25
      $r->lrange($key1, 0, 19, sub {
 
26
          my $value = join "\n", map {"A" x 100} (0 .. 3);
 
27
          is scalar @{$_[0]}, 20, "correct length $key1 0 19";
 
28
          is $_[0][-1], $value, "correct end value $key1 0 19";
 
29
          is $_[0][0], $value, "correct start value $key1 0 19";
 
30
          $r->all_cv->end;
 
31
      });
 
32
 
 
33
      $r->all_cv->begin;
 
34
      $r->lrange($key2, 0, 19, sub {
 
35
          my $value = join "\n", map {"B" x 100} (0 .. 3);
 
36
          is scalar @{$_[0]}, 20, "correct length $key2 0 19";
 
37
          is $_[0][-1], $value, "correct end value $key2 0 19";
 
38
          is $_[0][0], $value, "correct start value $key2 0 19";
 
39
          $r->all_cv->end;
 
40
      });
 
41
 
 
42
      $r->all_cv->begin;
 
43
      $r->lrange($key1, 20, 39, sub {
 
44
          my $value = join "\n", map {"C" x 100} (0 .. 3);
 
45
          is scalar @{$_[0]}, 20, "correct length $key1 20 39";
 
46
          is $_[0][-1], $value, "correct end value $key1 20 39";
 
47
          is $_[0][0], $value, "correct start value $key1 20 39";
 
48
          $r->del($key1, sub { $r->all_cv->end });
 
49
      });
 
50
 
 
51
      $r->all_cv->begin;
 
52
      $r->lrange($key2, 20, 39, sub {
 
53
          my $value = join "\n", map {"D" x 100} (0 .. 3);
 
54
          is scalar @{$_[0]}, 20, "correct length $key2 20 39";
 
55
          is $_[0][-1], $value, "correct end value $key2 20 39";
 
56
          is $_[0][0], $value, "correct start value $key2 20 39";
 
57
          $r->del($key2, sub { $r->all_cv->end });
 
58
      });
 
59
    }
 
60
 
 
61
    $r->all_cv->recv;
 
62
};
 
63
done_testing;