add tests for 'df<char>' motion. Some fail and need the implementation to be fixed.

This commit is contained in:
2025-10-17 15:56:08 +01:00
parent 52f8e2307c
commit 09c9a92029
2 changed files with 92 additions and 3 deletions

View File

@@ -1,3 +1 @@
hello hello world
world

View File

@@ -3443,6 +3443,96 @@ struct
end) end)
] ]
val dfDelete = describe "delete motion 'df<char>'"
[ test
"does not delete when there is no occurrence of <char> \
\after cursor position"
(fn _ =>
let
(* arrange *)
val originalString = "hello world\n"
val app = TestUtils.init originalString
val app = AppWith.idx (app, 0)
(* act *)
val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "dff")
(* assert *)
val actualString = LineGap.toString buffer
val expectedString = originalString
val expectedCursorIdx = 0
in
Expect.isTrue
(actualString = expectedString
andalso cursorIdx = expectedCursorIdx)
end)
, test
"does not delete when cursor is at last occurrence of <char> in buffer"
(fn _ =>
let
(* arrange *)
val originalString = "hello world\n"
val app = TestUtils.init originalString
val app = AppWith.idx (app, 6)
(* act *)
val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "dfw")
(* assert *)
val actualString = LineGap.toString buffer
val expectedString = originalString
val expectedCursorIdx = 6
in
Expect.isTrue
(actualString = expectedString
andalso cursorIdx = expectedCursorIdx)
end)
, test
"deletes up to <char> when \
\there is an ocurrence of <char> after cursor's position on same line"
(fn _ =>
let
(* arrange *)
val originalString = "hey hello\n"
val app = TestUtils.init originalString
val app = AppWith.idx (app, 0)
(* act *)
val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "dfy")
(* assert *)
val actualString = LineGap.toString buffer
val expectedString = " hello\n"
val expectedCursorIdx = 0
in
Expect.isTrue
(actualString = expectedString
andalso cursorIdx = expectedCursorIdx)
end)
, test
"deletes up to <char> when the next occurrence of <char> \
\is after a newline"
(fn _ =>
let
(* arrange *)
val originalString = "hello\nworld\n"
val app = TestUtils.init originalString
val app = AppWith.idx (app, 0)
(* act *)
val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "dfr")
(* assert *)
val actualString = LineGap.toString buffer
val expectedString = "ld\n"
val expectedCursorIdx = 0
in
Expect.isTrue
(actualString = expectedString
andalso cursorIdx = expectedCursorIdx)
end)
]
val tests = val tests =
[ dhDelete [ dhDelete
, dlDelete , dlDelete
@@ -3464,5 +3554,6 @@ struct
, dCaretDelete , dCaretDelete
, dnDelete , dnDelete
, dNDelete , dNDelete
, dfDelete
] ]
end end