From cbc1359de148ec31b2e0a058800844136c3782ac Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Sat, 22 Mar 2025 20:58:39 +0000 Subject: [PATCH] add tests for cursor movement 'gg', which means all cursor movements have tests now. Next: add tests for delete motions. --- test/normal-move.sml | 58 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/test/normal-move.sml b/test/normal-move.sml index a8085c5..1e37f02 100644 --- a/test/normal-move.sml +++ b/test/normal-move.sml @@ -2100,6 +2100,63 @@ struct end) ] + val ggMove = describe "move motion 'gg'" + [ test "moves cursor to start when cursor is at end" (fn _ => + let + (* arrange *) + val buffer = LineGap.fromString "hello world" + val app = AppType.init (buffer, 0, 0) + val app = withIdx (app, 10) + + (* act *) + val app = updateMany (app, "gg") + in + (* assert *) + Expect.isTrue (getChr app = #"h") + end) + , test "moves cursor to start when cursor is in middle" (fn _ => + let + (* arrange *) + val buffer = LineGap.fromString "hello world" + val app = AppType.init (buffer, 0, 0) + val app = withIdx (app, 5) + + (* act *) + val app = updateMany (app, "gg") + in + (* assert *) + Expect.isTrue (getChr app = #"h") + end) + , test "leaves cursor in same place when cursor is already at start" + (fn _ => + let + (* arrange *) + val buffer = LineGap.fromString "hello world" + val app = AppType.init (buffer, 0, 0) + + (* act *) + val app = updateMany (app, "gg") + in + (* assert *) + Expect.isTrue (getChr app = #"h") + end) + , test "is cancellable by pressing escape" (fn _ => + let + (* arrange *) + val buffer = LineGap.fromString "hello world" + val app = AppType.init (buffer, 0, 0) + val app = withIdx (app, 5) + + (* act *) + val app1 = AppUpdate.update (app, CHAR_EVENT #"g") + val app2 = AppUpdate.update (app1, KEY_ESC) + val app3 = AppUpdate.update (app2, CHAR_EVENT #"g") + in + (* assert *) + Expect.isTrue (#cursorIdx app3 = 5) + end) + ] + val tests = concat [ hMove , jMove @@ -2121,5 +2178,6 @@ struct , TMove , fMove , FMove + , ggMove ] end