Files
sml-projects/test/test.sml

63 lines
1.6 KiB
Standard ML
Raw Normal View History

2024-11-19 03:48:30 +00:00
open Railroad
open Railroad.Test
open InputMsg
val emptyVec = Vector.fromList []
val cursorTests = describe "cursor operations"
2024-11-19 03:53:05 +00:00
[ test "'l' moves cursor leftward by one when cursorIdx < length" (fn _ =>
2024-11-19 03:53:22 +00:00
let
(* arrange *)
val buffer = LineGap.fromString "hello world"
val app = AppType.init (buffer, 0, 0)
(* act *)
2024-11-19 03:53:05 +00:00
val ({cursorIdx, ...}, _) = AppUpdate.update (app, CHAR_EVENT #"l")
2024-11-19 03:53:22 +00:00
(* assert *)
in
Expect.isTrue (cursorIdx = 1)
end)
2024-11-19 03:53:05 +00:00
, test "'w' moves cursor to start of next word in contiguous string" (fn _ =>
2024-11-19 03:48:30 +00:00
let
(* arrange *)
val buffer = LineGap.fromString "hello world"
val app = AppType.init (buffer, 0, 0)
(* act *)
val ({cursorIdx, ...}, _) = AppUpdate.update (app, CHAR_EVENT #"w")
(* assert *)
val chr = String.sub ("hello world", cursorIdx)
in
Expect.isTrue (chr = #"w")
end)
, test "'w' moves cursor to start of next word in split string" (fn _ =>
let
(* arrange *)
val buffer =
{ idx = 0
, line = 0
, leftStrings = []
, leftLines = []
, rightStrings = ["hello ", "world"]
, rightLines = [emptyVec, emptyVec]
}
val app = AppType.init (buffer, 0, 0)
(* act *)
val ({cursorIdx, ...}, _) = AppUpdate.update (app, CHAR_EVENT #"w")
(* assert *)
val chr = String.sub ("hello world", cursorIdx)
in
Expect.isTrue (chr = #"w")
end)
]
val tests = concat [cursorTests]
val _ = run tests