diff --git a/test/normal-move.sml b/test/normal-move.sml index 0c6b8d8..599e5a5 100644 --- a/test/normal-move.sml +++ b/test/normal-move.sml @@ -1951,6 +1951,78 @@ struct end) ] + val fMove = describe "move motion 'f'" + [ test "motion 'fw' moves cursor to first 'w' 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, "fw") + in + (* assert *) + Expect.isTrue (getChr app = #"w") + end) + , test "count followed by f moves to count'th match" (fn _ => + let + (* arrange *) + val buffer = LineGap.fromString "hello world" + val app = AppType.init (buffer, 0, 0) + + (* act *) + val app = updateMany (app, "3fl") + in + (* assert *) + Expect.isTrue (#cursorIdx app = 9 andalso getChr app = #"l") + end) + , test + "'count f' goes to last match when count is greater than number of chars" + (fn _ => + let + (* arrange *) + val buffer = LineGap.fromString "hello world" + val app = AppType.init (buffer, 0, 0) + + (* act *) + val app = updateMany (app, "9fl") + in + (* assert *) + Expect.isTrue (#cursorIdx app = 9 andalso getChr app = #"l") + end) + , test + "does not move cursor at all when char following 'f' 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, "f;") + 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 #"f") + 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 [ hMove , jMove @@ -1970,5 +2042,6 @@ struct (* multi-char motions *) , tMove , TMove + , fMove ] end