add tests for 'ye' yank motion

This commit is contained in:
2026-05-04 15:44:34 +01:00
parent a65338204d
commit 9520f683db
3 changed files with 177 additions and 2 deletions

View File

@@ -1014,5 +1014,168 @@ struct
end)
]
val tests = [yhYank, ylYank, ykYank, yjYank, yyYank, ywYank, yWYank]
val yeYank = describe "yank motion 'ye'"
[ test
"yanks second last character in buffer \
\when curson is on second last character, \
\and last character is a newline"
(fn _ =>
let
(* arrange *)
val originalString = "hello world\n"
val originalIdx = String.size originalString - 2
val app = TestUtils.init originalString
val app = AppWith.idx (app, originalIdx)
(* act *)
val newApp = TestUtils.updateMany (app, "ye")
(* assert *)
val expectedString = "d"
in
TestUtils.expectYank (newApp, expectedString)
end)
, test "yanks second word as expected when there are three words" (fn _ =>
let
(* arrange *)
val originalString = "hello world again\n"
val app = TestUtils.init originalString
(* all the different positions the cursor can be
* on the second word *)
val app1 = AppWith.idx (app, 6)
val app2 = AppWith.idx (app, 7)
val app3 = AppWith.idx (app, 8)
val app4 = AppWith.idx (app, 9)
val app5 = AppWith.idx (app, 10)
(* act *)
val newApp1 = TestUtils.updateMany (app1, "ye")
val newApp2 = TestUtils.updateMany (app2, "ye")
val newApp3 = TestUtils.updateMany (app3, "ye")
val newApp4 = TestUtils.updateMany (app4, "ye")
val newApp5 = TestUtils.updateMany (app5, "ye")
(* assert *)
val yankedAsExpected =
TestUtils.isStringYanked (newApp1, "world")
andalso TestUtils.isStringYanked (newApp2, "orld")
andalso TestUtils.isStringYanked (newApp3, "rld")
andalso TestUtils.isStringYanked (newApp4, "ld")
andalso TestUtils.isStringYanked (newApp5, "d again")
in
Expect.isTrue yankedAsExpected
end)
, test
"yanks to end of current word when \
\current word is immediately followed by newline"
(fn _ =>
let
(* arrange *)
val originalString = "hello\nworld\nagain\n"
val app = TestUtils.init originalString
val app = AppWith.idx (app, 1)
(* act *)
val newApp = TestUtils.updateMany (app, "ye")
(* assert *)
val expectedString = "ello"
in
TestUtils.expectYank (newApp, expectedString)
end)
, test
"yanks until first punctuation char when on an alpha char \
\and there is no space between alpha and punctuation"
(fn _ =>
let
(* arrange *)
val originalString = "hello!world!again\n"
val app = TestUtils.init originalString
(* act *)
val newApp = TestUtils.updateMany (app, "ye")
(* assert *)
val expectedString = "hello"
in
TestUtils.expectYank (newApp, expectedString)
end)
, test
"yanks until first alpha char when on punctuation \
\and there is no space between punctuation and alpha"
(fn _ =>
let
(* arrange *)
val originalString = "!#%&QWERTY#!\n"
val app = TestUtils.init originalString
(* act *)
val newApp = TestUtils.updateMany (app, "ye")
(* assert *)
val expectedString = "!#%&"
in
TestUtils.expectYank (newApp, expectedString)
end)
, test
"yanks to end of next word \
\when cursor is on space and next char is alpha"
(fn _ =>
let
(* arrange *)
val originalString = "h ello world\n"
val app = TestUtils.init originalString
val app = AppWith.idx (app, 1)
(* act *)
val newApp = TestUtils.updateMany (app, "ye")
(* assert *)
val expectedString = " ello"
in
TestUtils.expectYank (newApp, expectedString)
end)
, test
"yanks to end of next word \
\when cursor is on space, many spaces are ahead, \
\and first char after spaces is alpha"
(fn _ =>
let
(* arrange *)
val originalString = "h ello world\n"
val app = TestUtils.init originalString
val app = AppWith.idx (app, 3)
(* act *)
val newApp = TestUtils.updateMany (app, "ye")
(* assert *)
val expectedString = " ello"
in
TestUtils.expectYank (newApp, expectedString)
end)
, test
"yanks spaces until (excluding) non-space char \
\when cursor is on space and next non-space char is punctuation"
(fn _ =>
let
(* arrange *)
val originalString = "! @#$% world\n"
val app = TestUtils.init originalString
val app = AppWith.idx (app, 2)
(* act *)
val newApp = TestUtils.updateMany (app, "ye")
(* assert *)
val expectedString = " @#$%"
in
TestUtils.expectYank (newApp, expectedString)
end)
]
val tests = [yhYank, ylYank, ykYank, yjYank, yyYank, ywYank, yWYank, yeYank]
end