+++: penalty
authorMischa POSLAWSKY <perl@shiar.org>
Sat, 14 Nov 2009 19:00:34 +0000 (20:00 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 14 Nov 2009 19:00:45 +0000 (20:00 +0100)
lib/List/Index.pm
t/10-ranges.t

index 06c27273fcbd67193e9eb4f751ab280a93f0a8ac..339bd7d8710b6ede1e44fef6b207d28e0e26f766 100644 (file)
@@ -55,9 +55,10 @@ sub ranges {
                                # use this link if it's shorter
                                if ($trim < length $link) {
                                        $link = substr $after, 0, $trim;
-#                                      $offset += $context + 1;
-                                       $self->[$offset + ++$penalty] =~ /^\Q$link/
-                                               while $offset + $penalty < $#$self;
+                                       for ($offset .. $#$self) {
+                                               last if $self->[$offset + $penalty] =~ /^\Q$link/;
+                                               $penalty++;
+                                       }
                                }
                        }
                }
index f935820eaf99904bb4007478b3b3c51be8eb568b..d96ebb528ef1358cf82646d9c238eba1fb149e19 100644 (file)
@@ -54,14 +54,12 @@ subtest 'context' => sub {
 };
 
 subtest 'distribution' => sub {
-       plan tests => 2;
+       plan tests => 3;
        my $index = List::Index->new([qw(
                kkeg kl km kmlu knsy    koxb kpeo kuaa kuab kuac
                kuap kuaq kuq kux kzb   lc lg lgu lgua lguc
                lguq lgur lgus lgx lka  lkq lks lln llq llx
        )]) or return;
-TODO: {
-       local $TODO = 'under development';
        is_deeply(
                $index->ranges({ pagesize=>10, context=>3 }),
                # shorten 'kuap' to 'ku' because lookbehind is 'kp...'
@@ -69,11 +67,18 @@ TODO: {
                [qw(-kt ku-lgt lgu-)],
                'lookbehind'
        );
-}
        is_deeply(
                $index->ranges({ pagesize=>10, context=>4 }),
                [qw(-kt ku-lf lg-)],
                'maximal lookahead'
        );
+       is_deeply(
+               $index->ranges({ pagesize=>10, context=>5 }),
+               # after forwarding 'kuap' to 'lc'
+               # disallow backtracking of 'lguq' to 'lc' to prevent qw[-k l-]
+               # so only lookahead (to 'lkq') remains
+               [qw(-k l-lj lk-)],
+               'lookbehind after full lookahead'
+       );
 }