From 26850da6d39de2f265ab71306059161baab1068b Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Tue, 19 Nov 2024 06:43:00 +0000 Subject: [PATCH] done testing 'j' motion; next is to test 'k' motion --- test/test.sml | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/test/test.sml b/test/test.sml index e13d9e1..1fb52d2 100644 --- a/test/test.sml +++ b/test/test.sml @@ -182,7 +182,7 @@ val lMove = describe "move motion 'l'" Expect.isTrue (oldCursorIdx = 0 andalso cursorIdx = 1) end) - , test "does not move cursor right by one when cursorIdx = length" (fn _ => + , test "does not move cursor when cursorIdx = length" (fn _ => let (* arrange *) val buffer = LineGap.fromString "hello world\n" @@ -388,6 +388,28 @@ val jMove = describe "move motion 'j'" in Expect.isTrue isAtEnd end) + + , test "leaves cursor at same idx when already at end of buffer" (fn _ => + let + (* arrange *) + val str = "hello \nworld \ntime to go\n" + val len = String.size str - 2 + val buffer = LineGap.fromString str + val app = AppType.init (buffer, 0, 0) + val app = withIdx (app, len) + + (* act *) + val ({cursorIdx, ...}, _) = AppUpdate.update (app, CHAR_EVENT #"j") + + (* assert *) + (* String.size str - 1 is a valid char position + * but we are counting String.size str - 2 as the end + * because, in Vim, saved files always end with \n + * but the last char, \n, is not visible *) + val isAtEnd = cursorIdx = len + in + Expect.isTrue isAtEnd + end) ] val wMove = describe "move motion 'w'"