Permalink
Browse files

implements sidelen

  • Loading branch information...
1 parent 12d46bc commit dd989025e54b4788378e8f61507ebdffc87006f9 HyunSeung Kim committed Apr 25, 2012
Showing with 13 additions and 2 deletions.
  1. +6 −0 lib/Template/Reverse.pm
  2. +7 −2 t/03-1-reverse-detect-sidelen.t
@@ -80,6 +80,9 @@ sub _detect{
{
my $from = $lastStar;
my $to = $i-1;
+ if( $sidelen ){
+ $from = $to-$sidelen+1 if $to-$from+1 > $sidelen;
+ }
my @pre = map{substr($_,1);}@d[$from..$to];
my $j = @d;
@@ -93,6 +96,9 @@ sub _detect{
}
$from = $i+1;
$to = $j-1;
+ if( $sidelen ){
+ $to = $from + $sidelen-1 if $to-$from+1 > $sidelen;
+ }
my @post = map{substr($_,1);}@d[$from..$to];
push(@res,[\@pre,\@post]);
@@ -6,7 +6,9 @@ use_ok('Template::Reverse');
use Data::Dumper;
sub detect{
my $diff= shift;
- return Template::Reverse::_detect($diff, 3);
+ my $r = Template::Reverse::_detect($diff, 3);
+ print Dumper $r;
+ return $r;
}
@diff = qw(-A -B -C -D -E);
@@ -29,11 +31,14 @@ ok( eq_array($patt, [ [[],[qw(B C D)]] ] ) );
$patt = detect(\@diff);
ok( eq_array($patt, [ [[qw(A)],[qw(C)]], [[qw(C)],[qw(E)]]] ) );
-
@diff = qw(-A -B -C * -G -H -I -J -K * -M -N);
$patt = detect(\@diff);
ok( eq_array($patt, [ [[qw(A B C)],[qw(G H I)]], [[qw(I J K)],[qw(M N)]]] ) );
+@diff = qw(-Q -A -B -C * -G -H -I -J -K * -M -N -O -P);
+$patt = detect(\@diff);
+ok( eq_array($patt, [ [[qw(A B C)],[qw(G H I)]], [[qw(I J K)],[qw(M N O)]]] ) );
+
@diff = qw(* -A -B -C * -G -H -I -J -K * -M -N * );
$patt = detect(\@diff);
ok( eq_array($patt, [ [[],[qw(A B C)]],[[qw(A B C)],[qw(G H I)]], [[qw(I J K)],[qw(M N)]], [[qw(M N)],[]]] ) );

0 comments on commit dd98902

Please sign in to comment.