add tests for 'dgg' motion
This commit is contained in:
@@ -72,7 +72,6 @@ struct
|
|||||||
finishAfterDeletingBuffer (app, startIdx, buffer, time, initialMsg)
|
finishAfterDeletingBuffer (app, startIdx, buffer, time, initialMsg)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
(* equivalent of vi's 'x' command **)
|
(* equivalent of vi's 'x' command **)
|
||||||
fun removeChr (app: app_type, count, time) =
|
fun removeChr (app: app_type, count, time) =
|
||||||
let
|
let
|
||||||
@@ -727,6 +726,11 @@ struct
|
|||||||
val initialMsg = Fn.initMsgs (0, cursorIdx, buffer)
|
val initialMsg = Fn.initMsgs (0, cursorIdx, buffer)
|
||||||
|
|
||||||
val buffer = LineGap.delete (0, cursorIdx, buffer)
|
val buffer = LineGap.delete (0, cursorIdx, buffer)
|
||||||
|
val buffer =
|
||||||
|
if #textLength buffer = 0 then
|
||||||
|
LineGap.fromString "\n"
|
||||||
|
else
|
||||||
|
buffer
|
||||||
val buffer = LineGap.goToStart buffer
|
val buffer = LineGap.goToStart buffer
|
||||||
val initialMsg = SEARCH (buffer, dfa, time) :: initialMsg
|
val initialMsg = SEARCH (buffer, dfa, time) :: initialMsg
|
||||||
|
|
||||||
|
|||||||
@@ -2690,6 +2690,117 @@ struct
|
|||||||
end)
|
end)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
val dggDelete = describe "delete motion 'dgg'"
|
||||||
|
[ test "leaves newline behind when deleting from last line" (fn _ =>
|
||||||
|
let
|
||||||
|
(* arrange *)
|
||||||
|
val originalString = "hello\nworld\n"
|
||||||
|
val app = TestUtils.init originalString
|
||||||
|
val app = AppWith.idx (app, 7)
|
||||||
|
|
||||||
|
(* act *)
|
||||||
|
val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "dgg")
|
||||||
|
|
||||||
|
(* assert *)
|
||||||
|
val actualString = LineGap.toString buffer
|
||||||
|
val expectedString = "\n"
|
||||||
|
val expectedCursorIdx = 0
|
||||||
|
in
|
||||||
|
Expect.isTrue
|
||||||
|
(actualString = expectedString andalso cursorIdx = expectedCursorIdx)
|
||||||
|
end)
|
||||||
|
, test
|
||||||
|
"deletes whole line that cursor is currently on, \
|
||||||
|
\and all lines preceding cursor"
|
||||||
|
(fn _ =>
|
||||||
|
let
|
||||||
|
(* arrange *)
|
||||||
|
val originalString = "hello\nworld\nagain\n"
|
||||||
|
val app = TestUtils.init originalString
|
||||||
|
val app = AppWith.idx (app, 7)
|
||||||
|
|
||||||
|
(* act *)
|
||||||
|
val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "dgg")
|
||||||
|
|
||||||
|
(* assert *)
|
||||||
|
val expectedString = "again\n"
|
||||||
|
val actualString = LineGap.toString buffer
|
||||||
|
|
||||||
|
val expectedCursurIdx = 0
|
||||||
|
|
||||||
|
val stringIsExpected = expectedString = actualString
|
||||||
|
val cursorIsExpected = expectedCursurIdx = cursorIdx
|
||||||
|
in
|
||||||
|
Expect.isTrue (stringIsExpected andalso cursorIsExpected)
|
||||||
|
end)
|
||||||
|
, test
|
||||||
|
"deletes current line and preceding lines \
|
||||||
|
\when current line does not end with a newline"
|
||||||
|
(fn _ =>
|
||||||
|
let
|
||||||
|
(* arrange *)
|
||||||
|
val originalString = "hello\nworld"
|
||||||
|
val app = TestUtils.init originalString
|
||||||
|
val app = AppWith.idx (app, 7)
|
||||||
|
|
||||||
|
(* act *)
|
||||||
|
val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "dgg")
|
||||||
|
|
||||||
|
(* assert *)
|
||||||
|
val actualString = LineGap.toString buffer
|
||||||
|
val expectedString = "\n"
|
||||||
|
val expectedCursorIdx = 0
|
||||||
|
in
|
||||||
|
Expect.isTrue
|
||||||
|
(actualString = expectedString
|
||||||
|
andalso cursorIdx = expectedCursorIdx)
|
||||||
|
end)
|
||||||
|
, test
|
||||||
|
"deletes current line and preceding line \
|
||||||
|
\when cursor is on a newline preceded by a newline"
|
||||||
|
(fn _ =>
|
||||||
|
let
|
||||||
|
(* arrange *)
|
||||||
|
val originalString = "\n\nhello world\n"
|
||||||
|
val app = TestUtils.init originalString
|
||||||
|
val app = AppWith.idx (app, 1)
|
||||||
|
|
||||||
|
(* act *)
|
||||||
|
val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "dgg")
|
||||||
|
|
||||||
|
(* assert *)
|
||||||
|
val actualString = LineGap.toString buffer
|
||||||
|
val expectedString = "hello world\n"
|
||||||
|
val expectedCursorIdx = 0
|
||||||
|
in
|
||||||
|
Expect.isTrue
|
||||||
|
(actualString = expectedString
|
||||||
|
andalso cursorIdx = expectedCursorIdx)
|
||||||
|
end)
|
||||||
|
, test
|
||||||
|
"deletes current line and preceding line \
|
||||||
|
\when cursor is on a newline, followed by another newline"
|
||||||
|
(fn _ =>
|
||||||
|
let
|
||||||
|
(* arrange *)
|
||||||
|
val originalString = "\n\n\nhello world\n"
|
||||||
|
val app = TestUtils.init originalString
|
||||||
|
val app = AppWith.idx (app, 1)
|
||||||
|
|
||||||
|
(* act *)
|
||||||
|
val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "dgg")
|
||||||
|
|
||||||
|
(* assert *)
|
||||||
|
val actualString = LineGap.toString buffer
|
||||||
|
val expectedString = "\nhello world\n"
|
||||||
|
val expectedCursorIdx = 0
|
||||||
|
in
|
||||||
|
Expect.isTrue
|
||||||
|
(actualString = expectedString
|
||||||
|
andalso cursorIdx = expectedCursorIdx)
|
||||||
|
end)
|
||||||
|
]
|
||||||
|
|
||||||
val tests =
|
val tests =
|
||||||
[ dhDelete
|
[ dhDelete
|
||||||
, dlDelete
|
, dlDelete
|
||||||
@@ -2704,5 +2815,6 @@ struct
|
|||||||
, dBDelete
|
, dBDelete
|
||||||
, dgeDelete
|
, dgeDelete
|
||||||
, dgEDelete
|
, dgEDelete
|
||||||
|
, dggDelete
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user