lookbehind before context, so page increment is _upto_ context rows
authorMischa POSLAWSKY <perl@shiar.org>
Fri, 13 Nov 2009 14:59:30 +0000 (15:59 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Fri, 13 Nov 2009 14:59:30 +0000 (15:59 +0100)
lib/List/Index.pm
t/10-ranges.t

index 5b46313d7272168dea172ddf5135ce9ef480dae0..4a2118910cf3708c11ada4bc07644930a33f3486 100644 (file)
@@ -28,9 +28,9 @@ sub ranges {
        while ($offset < @$self) {
                my $link = substr $self->[$offset], 0, $length;
                if ($context) {
-                       {
+                       if ($offset > $context - 1) {
                                # take a value slightly before the current offset
-                               my $before = $offset > $context ? $self->[$offset - $context] : '.';
+                               my $before = $self->[$offset - $context - 1];
                                # see how much of it matches the current link
                                my $trim = 1;
                                for my $match (split //, $before) {
index 1ec5d60da6a76e5fdc7ddffc68bc39bd4aaeafba..ef292b1f55ab67a4b110d19ffde6462093d0bc98 100644 (file)
@@ -29,7 +29,7 @@ subtest 'uniform alphanumeric' => sub {
                .-bp bq-dm dn-fi fj-hf hg-i j-k l-m n-os ot-qp qq-sm sn-uj uk-wf wg-x y-
 
        )], 'default ranges');
-       is_deeply($index->ranges({pagesize => 300}), [qw(-c d-o p-)], 'large pagesize');
+       is_deeply($index->ranges({pagesize => 300}), [qw(-c d-n o-)], 'large pagesize');
 };
 
 subtest 'context' => sub {
@@ -41,12 +41,12 @@ subtest 'context' => sub {
                qw(-baa. baa.-bbb bbc-daa. daaa-eaa. eaaa-)
        ], 'no context');
        is_deeply($index->ranges({pagesize => 2}), [
-               qw(-a b c d-ea. eaa-)
+               qw(-a b c d e-)
        ], 'default context');  # context should be 1
        is_deeply($index->ranges({pagesize => 2, context => 2}), [
                qw(-a b-c d e-)
        ], 'overlap');  # first item equals second due to large context
-       is_deeply($index->ranges({pagesize => 2, length => 1}), [
+       is_deeply($index->ranges({pagesize => 2, context => 0, length => 1}), [
                qw(-a b-c d e-)
        ], 'single char');