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