fix corner case where #items-1 == #pages
authorMischa POSLAWSKY <perl@shiar.org>
Tue, 17 Nov 2009 17:16:01 +0000 (18:16 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 17 Nov 2009 17:16:01 +0000 (18:16 +0100)
lib/List/Index.pm
t/10-ranges.t

index f58e43e572be60f55bf05f972ea70ea97d5d7883..35f0549e288cd999cab4e5238cf6b8c142d7b17e 100644 (file)
@@ -24,9 +24,9 @@ sub ranges {
        my $pagesize = $options->{pagesize} || 50;
        my $context  = $options->{context } // 1 + ($pagesize >> 4);
        my $length   = $options->{length  } || 4;
        my $pagesize = $options->{pagesize} || 50;
        my $context  = $options->{context } // 1 + ($pagesize >> 4);
        my $length   = $options->{length  } || 4;
-       my $pages    = $options->{pages   } || 1 + int $#rows / $pagesize;
+       my $pages    = $options->{pages   } || 1 + int($#rows / $pagesize);
 
 
-       $pagesize = $pages >= $#rows ? 1 : @rows / $pages;
+       $pagesize = $pages >= @rows ? 1 : @rows / $pages;
        my $shrunk = 0;
        my $enlarged = 0;
 
        my $shrunk = 0;
        my $enlarged = 0;
 
index 5c994c1946293bc36e1320c106b958a481b7d352..3a465b83eddec8950eab27790d12dc7be1660de2 100644 (file)
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 
 use strict;
 use warnings;
 
-use Test::More tests => 9;
+use Test::More tests => 10;
 use Test::NoWarnings;
 use Data::Dump 'pp';
 
 use Test::NoWarnings;
 use Data::Dump 'pp';
 
@@ -165,6 +165,16 @@ subtest 'modulo' => sub {
        );
 };
 
        );
 };
 
+subtest 'corner cases' => sub {
+       plan tests => 1;
+
+       is_deeply(
+               List::Index->new->ranges(['foo','bar']),
+               ['-'],
+               '2 rows 1 page'
+       );
+};
+
 subtest 'context' => sub {
        plan tests => 4;
        my @data = qw( baa1 baa2  baa3 baaa  bbc cbc  daaa ea  eaaa zed );
 subtest 'context' => sub {
        plan tests => 4;
        my @data = qw( baa1 baa2  baa3 baaa  bbc cbc  daaa ea  eaaa zed );