add some more tests for 'df<char' motion, and fix implementation to pass those tests (if our cursor is at the same position after calling 'fMove', then exit the loop to find the next occurrence of <char>)

This commit is contained in:
2025-10-17 16:19:17 +01:00
parent 09c9a92029
commit b8beeaaa60
3 changed files with 69 additions and 21 deletions

View File

@@ -677,34 +677,38 @@ struct
deleteAndFinish (app, low, length, buffer, time) deleteAndFinish (app, low, length, buffer, time)
end end
fun finishDeleteToChr (app, buffer, cursorIdx, otherIdx, time) =
let
val low = Int.min (cursorIdx, otherIdx)
val high = Int.max (cursorIdx, otherIdx)
val length = high - low
in
deleteAndFinish (app, low, length, buffer, time)
end
fun helpDeleteToChr fun helpDeleteToChr
(app: app_type, buffer, cursorIdx, otherIdx, count, fMove, fInc, chr, time) = (app: app_type, buffer, cursorIdx, otherIdx, count, fMove, fInc, chr, time) =
if count = 0 then if count = 0 then
let finishDeleteToChr (app, buffer, cursorIdx, otherIdx, time)
val low = Int.min (cursorIdx, otherIdx)
val high = Int.max (cursorIdx, otherIdx)
val length = high - low
in
deleteAndFinish (app, low, length, buffer, time)
end
else else
let let
val buffer = LineGap.goToIdx (otherIdx, buffer) val buffer = LineGap.goToIdx (otherIdx, buffer)
val newOtherIdx = fMove (buffer, otherIdx, chr) val newOtherIdx = fMove (buffer, otherIdx, chr)
val newCount = if newOtherIdx = otherIdx then 0 else count - 1
val newOtherIdx = fInc (newOtherIdx, 1)
in in
helpDeleteToChr if otherIdx = newOtherIdx then
( app finishDeleteToChr (app, buffer, cursorIdx, otherIdx, time)
, buffer else
, cursorIdx helpDeleteToChr
, newOtherIdx ( app
, newCount , buffer
, fMove , cursorIdx
, fInc , fInc (newOtherIdx, 1)
, chr , count - 1
, time , fMove
) , fInc
, chr
, time
)
end end
fun deleteToChr (app: app_type, count, fMove, fInc, chr, time) = fun deleteToChr (app: app_type, count, fMove, fInc, chr, time) =

View File

@@ -3531,6 +3531,51 @@ struct
(actualString = expectedString (actualString = expectedString
andalso cursorIdx = expectedCursorIdx) andalso cursorIdx = expectedCursorIdx)
end) end)
, test
"deletes from cursor's position to second occurrence of <char> \
\if motion has a count of 2"
(fn _ =>
let
(* arrange *)
val originalString = "hello\nworld\n"
val app = TestUtils.init originalString
val app = AppWith.idx (app, 0)
(* act *)
val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "2dfo")
(* assert *)
val actualString = LineGap.toString buffer
val expectedString = "rld\n"
val expectedCursorIdx = 0
in
Expect.isTrue
(actualString = expectedString
andalso cursorIdx = expectedCursorIdx)
end)
, test
"deletes from cursor's position to last occurrence of <char> \
\if motion has a count greater than \
\the number of occurences of <char>, after the cursor"
(fn _ =>
let
(* arrange *)
val originalString = "hello\nworld\n"
val app = TestUtils.init originalString
val app = AppWith.idx (app, 0)
(* act *)
val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "99dfl")
(* assert *)
val actualString = LineGap.toString buffer
val expectedString = "d\n"
val expectedCursorIdx = 0
in
Expect.isTrue
(actualString = expectedString
andalso cursorIdx = expectedCursorIdx)
end)
] ]
val tests = val tests =

View File

@@ -1,7 +1,6 @@
# To-do list # To-do list
- Add tests for: - Add tests for:
- `df<char>`
- `dF<char>` - `dF<char>`
- `dt<char>` - `dt<char>`
- `dT<char>` - `dT<char>`