From 46ab3d20e7d621435629678aa6bf10dc511a2daa Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Sat, 20 Sep 2025 23:49:30 +0100 Subject: [PATCH] add tests to verify that cursorIdx is as expected after 'dh' delete motion --- test/normal-delete.sml | 60 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/test/normal-delete.sml b/test/normal-delete.sml index ffc1fc3..3aa32a2 100644 --- a/test/normal-delete.sml +++ b/test/normal-delete.sml @@ -53,6 +53,66 @@ struct 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]