From 6c1e5777d1b7fee056ec4b47dd73c38dca58dd08 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Sun, 8 Feb 2026 09:54:39 +0000 Subject: [PATCH] begin adding tests for how searchList should be after a deletion --- test/normal-delete-tests.sml | 110 +++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/test/normal-delete-tests.sml b/test/normal-delete-tests.sml index 4dea247..4128fa7 100644 --- a/test/normal-delete-tests.sml +++ b/test/normal-delete-tests.sml @@ -113,6 +113,116 @@ struct in Expect.isTrue (stringIsExpected andalso cursorIdxIsExpected) end) + , test "has same searchList when deleting after all matches" (fn _ => + let + (* arrange *) + val originalIdx = 5 + val originalString = "hello world\n" + + val app = TestUtils.init originalString + val app = AppWith.idx (app, originalIdx) + + val app = TestUtils.updateMany (app, "/he") + val app = AppUpdate.update (app, InputMsg.KEY_ENTER, Time.now ()) + + (* act *) + val newApp = TestUtils.updateMany (app, "dh") + in + (* assert *) + Expect.isTrue (#searchList app = #searchList newApp) + end) + , test "decrements search list by 1 when we delete a single char" (fn _ => + let + (* arrange *) + val originalIdx = 1 + val originalString = "hello world\n" + + val app = TestUtils.init originalString + val app = AppWith.idx (app, originalIdx) + + val app = TestUtils.updateMany (app, "/wo") + val app = AppUpdate.update (app, InputMsg.KEY_ENTER, Time.now ()) + + (* act *) + val newApp = TestUtils.updateMany (app, "dh") + + (* assert *) + val oldSearchList = #searchList app + val oldSearchList = PersistentVector.toList oldSearchList + + val expectedSearchList = + List.map + (fn {start, finish} => {start = start - 1, finish = finish - 1}) + oldSearchList + + val newSearchList = #searchList newApp + val newSearchList = PersistentVector.toList newSearchList + in + Expect.isTrue (newSearchList = expectedSearchList) + end) + , test "recognises new match when there is a match after deletion" (fn _ => + let + (* arrange *) + val originalIdx = 6 + val originalString = "hello world\n" + + val app = TestUtils.init originalString + val app = AppWith.idx (app, originalIdx) + + val app = TestUtils.updateMany (app, "/helloworld") + val app = AppUpdate.update (app, InputMsg.KEY_ENTER, Time.now ()) + + (* act *) + val newApp = TestUtils.updateMany (app, "dh") + + (* assert *) + val expectedSearchList = [{start = 0, finish = 9}] + + val newSearchList = #searchList newApp + val newSearchList = PersistentVector.toList newSearchList + + val assertion = + PersistentVector.isEmpty (#searchList app) + andalso newSearchList = expectedSearchList + in + Expect.isTrue assertion + end) + , test + "extends existing match when existing match should extend \ + \after deletion" + (fn _ => + let + (* arrange *) + val originalIdx = 6 + val originalString = "hello one\n" + + val app = TestUtils.init originalString + val app = AppWith.idx (app, originalIdx) + + val app = TestUtils.updateMany (app, "/o+") + val app = AppUpdate.update (app, InputMsg.KEY_ENTER, Time.now ()) + + (* act *) + val newApp = TestUtils.updateMany (app, "dh") + + (* assert *) + val oldSearchList = #searchList app + val oldSearchList = PersistentVector.toList oldSearchList + + val expectedOldSearchList = + [{start = 4, finish = 4}, {start = 6, finish = 6}] + + val newSearchList = #searchList newApp + val newSearchList = PersistentVector.toList newSearchList + + val expectedNewSearchList = [{start = 4, finish = 5}] + + val assertion = + oldSearchList = expectedOldSearchList + andalso newSearchList = expectedNewSearchList + in + Expect.isTrue assertion + end) ] (* 'dl' motion and 'x' motion have identical behaviour *)