diff options
| -rw-r--r-- | incdec.pm | 19 | ||||
| -rw-r--r-- | t/100-increment-decrement.t | 6 |
2 files changed, 25 insertions, 0 deletions
@@ -10,12 +10,31 @@ sub incdec { $is_backward ||= 0; my $start_position = 0; + my @points = (); + my $previous_match_start = 0; while ($line =~ /(\d+)/g) { + if ($is_backward) { + $previous_match_start = $-[0]; + + # if $point_position < $-[0] + # && previous $+[0] <= $point_position + # if ($point_position >= $-[0]) { + # $start_position = $-[0]; + # + # last; + # } + } + else { if ($point_position < $+[0]) { $start_position = $-[0]; last; } + } + } + + if ($is_backward) { + $start_position = $previous_match_start; } pos($line) = $start_position; diff --git a/t/100-increment-decrement.t b/t/100-increment-decrement.t index ee7aee9..b234f83 100644 --- a/t/100-increment-decrement.t +++ b/t/100-increment-decrement.t @@ -55,4 +55,10 @@ is( 'increments the fourth double-digit integer with point at position 16' ); +is( + incdec::incdec('test 12 19 555 64', 17, 1), + 'test 12 19 555 65', + 'increments the fourth double-digit integer with point at position 16 backward' +); + done_testing; |
