+++: rangematch() fixes
authorMischa POSLAWSKY <perl@shiar.org>
Wed, 11 Nov 2009 03:03:31 +0000 (04:03 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Wed, 11 Nov 2009 03:03:31 +0000 (04:03 +0100)
lib/List/Index.pm
t/20-links.t

index 6a818bb23ec78e766a0c808c52681a38260142ec..89fdc75c83fa3c7b8709734f6b0403aeee087048 100644 (file)
@@ -65,8 +65,8 @@ sub rangematch {
                        $c1 = substr $s1, $i, 1;
                        my $c2 = length $s2 <= $i ? undef : substr $s2, $i, 1;
                        my $next = $i + 1 >= length($s1) ? $c1 : chr( ord($c1) + 1 );
-                       $next le $c2 or next if defined $c2;
                        my $last = defined $c2 && $i == 0 ? chr( ord($c2) - (length $s2 > 1) ) : 'z';
+                       $next le $last or next if defined $c2;
                        push @allow, $prefix."[$next-$last]";
                }
                continue {
index 89f5dee223c90c0e1027ee04a6336fffadbaaa43..6a093145f265fb45b02a665a655a975e93e96d17 100644 (file)
@@ -2,8 +2,9 @@
 use strict;
 use warnings;
 
-use Test::More tests => 13;
+use Test::More tests => 18;
 use Test::NoWarnings;
+use Data::Dump 'pp';
 
 BEGIN { use_ok('List::Index' => 'rangematch'); }
 
@@ -15,9 +16,14 @@ for (
        [  'q-'    =>    '[q-z]'],
        ['qqq-'    => '(?:[r-z]|q[r-z]|qq[q-z])'],
        [  'q-x'   =>    '[q-x]'],
+       [  'q-q'   =>    '[q-q]'],
+       [ 'qq-qq'  =>                 'qq'],
+       [ 'qq-qqx' =>                                    'qq(?![x-z])|qqx'],
+       [  'q-qx'  =>                      '(?:q(?![x-z])|qx)'],
        ['qqq-xxx' => '(?:[r-w]|q[r-z]|qq[q-z]|x(?![x-z])|xx(?![x-z])|xxx)'],
        ['qqq-x'   => '(?:[r-x]|q[r-z]|qq[q-z])'],
        ['qqq-q'   =>       '(?:q[r-z]|qq[q-z])'],
+       ['qaa-qb'  =>              '(?:qa[a-z]|q(?![b-z]))'],
        [  'q-xxx' =>                '(?:[q-w]|x(?![x-z])|xx(?![x-z])|xxx)'],
 ) {
        my ($in, $out) = @$_;