From c3ca8dddf49bb84f765f7568f87bebbbb4ecbe7d Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Tue, 23 Sep 2025 13:30:54 +0100 Subject: [PATCH] add additional failing unit test for 'j' motion --- test/normal-move.sml | 51 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/test/normal-move.sml b/test/normal-move.sml index ceaf174..9df0172 100644 --- a/test/normal-move.sml +++ b/test/normal-move.sml @@ -370,22 +370,24 @@ struct Expect.isTrue (cursorIdx = 7) end) , test - "does not go to last newline in file \ + "goes to second-last newline in file \ \when newline is preceded by a non-newline" (fn _ => let (* arrange *) - val str = "hello\n\nworld\n" - val initialCursorIdx = String.size str - 2 + val str = "hello\nworld\n" + val initialCursorIdx = 4 val app = TestUtils.init str val app = AppWith.idx (app, initialCursorIdx) (* act *) - val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"j") - in + val {cursorIdx, ...} = TestUtils.updateMany (app, "2j") + (* assert *) - Expect.isTrue (cursorIdx = initialCursorIdx) + val expectedIdx = 10 + in + Expect.isTrue (cursorIdx = expectedIdx) end) , test "goes to last newline in file \ @@ -407,6 +409,43 @@ struct in Expect.isTrue (cursorIdx = expectedIdx) 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'"