New upstream version 0.21
gregor herrmann
5 years ago
0 | 0 | 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) | |
1 | 4 | |
2 | 5 | 0.20 2017-02-03 |
3 | 6 | - support negative indicies (Gianni Ceccarelli) |
19 | 19 | t/13-multi.t |
20 | 20 | t/14-pipeline.t |
21 | 21 | t/15-import.t |
22 | t/50-lrem.t | |
22 | 23 | t/boilerplate.t |
23 | 24 | t/manifest.t |
24 | 25 | t/pod.t |
48 | 48 | "provides" : { |
49 | 49 | "Test::Mock::Redis" : { |
50 | 50 | "file" : "lib/Test/Mock/Redis.pm", |
51 | "version" : "0.20" | |
51 | "version" : "0.21" | |
52 | 52 | }, |
53 | 53 | "Test::Mock::Redis::Hash" : { |
54 | 54 | "file" : "lib/Test/Mock/Redis.pm" |
78 | 78 | "url" : "http://github.com/jlavallee/Test-Mock-Redis/" |
79 | 79 | } |
80 | 80 | }, |
81 | "version" : "0.20", | |
81 | "version" : "0.21", | |
82 | 82 | "x_serialization_backend" : "JSON::PP version 2.27300" |
83 | 83 | } |
25 | 25 | provides: |
26 | 26 | Test::Mock::Redis: |
27 | 27 | file: lib/Test/Mock/Redis.pm |
28 | version: '0.20' | |
28 | version: '0.21' | |
29 | 29 | Test::Mock::Redis::Hash: |
30 | 30 | file: lib/Test/Mock/Redis.pm |
31 | 31 | Test::Mock::Redis::List: |
46 | 46 | bugtracker: http://rt.cpan.org/NoAuth/Bugs.html?Dist=Test-Mock-Redis |
47 | 47 | license: http://dev.perl.org/licenses/ |
48 | 48 | repository: http://github.com/jlavallee/Test-Mock-Redis/ |
49 | version: '0.20' | |
49 | version: '0.21' | |
50 | 50 | x_serialization_backend: 'CPAN::Meta::YAML version 0.018' |
1 | 1 | use ExtUtils::MakeMaker; |
2 | 2 | WriteMakefile |
3 | 3 | ( |
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 | }, | |
5 | 17 | 'INSTALLDIRS' => 'site', |
6 | 18 | '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' | |
20 | 20 | ) |
21 | 21 | ; |
16 | 16 | |
17 | 17 | =head1 VERSION |
18 | 18 | |
19 | Version 0.20 | |
19 | Version 0.21 | |
20 | 20 | |
21 | 21 | =cut |
22 | 22 | |
23 | our $VERSION = '0.20'; | |
23 | our $VERSION = '0.21'; | |
24 | 24 | |
25 | 25 | =head1 SYNOPSIS |
26 | 26 | |
528 | 528 | sub lrem { |
529 | 529 | my ( $self, $key, $count, $value ) = @_; |
530 | 530 | 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; | |
535 | 533 | $count = abs $count; |
536 | 534 | |
535 | my @to_remove; | |
537 | 536 | for my $index (@indicies){ |
538 | 537 | 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; | |
541 | 541 | } |
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; | |
542 | 547 | } |
543 | 548 | |
544 | 549 | return $removed; |
1221 | 1226 | |
1222 | 1227 | =item * Nigel Gregoire |
1223 | 1228 | |
1229 | =item * Thomas Bloor | |
1230 | ||
1224 | 1231 | =item * Yaakov Shaul |
1225 | 1232 | |
1226 | 1233 | =back |
1227 | 1234 | |
1228 | 1235 | =head1 LICENSE AND COPYRIGHT |
1229 | 1236 | |
1230 | Copyright 2015 Jeff Lavallee. | |
1237 | Copyright 2018 Jeff Lavallee. | |
1231 | 1238 | |
1232 | 1239 | This program is free software; you can redistribute it and/or modify it |
1233 | 1240 | 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 |