add two more test cases for 'dj' motion that were failing when added, and modify 'MakeNormalDelete.deleteLineDown' to handle them
This commit is contained in:
@@ -413,7 +413,18 @@ struct
|
||||
* to the first column of the now-last line *)
|
||||
val newEndIdx = #textLength buffer - 1
|
||||
in
|
||||
if startIdx >= newEndIdx then
|
||||
if newEndIdx < 0 then
|
||||
(* deleted whole file; add newline to the end *)
|
||||
let val buffer = LineGap.append ("\n", buffer)
|
||||
in finishAfterDeletingBuffer (app, 0, buffer, time, initialMsg)
|
||||
end
|
||||
else if newEndIdx = 0 then
|
||||
(* there is only one char left in the file *)
|
||||
finishAfterDeletingBuffer (app, 0, buffer, time, initialMsg)
|
||||
else if startIdx >= newEndIdx then
|
||||
(* deleted the last part of the file such that the cursor's idx
|
||||
* now refers to an index that no longer exists.
|
||||
* Have to move cursor to the last line of the file. *)
|
||||
let
|
||||
val buffer = LineGap.goToIdx (newEndIdx, buffer)
|
||||
in
|
||||
|
||||
@@ -386,6 +386,56 @@ struct
|
||||
in
|
||||
Expect.isTrue (stringIsExpected andalso cursorIdxIsExpected)
|
||||
end)
|
||||
, test
|
||||
"leaves a newline at the end when deleting the whole file \
|
||||
\and file ends with a newline"
|
||||
(fn _ =>
|
||||
let
|
||||
(* arrange *)
|
||||
val originalString = "hello\nworld\n"
|
||||
val originalIdx = 0
|
||||
|
||||
val app = TestUtils.init originalString
|
||||
val app = AppWith.idx (app, originalIdx)
|
||||
|
||||
(* act *)
|
||||
val {cursorIdx, buffer, ...} = TestUtils.updateMany (app, "33dj")
|
||||
|
||||
(* assert *)
|
||||
val expectedString = "\n"
|
||||
val actualString = LineGap.toString buffer
|
||||
val stringIsExpected = expectedString = actualString
|
||||
|
||||
val expectedCursorIdx = 0
|
||||
val cursorIdxIsExpected = expectedCursorIdx = cursorIdx
|
||||
in
|
||||
Expect.isTrue (stringIsExpected andalso cursorIdxIsExpected)
|
||||
end)
|
||||
, test
|
||||
"leaves a newline at the end when deleting the whole file \
|
||||
\and file does not end with a newline"
|
||||
(fn _ =>
|
||||
let
|
||||
(* arrange *)
|
||||
val originalString = "hello\nworld"
|
||||
val originalIdx = 0
|
||||
|
||||
val app = TestUtils.init originalString
|
||||
val app = AppWith.idx (app, originalIdx)
|
||||
|
||||
(* act *)
|
||||
val {cursorIdx, buffer, ...} = TestUtils.updateMany (app, "33dj")
|
||||
|
||||
(* assert *)
|
||||
val expectedString = "\n"
|
||||
val actualString = LineGap.toString buffer
|
||||
val stringIsExpected = expectedString = actualString
|
||||
|
||||
val expectedCursorIdx = 0
|
||||
val cursorIdxIsExpected = expectedCursorIdx = cursorIdx
|
||||
in
|
||||
Expect.isTrue (stringIsExpected andalso cursorIdxIsExpected)
|
||||
end)
|
||||
]
|
||||
|
||||
val tests = [dhDelete, dlDelete, djDelete]
|
||||
|
||||
Reference in New Issue
Block a user