From de8f5b77611fe3baa3c6ca3fe788999476765272 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Thu, 25 Sep 2025 09:19:15 +0100 Subject: [PATCH] add a few more tests for 'dk' motion --- test/normal-delete.sml | 85 +++++++++++++++++++++++++++++++++--------- 1 file changed, 68 insertions(+), 17 deletions(-) diff --git a/test/normal-delete.sml b/test/normal-delete.sml index d29353c..f78ebc1 100644 --- a/test/normal-delete.sml +++ b/test/normal-delete.sml @@ -634,27 +634,78 @@ struct Expect.isTrue (expectedString = actualString andalso expectedIdx = cursorIdx) end) - , test "deletes first two lines when cursor is on second line" (fn _ => - let - (* arrange *) - val originalString = "hello\nworld\n" - val originalIdx = 6 + , test + "deletes first two lines, leaving a newline in the buffer \ + \ when there are two lines \and cursor is on second line" + (fn _ => + let + (* arrange *) + val originalString = "hello\nworld\n" + val originalIdx = 6 - val app = TestUtils.init originalString - val app = AppWith.idx (app, originalIdx) + val app = TestUtils.init originalString + val app = AppWith.idx (app, originalIdx) - (* act *) - val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "dk") + (* act *) + val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "dk") - (* assert *) - val expectedString = "\n" - val actualString = LineGap.toString buffer + (* assert *) + val expectedString = "\n" + val actualString = LineGap.toString buffer - val expectedIdx = 0 - in - Expect.isTrue - (expectedString = actualString andalso expectedIdx = cursorIdx) - end) + val expectedIdx = 0 + in + Expect.isTrue + (expectedString = actualString andalso expectedIdx = cursorIdx) + end) + , test + "deletes last two lines when there are three lines in the buffer \ + \ and cursor is on third line" + (fn _ => + let + (* arrange *) + val originalString = "hello\nworld\nagain\n" + val originalIdx = 15 + + val app = TestUtils.init originalString + val app = AppWith.idx (app, originalIdx) + + (* act *) + val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "dk") + + (* assert *) + val expectedString = "hello\n" + val actualString = LineGap.toString buffer + + val expectedIdx = 0 + in + Expect.isTrue + (expectedString = actualString andalso expectedIdx = cursorIdx) + end) + , test + "leaves a buffer containing just a newline when\ + \deleting from last line with a counter greater than total lines" + (fn _ => + let + (* arrange *) + val originalString = "hello\nworld\nagain\n" + val originalIdx = 15 + + val app = TestUtils.init originalString + val app = AppWith.idx (app, originalIdx) + + (* act *) + val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "33dk") + + (* assert *) + val expectedString = "\n" + val actualString = LineGap.toString buffer + + val expectedIdx = 0 + in + Expect.isTrue + (expectedString = actualString andalso expectedIdx = cursorIdx) + end) ] val tests = [dhDelete, dlDelete, djDelete, ddDelete, dkDelete]