begin adding tests for how searchList should be after a deletion

This commit is contained in:
2026-02-08 09:54:39 +00:00
parent 3b21025dbc
commit 6c1e5777d1

View File

@@ -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 *)