From 98f83131415578c4a44e3d32970ecc3ad822882a Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Sun, 24 Nov 2024 20:15:07 +0000 Subject: [PATCH] add motion tests for '$' command --- test/test.sml | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/test/test.sml b/test/test.sml index 0e5609f..525276a 100644 --- a/test/test.sml +++ b/test/test.sml @@ -925,6 +925,75 @@ val zeroMove = describe "move motion '0'" end) ] -val tests = concat [hMove, lMove, jMove, kMove, wMove, WMove, zeroMove] +val dlrMove = describe "move motion '$'" + [ test "moves cursor to char before '\\n' in contiguous string" (fn _ => + let + (* arrange *) + val buffer = LineGap.fromString "hello wor9\n" + val app = AppType.init (buffer, 0, 0) + + (* act *) + val (app, _) = AppUpdate.update (app, CHAR_EVENT #"$") + in + (* assert *) + Expect.isTrue (getChr app = #"9") + end) + , test "moves cursor to char before '\\n' in split string" (fn _ => + let + (* arrange *) + val buffer = fromList ["hel", "lo ", " wor9\n"] + val app = AppType.init (buffer, 0, 0) + + (* act *) + val (app, _) = AppUpdate.update (app, CHAR_EVENT #"$") + in + (* assert *) + Expect.isTrue (getChr app = #"9") + end) + , test + "leaves cursor at same idx in contiguous string\ + \when char after cursor is '\\n'" + (fn _ => + let + (* arrange *) + val buffer = LineGap.fromString "hello\n world\n" + val app = AppType.init (buffer, 0, 0) + val app = withIdx (app, 11) + val oldIdx = #cursorIdx app + + (* act *) + val (app, _) = AppUpdate.update (app, CHAR_EVENT #"$") + val newIdx = #cursorIdx app + + val nchr = getChr app + val nchr = Char.toString nchr ^ "\n" + in + (* assert *) + Expect.isTrue (oldIdx = newIdx) + end) + , test + "leaves cursor at same idx in split string\ + \when char after cursor is '\\n'" + (fn _ => + let + (* arrange *) + val buffer = fromList ["hel", "lo\n", " wo", "rld", "\n"] + val app = AppType.init (buffer, 0, 0) + val app = withIdx (app, 11) + val oldIdx = #cursorIdx app + + (* act *) + val (app, _) = AppUpdate.update (app, CHAR_EVENT #"$") + val newIdx = #cursorIdx app + + val nchr = getChr app + val nchr = Char.toString nchr ^ "\n" + in + (* assert *) + Expect.isTrue (oldIdx = newIdx) + end) + ] + +val tests = concat [hMove, lMove, jMove, kMove, wMove, WMove, zeroMove, dlrMove] val _ = run tests