begin adding multi-char tests (for motions such as 't<char>')

This commit is contained in:
2025-03-22 06:13:01 +00:00
parent 884c5fa08d
commit 9eae0c2d48

View File

@@ -1497,7 +1497,7 @@ struct
end) end)
] ]
val caretMove = describe "move motion '^'" val hatMove = describe "move motion '^'"
[ test [ test
"moves cursor to first non-space char in first line\ "moves cursor to first non-space char in first line\
\when first line starts with spaces\ \when first line starts with spaces\
@@ -1805,21 +1805,101 @@ struct
end) end)
] ]
(* movements which use multiple chars *)
fun updateMany (app, str) =
let
fun loop (pos, app) =
if pos = String.size str then
app
else
let
val chr = String.sub (str, pos)
val app = AppUpdate.update (app, CHAR_EVENT chr)
in
loop (pos + 1, app)
end
in
loop (0, app)
end
val tMove = describe "move motion 't'"
[ test
"motion 'td' moves cursor to char before 'd' in string \"hello world\""
(fn _ =>
let
(* arrange *)
val buffer = LineGap.fromString "hello world"
val app = AppType.init (buffer, 0, 0)
(* act *)
val app = updateMany (app, "td")
in
(* assert *)
Expect.isTrue (getChr app = #"l")
end)
, test "repeating 't' motion with same char does not move cursor" (fn _ =>
let
(* arrange *)
val buffer = LineGap.fromString "hello world"
val app = AppType.init (buffer, 0, 0)
(* act *)
val app1 = updateMany (app, "td")
val app2 = updateMany (app1, "td")
in
(* assert *)
Expect.isTrue
(#cursorIdx app1 = #cursorIdx app2 andalso getChr app1 = #"l")
end)
, test
"does not move cursor at all when char following 't' is not in string"
(fn _ =>
let
(* arrange *)
val buffer = LineGap.fromString "hello world"
val app = AppType.init (buffer, 0, 0)
(* act *)
val app1 = updateMany (app, "t;")
in
(* assert *)
Expect.isTrue (#cursorIdx app1 = #cursorIdx app)
end)
, test "is cancellable by pressing escape" (fn _ =>
let
(* arrange *)
val buffer = LineGap.fromString "hello world"
val app = AppType.init (buffer, 0, 0)
(* act *)
val app1 = AppUpdate.update (app, CHAR_EVENT #"t")
val app2 = AppUpdate.update (app1, KEY_ESC)
val app3 = AppUpdate.update (app2, CHAR_EVENT #"d")
in
(* assert *)
Expect.isTrue
(#cursorIdx app1 = #cursorIdx app2
andalso #cursorIdx app2 = #cursorIdx app3)
end)
]
val tests = concat val tests = concat
[ hMove [ hMove
, lMove
, jMove , jMove
, kMove , kMove
, lMove
, wMove , wMove
, WMove , WMove
, eMove
, EMove
, bMove , bMove
, BMove , BMove
, eMove
, EMove
, zeroMove , zeroMove
, dlrMove , dlrMove
, caretMove , hatMove
, GMove , GMove
, percentMove , percentMove
(* multi-char motions *)
, tMove
] ]
end end