add additional failing unit test for 'j' motion

This commit is contained in:
2025-09-23 13:30:54 +01:00
parent 109fda187a
commit c3ca8dddf4

View File

@@ -370,22 +370,24 @@ struct
Expect.isTrue (cursorIdx = 7) Expect.isTrue (cursorIdx = 7)
end) end)
, test , test
"does not go to last newline in file \ "goes to second-last newline in file \
\when newline is preceded by a non-newline" \when newline is preceded by a non-newline"
(fn _ => (fn _ =>
let let
(* arrange *) (* arrange *)
val str = "hello\n\nworld\n" val str = "hello\nworld\n"
val initialCursorIdx = String.size str - 2 val initialCursorIdx = 4
val app = TestUtils.init str val app = TestUtils.init str
val app = AppWith.idx (app, initialCursorIdx) val app = AppWith.idx (app, initialCursorIdx)
(* act *) (* act *)
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"j") val {cursorIdx, ...} = TestUtils.updateMany (app, "2j")
in
(* assert *) (* assert *)
Expect.isTrue (cursorIdx = initialCursorIdx) val expectedIdx = 10
in
Expect.isTrue (cursorIdx = expectedIdx)
end) end)
, test , test
"goes to last newline in file \ "goes to last newline in file \
@@ -407,6 +409,43 @@ struct
in in
Expect.isTrue (cursorIdx = expectedIdx) Expect.isTrue (cursorIdx = expectedIdx)
end) end)
, test "goes to last char in file when last char is not a newline" (fn _ =>
let
(* arrange *)
val str = "hello\nworld"
val initialCursorIdx = 6
val app = TestUtils.init str
val app = AppWith.idx (app, initialCursorIdx)
(* act *)
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"j")
(* assert *)
val expectedIdx = String.size str - 1
in
Expect.isTrue (cursorIdx = expectedIdx)
end)
, test
"leaves cursor at same idx when on last line \
\and file ends with a non-newline"
(fn _ =>
let
(* arrange *)
val str = "hello\nworld"
val initialCursorIdx = 6
val app = TestUtils.init str
val app = AppWith.idx (app, initialCursorIdx)
(* act *)
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"j")
(* assert *)
val expectedIdx = initialCursorIdx
in
Expect.isTrue (cursorIdx = expectedIdx)
end)
] ]
val kMove = describe "move motion 'k'" val kMove = describe "move motion 'k'"