add a couple of more tests asserting searchList state after deletion
This commit is contained in:
@@ -223,6 +223,34 @@ struct
|
||||
in
|
||||
Expect.isTrue assertion
|
||||
end)
|
||||
, test
|
||||
"deletes match in search list \
|
||||
\when match no longer exists in buffer \after buffer is deleted"
|
||||
(fn _ =>
|
||||
let
|
||||
(* arrange *)
|
||||
val originalIdx = 3
|
||||
val originalString = "hello one\n"
|
||||
|
||||
val app = TestUtils.init originalString
|
||||
val app = AppWith.idx (app, originalIdx)
|
||||
|
||||
val app = TestUtils.updateMany (app, "/hello")
|
||||
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 assertion =
|
||||
oldSearchList = [{start = 0, finish = 4}]
|
||||
andalso PersistentVector.isEmpty (#searchList newApp)
|
||||
in
|
||||
Expect.isTrue assertion
|
||||
end)
|
||||
]
|
||||
|
||||
(* 'dl' motion and 'x' motion have identical behaviour *)
|
||||
@@ -375,6 +403,144 @@ 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, "dl")
|
||||
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, "dl")
|
||||
|
||||
(* 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 = 5
|
||||
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, "dl")
|
||||
|
||||
(* 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 = 5
|
||||
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, "dl")
|
||||
|
||||
(* 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)
|
||||
, test
|
||||
"deletes match in search list \
|
||||
\when match no longer exists in buffer \after buffer is deleted"
|
||||
(fn _ =>
|
||||
let
|
||||
(* arrange *)
|
||||
val originalIdx = 3
|
||||
val originalString = "hello one\n"
|
||||
|
||||
val app = TestUtils.init originalString
|
||||
val app = AppWith.idx (app, originalIdx)
|
||||
|
||||
val app = TestUtils.updateMany (app, "/hello")
|
||||
val app = AppUpdate.update (app, InputMsg.KEY_ENTER, Time.now ())
|
||||
|
||||
(* act *)
|
||||
val newApp = TestUtils.updateMany (app, "dl")
|
||||
|
||||
(* assert *)
|
||||
val oldSearchList = #searchList app
|
||||
val oldSearchList = PersistentVector.toList oldSearchList
|
||||
|
||||
val assertion =
|
||||
oldSearchList = [{start = 0, finish = 4}]
|
||||
andalso PersistentVector.isEmpty (#searchList newApp)
|
||||
in
|
||||
Expect.isTrue assertion
|
||||
end)
|
||||
]
|
||||
|
||||
val djDelete = describe "delete motion 'dj'"
|
||||
|
||||
Reference in New Issue
Block a user