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:
@@ -677,9 +677,7 @@ struct
|
||||
deleteAndFinish (app, low, length, buffer, time)
|
||||
end
|
||||
|
||||
fun helpDeleteToChr
|
||||
(app: app_type, buffer, cursorIdx, otherIdx, count, fMove, fInc, chr, time) =
|
||||
if count = 0 then
|
||||
fun finishDeleteToChr (app, buffer, cursorIdx, otherIdx, time) =
|
||||
let
|
||||
val low = Int.min (cursorIdx, otherIdx)
|
||||
val high = Int.max (cursorIdx, otherIdx)
|
||||
@@ -687,19 +685,25 @@ struct
|
||||
in
|
||||
deleteAndFinish (app, low, length, buffer, time)
|
||||
end
|
||||
|
||||
fun helpDeleteToChr
|
||||
(app: app_type, buffer, cursorIdx, otherIdx, count, fMove, fInc, chr, time) =
|
||||
if count = 0 then
|
||||
finishDeleteToChr (app, buffer, cursorIdx, otherIdx, time)
|
||||
else
|
||||
let
|
||||
val buffer = LineGap.goToIdx (otherIdx, buffer)
|
||||
val newOtherIdx = fMove (buffer, otherIdx, chr)
|
||||
val newCount = if newOtherIdx = otherIdx then 0 else count - 1
|
||||
val newOtherIdx = fInc (newOtherIdx, 1)
|
||||
in
|
||||
if otherIdx = newOtherIdx then
|
||||
finishDeleteToChr (app, buffer, cursorIdx, otherIdx, time)
|
||||
else
|
||||
helpDeleteToChr
|
||||
( app
|
||||
, buffer
|
||||
, cursorIdx
|
||||
, newOtherIdx
|
||||
, newCount
|
||||
, fInc (newOtherIdx, 1)
|
||||
, count - 1
|
||||
, fMove
|
||||
, fInc
|
||||
, chr
|
||||
|
||||
@@ -3531,6 +3531,51 @@ struct
|
||||
(actualString = expectedString
|
||||
andalso cursorIdx = expectedCursorIdx)
|
||||
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 =
|
||||
|
||||
Reference in New Issue
Block a user