XXX: omit range end if it equals start
authorMischa POSLAWSKY <perl@shiar.org>
Thu, 12 Nov 2009 16:15:32 +0000 (17:15 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Thu, 12 Nov 2009 17:21:32 +0000 (18:21 +0100)
lib/List/Index.pm
t/10-ranges.t

index 50e48a5eb30f71d6b3abaefe77bcbd2a09b9cfa7..00f2bdb29e976de666f8bd8579cc56b88ca4552d 100644 (file)
@@ -45,6 +45,7 @@ sub ranges {
                my ($link, $lastchar) = $links[$i + 1]->[0] =~ /(.*)(.)/;
                $link .= $lastchar eq 'a' ? '.' : chr( ord($lastchar) - 1 )
                        unless $lastchar eq '.';
                my ($link, $lastchar) = $links[$i + 1]->[0] =~ /(.*)(.)/;
                $link .= $lastchar eq 'a' ? '.' : chr( ord($lastchar) - 1 )
                        unless $lastchar eq '.';
+               next if $link eq $links[$i]->[0];
                $links[$i]->[1] = $link;
        }
        $links[-1]->[1] = '';
                $links[$i]->[1] = $link;
        }
        $links[-1]->[1] = '';
index c5cc3e6b881614d4f158c698b34053972c674fab..feedb14fc4d87c234888a192d271ad920e5f6749 100644 (file)
@@ -25,7 +25,7 @@ is_deeply($index->ranges({pagesize => @uniform / 2.1}), [map { [split /-/, $_, 2
 {
 ok(my $index = List::Index->new(['aa'..'zz', 1..193]), 'non-alphabetic values (uniform)');
 is_deeply($index->ranges, [map { [split /-/, $_, 2] } qw(
 {
 ok(my $index = List::Index->new(['aa'..'zz', 1..193]), 'non-alphabetic values (uniform)');
 is_deeply($index->ranges, [map { [split /-/, $_, 2] } qw(
-       .-. ..-. ..-.. ...-.
+       . ..-. .. ...-.
        a-bv bw-dr ds-fn fo-hk hl-jg jh-k l-m n-ov ow-qr qs-sn so-uk ul-wg wh-x y-
 )], 'default ranges');
 is_deeply($index->ranges({pagesize => 300}), [map { [split /-/, $_, 2] } qw(
        a-bv bw-dr ds-fn fo-hk hl-jg jh-k l-m n-ov ow-qr qs-sn so-uk ul-wg wh-x y-
 )], 'default ranges');
 is_deeply($index->ranges({pagesize => 300}), [map { [split /-/, $_, 2] } qw(
@@ -44,10 +44,10 @@ is_deeply($index->ranges({pagesize => 2}), [
        map { [split /-/, $_, 2] } qw(b-baa baa.-ba bb-c d-ea. eaa-)
 ], 'default context');  # context should be 1
 is_deeply($index->ranges({pagesize => 2, context => 2}), [
        map { [split /-/, $_, 2] } qw(b-baa baa.-ba bb-c d-ea. eaa-)
 ], 'default context');  # context should be 1
 is_deeply($index->ranges({pagesize => 2, context => 2}), [
-       map { [split /-/, $_, 2] } qw(b-a b-ba bb-c d-d e-)
+       map { [split /-/, $_, 2] } qw(b-a b-ba bb-c d e-)
 ], 'overlap');  # first item equals second due to large context
 is_deeply($index->ranges({pagesize => 2, length => 1}), [
 ], 'overlap');  # first item equals second due to large context
 is_deeply($index->ranges({pagesize => 2, length => 1}), [
-       map { [split /-/, $_, 2] } qw(b-a b-a b-c d-d e-)
+       map { [split /-/, $_, 2] } qw(b-a b-a b-c d e-)
 ], 'single char');
 
 #pp($index->ranges({pagesize => 2, context => 2, length => 1}));
 ], 'single char');
 
 #pp($index->ranges({pagesize => 2, context => 2, length => 1}));