+++: numbers first
authorMischa POSLAWSKY <perl@shiar.org>
Wed, 11 Nov 2009 16:15:22 +0000 (17:15 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Thu, 12 Nov 2009 16:10:39 +0000 (17:10 +0100)
lib/List/Index.pm
t/10-ranges.t

index c42db44eadb5be52310a3ec76b54df640eb06209..50e48a5eb30f71d6b3abaefe77bcbd2a09b9cfa7 100644 (file)
@@ -29,7 +29,7 @@ sub ranges {
                my $link = substr $self->[$offset], 0, $length;
                if ($context) {
                        my $trim = 1;
-                       my $before = $offset > $context ? $self->[$offset - $context] : '';
+                       my $before = $offset > $context ? $self->[$offset - $context] : '.';
                        for my $match (split //, $before) {
                                scalar $link =~ /\G\Q$match/g or last;
                                $trim++;
@@ -43,8 +43,8 @@ sub ranges {
 
        for my $i (0 .. $#links - 1) {
                my ($link, $lastchar) = $links[$i + 1]->[0] =~ /(.*)(.)/;
-               $link .= $lastchar eq '.' ? 'a' : chr( ord($lastchar) - 1 )
-                       unless $lastchar eq 'a';
+               $link .= $lastchar eq 'a' ? '.' : chr( ord($lastchar) - 1 )
+                       unless $lastchar eq '.';
                $links[$i]->[1] = $link;
        }
        $links[-1]->[1] = '';
index eaae0e993483293b41abefdc6e28dcc70fe2a686..c5cc3e6b881614d4f158c698b34053972c674fab 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(
-       .-.a ..-.a ..-..a ...-
+       .-. ..-. ..-.. ...-.
        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(
@@ -38,10 +38,10 @@ ok(my $index = List::Index->new([qw(
        baa1 baa2  baa3 baaa  bbc cbc  daaa ea  eaaa zed
 )]), 'variable length values');
 is_deeply($index->ranges({pagesize => 2, context => 0}), [
-       map { [split /-/, $_, 2] } qw(baa.-baaa baa.-bbb bbc-daa daaa-eaa eaaa-)
+       map { [split /-/, $_, 2] } qw(baa.-baa baa.-bbb bbc-daa. daaa-eaa. eaaa-)
 ], 'no context');
 is_deeply($index->ranges({pagesize => 2}), [
-       map { [split /-/, $_, 2] } qw(b-baaa baa.-ba bb-c d-ea eaa-)
+       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-)