add tests for 'dl' motion
This commit is contained in:
@@ -115,8 +115,9 @@ struct
|
|||||||
end)
|
end)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
(* 'dl' motion and 'x' motion have identical behaviour *)
|
||||||
val dlDelete = describe "delete motion 'dl'"
|
val dlDelete = describe "delete motion 'dl'"
|
||||||
[test
|
[ test
|
||||||
"deletes last char and moves cursor back by 1 \
|
"deletes last char and moves cursor back by 1 \
|
||||||
\when next char is a newline"
|
\when next char is a newline"
|
||||||
(fn _ =>
|
(fn _ =>
|
||||||
@@ -140,7 +141,79 @@ struct
|
|||||||
val cursorIdxIsExpected = expectedCursorIdx = cursorIdx
|
val cursorIdxIsExpected = expectedCursorIdx = cursorIdx
|
||||||
in
|
in
|
||||||
Expect.isTrue (stringIsExpected andalso cursorIdxIsExpected)
|
Expect.isTrue (stringIsExpected andalso cursorIdxIsExpected)
|
||||||
end)]
|
end)
|
||||||
|
, test "deletes char that cursor is currently on when not on newline"
|
||||||
|
(fn _ =>
|
||||||
|
let
|
||||||
|
(* arrange *)
|
||||||
|
val originalIdx = 0
|
||||||
|
val originalString = "hello world\n"
|
||||||
|
|
||||||
|
val app = TestUtils.init originalString
|
||||||
|
val app = AppWith.idx (app, originalIdx)
|
||||||
|
|
||||||
|
(* act *)
|
||||||
|
val {cursorIdx, buffer, ...} = TestUtils.updateMany (app, "dl")
|
||||||
|
|
||||||
|
(* assert *)
|
||||||
|
val actualString = LineGap.toString buffer
|
||||||
|
val expectedString = "ello world\n"
|
||||||
|
val stringIsExpected = actualString = expectedString
|
||||||
|
|
||||||
|
val expectedCursorIdx = 0
|
||||||
|
val cursorIdxIsExpected = cursorIdx = expectedCursorIdx
|
||||||
|
in
|
||||||
|
Expect.isTrue (stringIsExpected andalso cursorIdxIsExpected)
|
||||||
|
end)
|
||||||
|
, test "does not delete any characters or move the cursor when on a newline"
|
||||||
|
(fn _ =>
|
||||||
|
let
|
||||||
|
(* arrange *)
|
||||||
|
val originalIdx = 5
|
||||||
|
val originalString = "hello\n\nworld\n"
|
||||||
|
|
||||||
|
val app = TestUtils.init originalString
|
||||||
|
val app = AppWith.idx (app, originalIdx)
|
||||||
|
|
||||||
|
(* act *)
|
||||||
|
val {cursorIdx, buffer, ...} = TestUtils.updateMany (app, "dl")
|
||||||
|
|
||||||
|
(* assert *)
|
||||||
|
val actualString = LineGap.toString buffer
|
||||||
|
val expectedString = originalString
|
||||||
|
val stringIsExpected = actualString = expectedString
|
||||||
|
|
||||||
|
val expectedCursorIdx = originalIdx
|
||||||
|
val cursorIdxIsExpected = cursorIdx = expectedCursorIdx
|
||||||
|
in
|
||||||
|
Expect.isTrue (stringIsExpected andalso cursorIdxIsExpected)
|
||||||
|
end)
|
||||||
|
, test
|
||||||
|
"does not delete past newline when specifying a range \
|
||||||
|
\greater than number of columns"
|
||||||
|
(fn _ =>
|
||||||
|
let
|
||||||
|
(* arrange *)
|
||||||
|
val originalIdx = 2
|
||||||
|
val originalString = "hello\nworld\n"
|
||||||
|
|
||||||
|
val app = TestUtils.init originalString
|
||||||
|
val app = AppWith.idx (app, originalIdx)
|
||||||
|
|
||||||
|
(* act *)
|
||||||
|
val {cursorIdx, buffer, ...} = TestUtils.updateMany (app, "33dl")
|
||||||
|
|
||||||
|
(* assert *)
|
||||||
|
val actualString = LineGap.toString buffer
|
||||||
|
val expectedString = "he\nworld\n"
|
||||||
|
val stringIsExpected = actualString = expectedString
|
||||||
|
|
||||||
|
val expectedCursorIdx = 1
|
||||||
|
val cursorIdxIsExpected = cursorIdx = expectedCursorIdx
|
||||||
|
in
|
||||||
|
Expect.isTrue (stringIsExpected)
|
||||||
|
end)
|
||||||
|
]
|
||||||
|
|
||||||
val tests = [dhDelete, dlDelete]
|
val tests = [dhDelete, dlDelete]
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user