Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added a better synopsis; * fix: added the POP method; * improved test suite. Signed-off-by: Pedro Melo <melo@simplicidade.org>
- Loading branch information
Showing
3 changed files
with
109 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,75 @@ | ||
#!/usr/bin/perl | ||
#!perl | ||
|
||
use warnings; | ||
use strict; | ||
use Test::More; | ||
use Redis::List; | ||
use lib 't/tlib'; | ||
use Test::SpawnRedisServer; | ||
|
||
use Test::More tests => 8; | ||
use lib 'lib'; | ||
my ($guard, $srv) = redis(); | ||
|
||
BEGIN { | ||
use_ok('Redis::List'); | ||
} | ||
## Setup | ||
my @my_list; | ||
ok(my $redis = tie(@my_list, 'Redis::List', 'my_list', server => $srv), | ||
'tied to our test redis-server'); | ||
ok($redis->ping, 'pinged fine'); | ||
isa_ok($redis, 'Redis::List'); | ||
|
||
my @a; | ||
|
||
ok(my $o = tie(@a, 'Redis::List', 'test-redis-list'), 'tie'); | ||
## Direct access | ||
subtest 'direct access' => sub { | ||
@my_list = (); | ||
is_deeply(\@my_list, [], 'empty list ok'); | ||
|
||
isa_ok($o, 'Redis::List'); | ||
@my_list = ('foo', 'bar', 'baz'); | ||
is_deeply(\@my_list, ['foo', 'bar', 'baz'], 'Set multiple values ok'); | ||
|
||
$o->CLEAR; | ||
$my_list[1] = 'BAR'; | ||
is_deeply(\@my_list, ['foo', 'BAR', 'baz'], 'Set single value ok'); | ||
|
||
ok(!@a, 'empty list'); | ||
is($my_list[2]++, 'baz', 'get single value ok'); | ||
is(++$my_list[2], 'bbb', '... even with post/pre-increments'); | ||
}; | ||
|
||
ok(@a = ('foo', 'bar', 'baz'), '='); | ||
is_deeply([@a], ['foo', 'bar', 'baz']); | ||
|
||
ok(push(@a, 'push'), 'push'); | ||
is_deeply([@a], ['foo', 'bar', 'baz', 'push']); | ||
## List functions | ||
subtest 'list functions' => sub { | ||
my $v; | ||
|
||
ok($v = shift(@my_list), 'shift ok'); | ||
is($v, 'foo', '... expected value'); | ||
is_deeply(\@my_list, ['BAR', 'bbb'], '... resulting list as expected'); | ||
|
||
ok(push(@my_list, $v), 'push ok'); | ||
is_deeply( | ||
\@my_list, | ||
['BAR', 'bbb', 'foo'], | ||
'... resulting list as expected' | ||
); | ||
|
||
ok($v = pop(@my_list), 'pop ok'); | ||
is($v, 'foo', '... expected value'); | ||
is_deeply(\@my_list, ['BAR', 'bbb'], '... resulting list as expected'); | ||
|
||
ok(unshift(@my_list, $v), 'unshift ok'); | ||
is_deeply( | ||
\@my_list, | ||
['foo', 'BAR', 'bbb'], | ||
'... resulting list as expected' | ||
); | ||
|
||
ok(my @s = splice(@my_list, 1, 2), 'splice ok'); | ||
is_deeply([@s], ['BAR', 'bbb'], '... resulting list as expected'); | ||
is_deeply( | ||
\@my_list, | ||
['foo', 'BAR', 'bbb'],'... original list as expected' | ||
); | ||
}; | ||
|
||
|
||
## Cleanup | ||
@my_list = (); | ||
is_deeply(\@my_list, [], 'empty list ok'); | ||
|
||
done_testing(); |