From 8ca8d1db2947d2c141ad3018141063ab668f1a77 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Mon, 22 Sep 2025 04:10:39 +0100 Subject: [PATCH] add new tests for 'l' motion to ensure that newlines are only skipped when they are preceded by chars --- test/normal-move.sml | 55 ++++++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/test/normal-move.sml b/test/normal-move.sml index f2f04b5..4ea33b9 100644 --- a/test/normal-move.sml +++ b/test/normal-move.sml @@ -83,20 +83,26 @@ struct (* assert *) Expect.isTrue (cursorIdx = 4) end) - , test - "moves cursor to odd-numbered newline when cursor is currently on char\ - \ after a triple newline" + , test "moves cursor to a newline when newline is not preceded by char" (fn _ => let (* arrange *) - val app = TestUtils.init "hello\n\n\nworld" - val app = AppWith.idx (app, 7) + val app = TestUtils.init "\n\n\nhello\n" + val app = AppWith.idx (app, 3) (* act *) - val app = TestUtils.update (app, CHAR_EVENT #"h") - in + val app1 = TestUtils.update (app, CHAR_EVENT #"h") + val app2 = TestUtils.update (app1, CHAR_EVENT #"h") + val app3 = TestUtils.update (app2, CHAR_EVENT #"h") + val app4 = TestUtils.update (app3, CHAR_EVENT #"h") + (* assert *) - Expect.isTrue (#cursorIdx app = 6) + val c1 = #cursorIdx app1 = 2 + val c2 = #cursorIdx app2 = 1 + val c3 = #cursorIdx app3 = 0 + val c4 = #cursorIdx app4 = 0 + in + Expect.isTrue (c1 andalso c2 andalso c3 andalso c4) end) ] @@ -125,9 +131,7 @@ struct (* assert *) Expect.isTrue (cursorIdx = 10) end) - , test - "moves cursor to the first character after a newline\ - \ when there is a newlineo on the right followed by a non-newline" + , test "moves cursor to char past newline when newline is preceded by char" (fn _ => let (* arrange *) @@ -140,9 +144,7 @@ struct (* assert *) Expect.isTrue (cursorIdx = 6) end) - , test - "moves cursor to the first newline\ - \ when there are multiple continuous newlines ahead" + , test "moves cursor to second newline when newline is preceded by char" (fn _ => let (* arrange *) @@ -153,7 +155,30 @@ struct val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"l") in (* assert *) - Expect.isTrue (cursorIdx = 5) + Expect.isTrue (cursorIdx = 6) + end) + , test + "moves cursor to each newline without skipping when no newline \ + \is preceded by char" + (fn _ => + let + (* arrange *) + val app = TestUtils.init "\n\n\nhello\n" + val app = AppWith.idx (app, 0) + + (* act *) + val app1 = TestUtils.update (app, CHAR_EVENT #"l") + val app2 = TestUtils.update (app1, CHAR_EVENT #"l") + val app3 = TestUtils.update (app2, CHAR_EVENT #"l") + val app4 = TestUtils.update (app3, CHAR_EVENT #"l") + + (* assert *) + val c1 = #cursorIdx app1 = 1 + val c2 = #cursorIdx app2 = 2 + val c3 = #cursorIdx app3 = 3 + val c4 = #cursorIdx app4 = 4 + in + Expect.isTrue (c1 andalso c2 andalso c3 andalso c4) end) ]