add tests for 'dl' motion

This commit is contained in:
2025-09-21 00:34:02 +01:00
parent 6af2b58b0f
commit 68cd2a33cf

View File

@@ -115,32 +115,105 @@ 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 _ =>
let let
(* arrange *) (* arrange *)
val originalString = "hello\nworld\n" val originalString = "hello\nworld\n"
val originalIdx = 4 val originalIdx = 4
val app = TestUtils.init originalString val app = TestUtils.init originalString
val app = AppWith.idx (app, originalIdx) val app = AppWith.idx (app, originalIdx)
(* act *) (* act *)
val {cursorIdx, buffer, ...} = TestUtils.updateMany (app, "dl") val {cursorIdx, buffer, ...} = TestUtils.updateMany (app, "dl")
(* assert *) (* assert *)
val expectedString = "hell\nworld\n" val expectedString = "hell\nworld\n"
val actualString = LineGap.toString buffer val actualString = LineGap.toString buffer
val stringIsExpected = expectedString = actualString val stringIsExpected = expectedString = actualString
val expectedCursorIdx = originalIdx - 1 val expectedCursorIdx = originalIdx - 1
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