Skip to content

Commit

Permalink
Cleanup whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
jlavallee committed May 16, 2015
1 parent bc471bd commit 3e3c290
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 39 deletions.
52 changes: 25 additions & 27 deletions lib/Test/Mock/Redis.pm
Expand Up @@ -55,15 +55,15 @@ returned, with all data preserved.
=head2 new
Create a new Test::Mock::Redis object.
Create a new Test::Mock::Redis object.
It can be used in place of a Redis object for unit testing.
It accepts the "server" argument, just like Redis.pm's new.
=head2 num_databases
Redis ships with a default of 16 databases, and that's what this module
Redis ships with a default of 16 databases, and that's what this module
handles by default. If you need to change that, do
use Test::Mock::Redis num_databases => 21;
Expand Down Expand Up @@ -340,15 +340,15 @@ sub type {

my $type = ref $self->_stash->{$key};

return !$type
return !$type
? 'string'
: $type eq 'Test::Mock::Redis::Hash'
: $type eq 'Test::Mock::Redis::Hash'
? 'hash'
: $type eq 'Test::Mock::Redis::Set'
? 'set'
: $type eq 'Test::Mock::Redis::ZSet'
? 'zset'
: $type eq 'Test::Mock::Redis::List'
: $type eq 'Test::Mock::Redis::List'
? 'list'
: 'unknown'
;
Expand Down Expand Up @@ -469,7 +469,7 @@ sub lrange {
sub ltrim {
my ( $self, $key, $start, $end ) = @_;

$self->_stash->{$key} = [ @{ $self->_stash->{$key} }[$start..$end] ];
$self->_stash->{$key} = [ @{ $self->_stash->{$key} }[$start..$end] ];
return 'OK';
}

Expand Down Expand Up @@ -501,7 +501,7 @@ sub lrem {
last if $count && ++$removed >= $count;
}
}

return $removed;
}

Expand All @@ -526,7 +526,7 @@ sub select {

my $max_index = $#{ $self->{_stash} };
if ($index > $max_index ){
die "You called select($index), but max allowed is $max_index unless you configure more databases";
die "You called select($index), but max allowed is $max_index unless you configure more databases";
}

$self->{_db_index} = $index;
Expand Down Expand Up @@ -563,7 +563,7 @@ sub sismember {
my ( $self, $key, $value ) = @_;

return exists $self->_stash->{$key}->{$value}
? 1
? 1
: 0;
}

Expand Down Expand Up @@ -839,7 +839,7 @@ sub sort {

my $cmp = do
{ no warnings 'uninitialized';
$how =~ /\bALPHA\b/
$how =~ /\bALPHA\b/
? $how =~ /\bDESC\b/
? sub { $b cmp $a }
: sub { $a cmp $b }
Expand All @@ -852,18 +852,18 @@ sub sort {
return sort $cmp @{ $self->_stash->{$key} };
}

sub save {
sub save {
my $self = shift;
$self->{_last_save} = time;
return 'OK';
}

sub bgsave {
sub bgsave {
my $self = shift;
return $self->save;
}

sub lastsave {
sub lastsave {
my $self = shift;
return $self->{_last_save};
}
Expand Down Expand Up @@ -996,14 +996,12 @@ sub zrange {
my ( $self, $key, $start, $stop, $withscores ) = @_;

$stop = $self->zcard($key)-1 if $stop >= $self->zcard($key);
return map { $withscores ? ( $_, $self->zscore($key, $_) ) : $_ }

return map { $withscores ? ( $_, $self->zscore($key, $_) ) : $_ }
( map { $_->[0] }
sort { $a->[1] <=> $b->[1]
||
$a->[0] cmp $b->[0] }
sort { $a->[1] <=> $b->[1] || $a->[0] cmp $b->[0] }
map { [ $_, $self->_stash->{$key}->{$_} ] }
keys %{ $self->_stash->{$key} }
keys %{ $self->_stash->{$key} }
)[$start..$stop]
;
}
Expand All @@ -1013,11 +1011,11 @@ sub zrevrange {

$stop = $self->zcard($key)-1 if $stop >= $self->zcard($key);

return map { $withscores ? ( $_, $self->zscore($key, $_) ) : $_ }
return map { $withscores ? ( $_, $self->zscore($key, $_) ) : $_ }
( map { $_->[0] }
sort { $b->[1] <=> $a->[1] }
map { [ $_, $self->_stash->{$key}->{$_} ] }
keys %{ $self->_stash->{$key} }
keys %{ $self->_stash->{$key} }
)[$start..$stop]
;
}
Expand All @@ -1030,14 +1028,14 @@ sub zrangebyscore {

my $cmp = !$min_inc && !$max_inc
? sub { $self->zscore($key, $_[0]) > $min && $self->zscore($key, $_[0]) < $max }
: !$min_inc
: !$min_inc
? sub { $self->zscore($key, $_[0]) > $min && $self->zscore($key, $_[0]) <= $max }
: !$max_inc
: !$max_inc
? sub { $self->zscore($key, $_[0]) >= $min && $self->zscore($key, $_[0]) < $max }
: sub { $self->zscore($key, $_[0]) >= $min && $self->zscore($key, $_[0]) <= $max }
;
return map { $withscores ? ( $_, $self->zscore($key, $_) ) : $_ }

return map { $withscores ? ( $_, $self->zscore($key, $_) ) : $_ }
grep { $cmp->($_) } $self->zrange($key, 0, $self->zcard($key)-1);
}

Expand All @@ -1047,7 +1045,7 @@ sub zrevrangebyscore {

my $not_with_scores = 0;

return map { $withscores ? ( $_, $self->zscore($key, $_) ) : $_ }
return map { $withscores ? ( $_, $self->zscore($key, $_) ) : $_ }
reverse $self->zrangebyscore($key, $min, $max, $not_with_scores);
}

Expand Down Expand Up @@ -1460,7 +1458,7 @@ use strict; use warnings;
use Tie::Hash;
use base qw/Tie::StdHash/;

sub DELETE {
sub DELETE {
my ( $self, $key ) = @_;

delete $self->{$key};
Expand Down
2 changes: 1 addition & 1 deletion t/01-basic.t
Expand Up @@ -248,7 +248,7 @@ foreach my $o (@redi){
$o->zadd($zset, 1, 'bar');
ok($o->zadd($zset, 5, $_)) for @sorting_zkeys;
$o->zadd($zset, 9, 'baz');

my @sorted_zkeys = sort @sorting_zkeys;
@sorting_zkeys = ('bar', @sorting_zkeys, 'baz');
@sorted_zkeys = ('bar', @sorted_zkeys, 'baz');
Expand Down
2 changes: 1 addition & 1 deletion t/05-server.t
Expand Up @@ -8,7 +8,7 @@ use Test::Mock::Redis;


=pod
x AUTH
x AUTH
x ECHO
x PING
x QUIT
Expand Down
6 changes: 3 additions & 3 deletions t/10-hash.t
Expand Up @@ -77,7 +77,7 @@ foreach my $r (@redi){
$r->del('hash');

ok $r->hset('hash', 'foo', 'foobar'), "hset returns true when it's happy";

ok $r->hexists('hash', 'foo'), "hexists returns true when it's true";

ok ! $r->hdel('blarg', 'blorf'), "hdel on a hash that doesn't exist returns false";
Expand Down Expand Up @@ -120,7 +120,7 @@ foreach my $r (@redi){
like exception { $r->hvals('not a hash') },
qr/^\Q[hvals] ERR Operation against a key holding the wrong kind of value\E/,
"hvals on key that isn't a hash throws error";


is_deeply [ $r->hmget('hash', qw/foo bar baz/) ], [ qw/bar baz qux/ ],
"hmget returns requested values";
Expand All @@ -136,7 +136,7 @@ foreach my $r (@redi){
"hincerby dies when called with the wrong number of arguments";

like exception { $r->hincrby('hash', 'foo', 1) },
qr/^\Q[hincrby] ERR hash value is not an integer\E/,
qr/^\Q[hincrby] ERR hash value is not an integer\E/,
"hincrby dies when a non-integer is incremented";

is $r->hincrby('hash', 'incrme', 1), 1, "incrby 1 on a value that doesn't exist returns 1";
Expand Down
14 changes: 7 additions & 7 deletions t/11-sets.t
Expand Up @@ -66,7 +66,7 @@ foreach my $r (@redi){

is $r->srem('set', 'bar'), 1, "srem returns 1 when it removes an element";

is $r->sadd('set', $_), 1, "srem returns 1 when it adds a new element to the set"
is $r->sadd('set', $_), 1, "srem returns 1 when it adds a new element to the set"
for (grep { $_ ne 'foo'} @members);

is $r->type('set'), 'set', "our set has type set";
Expand All @@ -83,18 +83,18 @@ foreach my $r (@redi){
}

# set has been emptied. Put some stuff in it again
is $r->sadd('set', $_), 1, "srem returns 1 when it adds a new element to the set"
is $r->sadd('set', $_), 1, "srem returns 1 when it adds a new element to the set"
for (@members);

is $r->sadd('otherset', $_), 1, "srem returns 1 when it adds a new element to the set"
is $r->sadd('otherset', $_), 1, "srem returns 1 when it adds a new element to the set"
for (qw/foo bar baz/);

is $r->sadd('anotherset', $_), 1, "srem returns 1 when it adds a new element to the set"
is $r->sadd('anotherset', $_), 1, "srem returns 1 when it adds a new element to the set"
for (qw/bar baz qux/);

is_deeply [sort $r->sinter('set', 'otherset')], [qw/bar baz foo/], "sinter returns all members in common";

is_deeply [sort $r->sinter('set', 'otherset', 'anotherset')], [qw/bar baz/],
is_deeply [sort $r->sinter('set', 'otherset', 'anotherset')], [qw/bar baz/],
"sinter returns all members in common for multiple sets";

is_deeply [$r->sinter('set', 'emptyset')], [], "sinter returns empty list";
Expand All @@ -109,7 +109,7 @@ foreach my $r (@redi){
is $r->sinterstore('destset', 'set', 'otherset', 'anotherset'), 2, "sinterstore returns cardinality of intersection";
is_deeply [sort $r->smembers('destset')], [sort $r->sinter('set', 'otherset', 'anotherset')], "sinterstore stored the correct result";

is $r->sadd('otherset', $_), 1, "srem returns 1 when it adds a new element to the set"
is $r->sadd('otherset', $_), 1, "srem returns 1 when it adds a new element to the set"
for (qw/oink bah neigh/);

is_deeply [sort $r->sunion('set', 'otherset')], [sort @members, qw/oink bah neigh/], "sunion returns all members of two sets";
Expand Down Expand Up @@ -145,7 +145,7 @@ foreach my $r (@redi){

is $r->smove('notaset', 'otherset', 'foo'), 0, "smove returns false when source doesn't exist";

$r->set('justakey', 'foobar');
$r->set('justakey', 'foobar');

like exception { $r->smove('justakey', 'set', 'foo') },
qr/^\Q[smove] ERR Operation against a key holding the wrong kind of value\E/,
Expand Down

0 comments on commit 3e3c290

Please sign in to comment.