From 09c9a920294d7e2b540d4a3895f96d9068203e8e Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Fri, 17 Oct 2025 15:56:08 +0100 Subject: [PATCH] add tests for 'df' motion. Some fail and need the implementation to be fixed. --- temp.txt | 4 +- test/normal-delete.sml | 91 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 3 deletions(-) diff --git a/temp.txt b/temp.txt index 6cb2dae..3b18e51 100644 --- a/temp.txt +++ b/temp.txt @@ -1,3 +1 @@ -hello - -world +hello world diff --git a/test/normal-delete.sml b/test/normal-delete.sml index 009ecab..586c511 100644 --- a/test/normal-delete.sml +++ b/test/normal-delete.sml @@ -3443,6 +3443,96 @@ struct end) ] + val dfDelete = describe "delete motion 'df'" + [ test + "does not delete when there is no occurrence of \ + \after cursor position" + (fn _ => + let + (* arrange *) + val originalString = "hello world\n" + val app = TestUtils.init originalString + val app = AppWith.idx (app, 0) + + (* act *) + val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "dff") + + (* assert *) + val actualString = LineGap.toString buffer + val expectedString = originalString + val expectedCursorIdx = 0 + in + Expect.isTrue + (actualString = expectedString + andalso cursorIdx = expectedCursorIdx) + end) + , test + "does not delete when cursor is at last occurrence of in buffer" + (fn _ => + let + (* arrange *) + val originalString = "hello world\n" + val app = TestUtils.init originalString + val app = AppWith.idx (app, 6) + + (* act *) + val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "dfw") + + (* assert *) + val actualString = LineGap.toString buffer + val expectedString = originalString + val expectedCursorIdx = 6 + in + Expect.isTrue + (actualString = expectedString + andalso cursorIdx = expectedCursorIdx) + end) + , test + "deletes up to when \ + \there is an ocurrence of after cursor's position on same line" + (fn _ => + let + (* arrange *) + val originalString = "hey hello\n" + val app = TestUtils.init originalString + val app = AppWith.idx (app, 0) + + (* act *) + val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "dfy") + + (* assert *) + val actualString = LineGap.toString buffer + val expectedString = " hello\n" + val expectedCursorIdx = 0 + in + Expect.isTrue + (actualString = expectedString + andalso cursorIdx = expectedCursorIdx) + end) + , test + "deletes up to when the next occurrence of \ + \is after a newline" + (fn _ => + let + (* arrange *) + val originalString = "hello\nworld\n" + val app = TestUtils.init originalString + val app = AppWith.idx (app, 0) + + (* act *) + val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "dfr") + + (* assert *) + val actualString = LineGap.toString buffer + val expectedString = "ld\n" + val expectedCursorIdx = 0 + in + Expect.isTrue + (actualString = expectedString + andalso cursorIdx = expectedCursorIdx) + end) + ] + val tests = [ dhDelete , dlDelete @@ -3464,5 +3554,6 @@ struct , dCaretDelete , dnDelete , dNDelete + , dfDelete ] end