From a65b950b777c7b86c77415b02ab9eaaf00616332 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Wed, 31 Dec 2025 11:44:42 +0000 Subject: [PATCH] add tests for 'daW' motion --- test/normal-delete.sml | 166 ++++++++++++++++++++++++++++++++++++++++- todo.md | 4 +- 2 files changed, 166 insertions(+), 4 deletions(-) diff --git a/test/normal-delete.sml b/test/normal-delete.sml index 0c6bfca..a6ea53a 100644 --- a/test/normal-delete.sml +++ b/test/normal-delete.sml @@ -4559,7 +4559,7 @@ struct andalso cursorIdx = expectedCursorIdx) end) , test - "deletes last world on line when cursor is on space \ + "deletes last word on line when cursor is on space \ \which immediately precedes last word" (fn _ => let @@ -4623,6 +4623,169 @@ struct end) ] + val daWDelete = describe "delete motion 'daW' (delete around word)" + [ test "deletes a single newline when cursor is on a newline" (fn _ => + let + (* arrange *) + val originalString = "hello\n\nworld\n" + val app = TestUtils.init originalString + val app = AppWith.idx (app, 6) + + (* act *) + val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "daW") + + (* assert *) + val expectedString = "hello\nworld\n" + val actualString = LineGap.toString buffer + + val expectedCursorIdx = 6 + in + Expect.isTrue + (actualString = expectedString andalso cursorIdx = expectedCursorIdx) + end) + , test + "deletes middle WORD and spaces after middle WORD \ + \when there are three WORDS on line and cursor is on middle WORD" + (fn _ => + let + (* arrange *) + val originalString = "he!!o wor!d aga!n\n" + val app = TestUtils.init originalString + + val app1 = AppWith.idx (app, 6) + val app2 = AppWith.idx (app, 7) + val app3 = AppWith.idx (app, 8) + val app4 = AppWith.idx (app, 9) + val app5 = AppWith.idx (app, 10) + + (* act *) + val app1 = TestUtils.updateMany (app1, "daW") + val app2 = TestUtils.updateMany (app2, "daW") + val app3 = TestUtils.updateMany (app3, "daW") + val app4 = TestUtils.updateMany (app4, "daW") + val app5 = TestUtils.updateMany (app5, "daW") + + (* assert *) + val expectedString = "he!!o aga!n\n" + + val actualString1 = LineGap.toString (#buffer app1) + val actualString2 = LineGap.toString (#buffer app2) + val actualString3 = LineGap.toString (#buffer app3) + val actualString4 = LineGap.toString (#buffer app4) + val actualString5 = LineGap.toString (#buffer app5) + + val stringsAreExpected = + expectedString = actualString1 + andalso expectedString = actualString2 + andalso expectedString = actualString3 + andalso expectedString = actualString4 + andalso expectedString = actualString5 + + val expectedCursorIdx = 6 + + val actualCursor1 = #cursorIdx app1 + val actualCursor2 = #cursorIdx app2 + val actualCursor3 = #cursorIdx app3 + val actualCursor4 = #cursorIdx app4 + val actualCursor5 = #cursorIdx app5 + + val cursorsAreExpected = + expectedCursorIdx = actualCursor1 + andalso expectedCursorIdx = actualCursor2 + andalso expectedCursorIdx = actualCursor3 + andalso expectedCursorIdx = actualCursor4 + andalso expectedCursorIdx = actualCursor5 + in + Expect.isTrue (stringsAreExpected andalso cursorsAreExpected) + end) + , test + "deletes trailing spaces when cursor is on WORD \ + \that has multiple trailing spaces after it" + (fn _ => + let + (* arrange *) + val originalString = "hello a&a!n world\n" + val app = TestUtils.init originalString + val app = AppWith.idx (app, 7) + + (* act *) + val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "daW") + + (* assert *) + val expectedString = "hello world\n" + val actualString = LineGap.toString buffer + + val expectedCursorIdx = 6 + in + Expect.isTrue + (actualString = expectedString + andalso cursorIdx = expectedCursorIdx) + end) + , test + "deletes last WORD on line when cursor is on space \ + \which immediately precedes last WORD" + (fn _ => + let + (* arrange *) + val originalString = "hello again w()r!d\n" + val app = TestUtils.init originalString + val app = AppWith.idx (app, 13) + + (* act *) + val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "daW") + + (* assert *) + val expectedString = "hello again\n" + val actualString = LineGap.toString buffer + + val expectedCursorIdx = 10 + in + Expect.isTrue + (actualString = expectedString + andalso cursorIdx = expectedCursorIdx) + end) + , test + "deletes WORD, including surrounding punctuation, \ + \when cursor is on alpha char" + (fn _ => + let + (* arrange *) + val app = TestUtils.init "hello a^a!n world\n" + val app = AppWith.idx (app, 8) + + (* act *) + val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "daW") + + (* assert *) + val expectedIdx = 6 + val expectedString = "hello world\n" + val actualString = LineGap.toString buffer + in + Expect.isTrue + (expectedString = actualString andalso expectedIdx = cursorIdx) + end) + , test + "deletes WORD, including surrounding alpha chars, \ + \when cursor is on punctuation char" + (fn _ => + let + (* arrange *) + val app = TestUtils.init "hello a!#%&(z world\n" + val app = AppWith.idx (app, 8) + + (* act *) + val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "daW") + + (* assert *) + val expectedIdx = 6 + val expectedString = "hello world\n" + val actualString = LineGap.toString buffer + in + Expect.isTrue + (expectedString = actualString andalso expectedIdx = cursorIdx) + end) + ] + val tests = [ dhDelete , dlDelete @@ -4651,5 +4814,6 @@ struct , diwDelete , diWDelete , dawDelete + , daWDelete ] end diff --git a/todo.md b/todo.md index c931694..ea8f526 100644 --- a/todo.md +++ b/todo.md @@ -1,9 +1,7 @@ # To-do list - Add tests for: -- Test delete-around-WORD - - Delete-around-word has tests for when cursor is on space (needs tests for alpha and punctuation too) -- Reimple `%` motion and `d%` motion. +- Reimplement `%` motion and `d%` motion. - They should both search for the next character in any pair, the same way in Vim - Add tests for reimplemented movements and motions - Reimplement `di` and `da`