aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2021-08-15 19:47:18 +0200
committerTeddy Wing2021-08-15 19:53:21 +0200
commit43eed8f077a6af734adb92f7999a6cdeff0715dd (patch)
treee51dcaa6780108d94cc8de673c1a8d5af95bf801
parent24495f6638809ca7d0db9ec6984a7c413abd2a58 (diff)
downloadreadline-incdec-43eed8f077a6af734adb92f7999a6cdeff0715dd.tar.bz2
incdec: Correctly handle middle-of-number point for third number
We were previously using values specific to the first and second numbers in the line. Get middle-of-number point handling working for the third number in the line, and hopefully the rest as well.
-rw-r--r--incdec.pm4
-rw-r--r--t/100-increment-decrement.t6
2 files changed, 8 insertions, 2 deletions
diff --git a/incdec.pm b/incdec.pm
index 3f4c8ef..bcf62e0 100644
--- a/incdec.pm
+++ b/incdec.pm
@@ -25,10 +25,10 @@ sub incdec {
}
if ($point_position >= $+[0]) {
- $line_start .= substr($line_part, $previous_point_position, $+[0]);
+ $line_start .= substr($line_part, 0, $+[0]);
$line_part = substr($line_part, $+[0]);
$previous_point_position = $point_position;
- $point_position = 0;
+ $point_position -= $+[0];
next;
}
diff --git a/t/100-increment-decrement.t b/t/100-increment-decrement.t
index e7feccb..ee7aee9 100644
--- a/t/100-increment-decrement.t
+++ b/t/100-increment-decrement.t
@@ -49,4 +49,10 @@ is(
'increments the third triple-digit integer with point at position 12'
);
+is(
+ incdec::incdec('test 12 19 555 64', 16),
+ 'test 12 19 555 65',
+ 'increments the fourth double-digit integer with point at position 16'
+);
+
done_testing;