Codebase list libtest-mock-redis-perl / fcacf22
New upstream version 0.21 gregor herrmann 5 years ago
7 changed file(s) with 119 addition(s) and 27 deletion(s). Raw diff Collapse all Expand all
00 Revision history for Perl module Test::Mock::Redis
1
2 0.21 2018-12-19
3 - fix lrem issue with array length changing (Thomas Bloor)
14
25 0.20 2017-02-03
36 - support negative indicies (Gianni Ceccarelli)
1919 t/13-multi.t
2020 t/14-pipeline.t
2121 t/15-import.t
22 t/50-lrem.t
2223 t/boilerplate.t
2324 t/manifest.t
2425 t/pod.t
4848 "provides" : {
4949 "Test::Mock::Redis" : {
5050 "file" : "lib/Test/Mock/Redis.pm",
51 "version" : "0.20"
51 "version" : "0.21"
5252 },
5353 "Test::Mock::Redis::Hash" : {
5454 "file" : "lib/Test/Mock/Redis.pm"
7878 "url" : "http://github.com/jlavallee/Test-Mock-Redis/"
7979 }
8080 },
81 "version" : "0.20",
81 "version" : "0.21",
8282 "x_serialization_backend" : "JSON::PP version 2.27300"
8383 }
2525 provides:
2626 Test::Mock::Redis:
2727 file: lib/Test/Mock/Redis.pm
28 version: '0.20'
28 version: '0.21'
2929 Test::Mock::Redis::Hash:
3030 file: lib/Test/Mock/Redis.pm
3131 Test::Mock::Redis::List:
4646 bugtracker: http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-Mock-Redis
4747 license: http://dev.perl.org/licenses/
4848 repository: http://github.com/jlavallee/Test-Mock-Redis/
49 version: '0.20'
49 version: '0.21'
5050 x_serialization_backend: 'CPAN::Meta::YAML version 0.018'
11 use ExtUtils::MakeMaker;
22 WriteMakefile
33 (
4 'NAME' => 'Test::Mock::Redis',
4 'EXE_FILES' => [],
5 'PL_FILES' => {},
6 'PREREQ_PM' => {
7 'namespace::clean' => 0,
8 'Test::Deep::UnorderedPairs' => 0,
9 'Test::More' => '0.88',
10 'Scalar::Util' => 0,
11 'Test::Fatal' => 0,
12 'Try::Tiny' => 0,
13 'Class::Method::Modifiers' => 0,
14 'Test::Deep' => 0,
15 'Package::Stash' => '0.34'
16 },
517 'INSTALLDIRS' => 'site',
618 'VERSION_FROM' => 'lib/Test/Mock/Redis.pm',
7 'PL_FILES' => {},
8 'EXE_FILES' => [],
9 'PREREQ_PM' => {
10 'Test::Deep::UnorderedPairs' => 0,
11 'Try::Tiny' => 0,
12 'Class::Method::Modifiers' => 0,
13 'Test::More' => '0.88',
14 'Scalar::Util' => 0,
15 'Test::Deep' => 0,
16 'namespace::clean' => 0,
17 'Test::Fatal' => 0,
18 'Package::Stash' => '0.34'
19 }
19 'NAME' => 'Test::Mock::Redis'
2020 )
2121 ;
1616
1717 =head1 VERSION
1818
19 Version 0.20
19 Version 0.21
2020
2121 =cut
2222
23 our $VERSION = '0.20';
23 our $VERSION = '0.21';
2424
2525 =head1 SYNOPSIS
2626
528528 sub lrem {
529529 my ( $self, $key, $count, $value ) = @_;
530530 my $removed;
531 my @indicies = $count < 0
532 ? ($#{ $self->_stash->{$key} }..0)
533 : (0..$#{ $self->_stash->{$key} })
534 ;
531 my @indicies = (0..$#{ $self->_stash->{$key} });
532 @indicies = reverse @indicies if $count < 0;
535533 $count = abs $count;
536534
535 my @to_remove;
537536 for my $index (@indicies){
538537 if($self->_stash->{$key}->[$index] eq $value){
539 splice @{ $self->_stash->{$key} }, $index, 1;
540 last if $count && ++$removed >= $count;
538 push @to_remove, $index;
539 $removed++;
540 last if $count && $removed >= $count;
541541 }
542 }
543
544 # reverse sort so that the higher indecies are removed first
545 for my $rm_idx (sort { $b <=> $a } @to_remove){
546 splice @{ $self->_stash->{$key} }, $rm_idx, 1;
542547 }
543548
544549 return $removed;
12211226
12221227 =item * Nigel Gregoire
12231228
1229 =item * Thomas Bloor
1230
12241231 =item * Yaakov Shaul
12251232
12261233 =back
12271234
12281235 =head1 LICENSE AND COPYRIGHT
12291236
1230 Copyright 2015 Jeff Lavallee.
1237 Copyright 2018 Jeff Lavallee.
12311238
12321239 This program is free software; you can redistribute it and/or modify it
12331240 under the terms of either: the GNU General Public License as published
0 #!perl
1
2 use warnings;
3 use strict;
4 use lib 't/tlib';
5 use Test::More;
6 use Test::Fatal;
7 use Test::Mock::Redis;
8
9 ok(my $r = Test::Mock::Redis->new, 'pretended to connect to our test redis-server');
10 my @redi = ($r);
11
12 my ( $guard, $srv );
13 if( $ENV{RELEASE_TESTING} ){
14 use_ok("Redis");
15 use_ok("Test::SpawnRedisServer");
16 ($guard, $srv) = redis();
17 ok(my $r = Redis->new(server => $srv), 'connected to our test redis-server');
18 $r->flushall;
19 unshift @redi, $r
20 }
21
22 foreach my $o (@redi){
23 diag("testing $o") if $ENV{RELEASE_TESTING};
24
25 my @lists = ( qw/ forward backward all / );
26
27 for my $lname ( @lists ) {
28 $o->rpush($lname, 'hello');
29 $o->rpush($lname, 'hello');
30 $o->rpush($lname, 'foo');
31 $o->rpush($lname, 'hello');
32
33 is_deeply(
34 [ $o->lrange($lname, 0, -1) ],
35 [ qw/
36 hello
37 hello
38 foo
39 hello
40 / ],
41 "list $lname as expected"
42 );
43 }
44
45 is( $o->lrem('forward', 2, 'hello'), 2, 'two removed from forward list' );
46
47 is_deeply(
48 [ $o->lrange('forward', 0, -1) ],
49 [ qw/
50 foo
51 hello
52 / ],
53 'forward list as expected'
54 );
55
56 is( $o->lrem('backward', -2, 'hello'), 2, 'two removed from backward list' );
57
58 is_deeply(
59 [ $o->lrange('backward', 0, -1) ],
60 [ qw/
61 hello
62 foo
63 / ],
64 'backward list as expected'
65 );
66
67 is( $o->lrem('all', 0, 'hello'), 3, '3 removed from all list' );
68
69 is_deeply(
70 [ $o->lrange('all', 0, -1) ],
71 [ qw/
72 foo
73 / ],
74 'all list as expected'
75 );
76 }
77
78
79 done_testing;
80