Files
sml-projects/test/normal-delete.sml

120 lines
3.7 KiB
Standard ML

structure NormalDelete =
struct
open Railroad
open Railroad.Test
open InputMsg
val dhDelete = describe "delete motion 'dh'"
[ test "does not delete when cursor is at index 0" (fn _ =>
let
(* arrange *)
val originalString = "hello world\n"
val app = TestUtils.init originalString
val app = AppWith.idx (app, 0)
(* act *)
val app = TestUtils.updateMany (app, "dh")
(* assert *)
val expectedString = originalString
val actualString = LineGap.toString (#buffer app)
in
Expect.isTrue (expectedString = actualString)
end)
, test "does not delete when character before cursor is a newline" (fn _ =>
let
(* arrange *)
val originalString = "hello\nworld\n"
val app = TestUtils.init originalString
val app = AppWith.idx (app, 6)
(* act *)
val app = TestUtils.updateMany (app, "dh")
(* assert *)
val expectedString = originalString
val actualString = LineGap.toString (#buffer app)
in
Expect.isTrue (expectedString = actualString)
end)
, test "deletes one char to the left when on a non-newline" (fn _ =>
let
(* arrange *)
val originalString = "hello world\n"
val app = TestUtils.init originalString
val app = AppWith.idx (app, 5)
(* act *)
val app = TestUtils.updateMany (app, "dh")
(* assert *)
val expectedString = "hell world\n"
val actualString = LineGap.toString (#buffer app)
in
Expect.isTrue (expectedString = actualString)
end)
, test "moves cursor left by one after deleting left char" (fn _ =>
let
(* arrange *)
val originalIdx = 5
val originalString = "hello world\n"
val app = TestUtils.init originalString
val app = AppWith.idx (app, originalIdx)
(* act *)
val {cursorIdx, ...} = TestUtils.updateMany (app, "dh")
in
(* assert *)
Expect.isTrue (cursorIdx = originalIdx - 1)
end)
, test "deletes 3 chars and moves cursor left by 3 when count is 3" (fn _ =>
let
(* arrange *)
val originalIdx = 5
val originalString = "hello world\n"
val app = TestUtils.init originalString
val app = AppWith.idx (app, originalIdx)
(* act *)
val {cursorIdx, buffer, ...} = TestUtils.updateMany (app, "3dh")
(* assert *)
val expectedString = "he world\n"
val deleted3CharsInString = expectedString = LineGap.toString buffer
val cursorIdxIsDecrementedBy3 = cursorIdx = originalIdx - 3
in
Expect.isTrue
(cursorIdxIsDecrementedBy3 andalso deleted3CharsInString)
end)
, test
"deletes until start column when \
\count is greater than current column"
(fn _ =>
let
(* arrange *)
val originalIdx = 5
val originalString = "hello world\n"
val app = TestUtils.init originalString
val app = AppWith.idx (app, originalIdx)
(* act *)
val {cursorIdx, buffer, ...} = TestUtils.updateMany (app, "9dh")
(* assert *)
val actualString = LineGap.toString buffer
val expectedString = " world\n"
val stringIsExpected = actualString = expectedString
val expectedCursorIdx = 0
val cursorIdxIsExpected = cursorIdx = expectedCursorIdx
in
Expect.isTrue (stringIsExpected andalso cursorIdxIsExpected)
end)
]
val tests = [dhDelete]
end