diff --git a/test/normal-delete.sml b/test/normal-delete.sml index cc9ae03..d946c42 100644 --- a/test/normal-delete.sml +++ b/test/normal-delete.sml @@ -4443,25 +4443,81 @@ struct ] 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) + [ 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") + (* act *) + val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "daw") - (* assert *) - val expectedString = "hello\nworld\n" - val actualString = LineGap.toString buffer + (* assert *) + val expectedString = "hello\nworld\n" + val actualString = LineGap.toString buffer - val expectedCursorIdx = 6 - in - Expect.isTrue - (actualString = expectedString andalso cursorIdx = expectedCursorIdx) - end)] + 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 = "hello world again\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 = "hello again\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) + ] val tests = [ dhDelete