begin adding tests for 'yw' yank motion
This commit is contained in:
@@ -68,17 +68,12 @@ struct
|
||||
let
|
||||
val cursorIdx = Int.max (textLength - 1, 0)
|
||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||
val cursorIdx =
|
||||
if Cursor.isOnNewlineAfterChr (buffer, cursorIdx) then cursorIdx - 1
|
||||
else cursorIdx
|
||||
in
|
||||
if Cursor.isOnNewlineAfterChr (buffer, cursorIdx) then
|
||||
let
|
||||
val cursorIdx = cursorIdx - 1
|
||||
in
|
||||
NormalFinish.buildTextAndClear
|
||||
(app, buffer, cursorIdx, searchList, [], bufferModifyTime)
|
||||
end
|
||||
else
|
||||
NormalFinish.buildTextAndClear
|
||||
(app, buffer, cursorIdx, searchList, [], bufferModifyTime)
|
||||
NormalFinish.buildTextAndClear
|
||||
(app, buffer, cursorIdx, searchList, [], bufferModifyTime)
|
||||
end
|
||||
else
|
||||
NormalFinish.buildTextAndClear
|
||||
|
||||
@@ -200,9 +200,10 @@ struct
|
||||
fun yankWhenMovingForward (app: app_type, fMove, count) =
|
||||
let
|
||||
val {buffer, cursorIdx, ...} = app
|
||||
|
||||
val buffer = LineGap.goToIdx (cursorIdx, buffer)
|
||||
|
||||
val high = fMove (buffer, cursorIdx, count)
|
||||
val high = if high = #textLength buffer then high - 1 else high
|
||||
|
||||
val buffer = LineGap.goToIdx (high, buffer)
|
||||
val length = high - cursorIdx
|
||||
|
||||
@@ -650,5 +650,249 @@ struct
|
||||
end)
|
||||
]
|
||||
|
||||
val tests = [yhYank, ylYank, ykYank, yjYank, yyYank]
|
||||
val ywYank = describe "yank motion 'yw'"
|
||||
[ test "yanks last character when cursor is on last character of line"
|
||||
(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 app = TestUtils.updateMany (app, "yw")
|
||||
|
||||
(* assert *)
|
||||
val expectedString = "d"
|
||||
in
|
||||
TestUtils.expectYank (app, expectedString)
|
||||
end)
|
||||
, test "deletes 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, "yw")
|
||||
val newApp2 = TestUtils.updateMany (app2, "yw")
|
||||
val newApp3 = TestUtils.updateMany (app3, "yw")
|
||||
val newApp4 = TestUtils.updateMany (app4, "yw")
|
||||
val newApp5 = TestUtils.updateMany (app5, "yw")
|
||||
|
||||
(* assert *)
|
||||
val expectedString1 = "hello again\n"
|
||||
val expectedString2 = "hello wagain\n"
|
||||
val expectedString3 = "hello woagain\n"
|
||||
val expectedString4 = "hello woragain\n"
|
||||
val expectedString5 = "hello worlagain\n"
|
||||
|
||||
val actualString1 = LineGap.toString (#buffer newApp1)
|
||||
val actualString2 = LineGap.toString (#buffer newApp2)
|
||||
val actualString3 = LineGap.toString (#buffer newApp3)
|
||||
val actualString4 = LineGap.toString (#buffer newApp4)
|
||||
val actualString5 = LineGap.toString (#buffer newApp5)
|
||||
|
||||
val stringsAreExpected =
|
||||
expectedString1 = actualString1
|
||||
andalso expectedString2 = actualString2
|
||||
andalso expectedString3 = actualString3
|
||||
andalso expectedString4 = actualString4
|
||||
andalso expectedString5 = actualString5
|
||||
|
||||
val expectedCursor1 = 6
|
||||
val expectedCursor2 = 7
|
||||
val expectedCursor3 = 8
|
||||
val expectedCursor4 = 9
|
||||
val expectedCursor5 = 10
|
||||
|
||||
val actualCursor1 = #cursorIdx newApp1
|
||||
val actualCursor2 = #cursorIdx newApp2
|
||||
val actualCursor3 = #cursorIdx newApp3
|
||||
val actualCursor4 = #cursorIdx newApp4
|
||||
val actualCursor5 = #cursorIdx newApp5
|
||||
|
||||
val cursorsAreExpected =
|
||||
expectedCursor1 = actualCursor1
|
||||
andalso expectedCursor2 = actualCursor2
|
||||
andalso expectedCursor3 = actualCursor3
|
||||
andalso expectedCursor4 = actualCursor4
|
||||
andalso expectedCursor5 = actualCursor5
|
||||
in
|
||||
Expect.isTrue (stringsAreExpected andalso cursorsAreExpected)
|
||||
end)
|
||||
, test "does not delete newline following word" (fn _ =>
|
||||
let
|
||||
(* arrange *)
|
||||
val originalString = "hello\nworld\nagain\n"
|
||||
val app = TestUtils.init originalString
|
||||
val app = AppWith.idx (app, 0)
|
||||
|
||||
(* act *)
|
||||
val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "yw")
|
||||
|
||||
(* assert *)
|
||||
val expectedString = "\nworld\nagain\n"
|
||||
val expectedCursor = 0
|
||||
|
||||
val actualString = LineGap.toString buffer
|
||||
|
||||
val stringIsExpected = expectedString = actualString
|
||||
val cursorIsExpected = expectedCursor = cursorIdx
|
||||
in
|
||||
Expect.isTrue (stringIsExpected andalso cursorIsExpected)
|
||||
end)
|
||||
, test
|
||||
"deletes 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 {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "yw")
|
||||
|
||||
(* assert *)
|
||||
val expectedString = "!world!again\n"
|
||||
val expectedCursor = 0
|
||||
|
||||
val actualString = LineGap.toString buffer
|
||||
|
||||
val stringIsExpected = expectedString = actualString
|
||||
val cursorIsExpected = expectedCursor = cursorIdx
|
||||
in
|
||||
Expect.isTrue (stringIsExpected andalso cursorIsExpected)
|
||||
end)
|
||||
, test
|
||||
"deletes 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 {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "yw")
|
||||
|
||||
(* assert *)
|
||||
val expectedString = "QWERTY#!\n"
|
||||
val expectedCursor = 0
|
||||
|
||||
val actualString = LineGap.toString buffer
|
||||
|
||||
val stringIsExpected = expectedString = actualString
|
||||
val cursorIsExpected = expectedCursor = cursorIdx
|
||||
in
|
||||
Expect.isTrue (stringIsExpected andalso cursorIsExpected)
|
||||
end)
|
||||
, test
|
||||
"deletes until first alpha char \
|
||||
\when cursor is on space and next char is alpha"
|
||||
(fn _ =>
|
||||
let
|
||||
(* arrange *)
|
||||
val originalString = "h ello\n"
|
||||
val app = TestUtils.init originalString
|
||||
val app = AppWith.idx (app, 1)
|
||||
|
||||
(* act *)
|
||||
val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "yw")
|
||||
|
||||
(* assert *)
|
||||
val expectedString = "hello\n"
|
||||
val actualString = LineGap.toString buffer
|
||||
val expectedCursor = 1
|
||||
|
||||
val stringIsExpected = expectedString = actualString
|
||||
val cursorIsExpected = expectedCursor = cursorIdx
|
||||
in
|
||||
Expect.isTrue (stringIsExpected andalso cursorIsExpected)
|
||||
end)
|
||||
, test
|
||||
"deletes until first alpha char \
|
||||
\when cursor is on space, many spaces are ahead, \
|
||||
\and first char after spaces is alpha"
|
||||
(fn _ =>
|
||||
let
|
||||
(* arrange *)
|
||||
val originalString = "h ello\n"
|
||||
val app = TestUtils.init originalString
|
||||
val app = AppWith.idx (app, 3)
|
||||
|
||||
(* act *)
|
||||
val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "yw")
|
||||
|
||||
(* assert *)
|
||||
val expectedString = "h ello\n"
|
||||
val actualString = LineGap.toString buffer
|
||||
val expectedCursor = 3
|
||||
|
||||
val stringIsExpected = expectedString = actualString
|
||||
val cursorIsExpected = expectedCursor = cursorIdx
|
||||
in
|
||||
Expect.isTrue (stringIsExpected andalso cursorIsExpected)
|
||||
end)
|
||||
, test
|
||||
"deletes until first punctuation char \
|
||||
\when cursor is on space and next non-space char is punctuation"
|
||||
(fn _ =>
|
||||
let
|
||||
(* arrange *)
|
||||
val originalString = "! @#$%\n"
|
||||
val app = TestUtils.init originalString
|
||||
val app = AppWith.idx (app, 2)
|
||||
|
||||
(* act *)
|
||||
val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "yw")
|
||||
|
||||
(* assert *)
|
||||
val expectedString = "! @#$%\n"
|
||||
val actualString = LineGap.toString buffer
|
||||
val expectedCursor = 2
|
||||
|
||||
val stringIsExpected = expectedString = actualString
|
||||
val cursorIsExpected = expectedCursor = cursorIdx
|
||||
in
|
||||
Expect.isTrue (stringIsExpected andalso cursorIsExpected)
|
||||
end)
|
||||
, test
|
||||
"deletes last char when on last word \
|
||||
\and there is no newline after current word"
|
||||
(fn _ =>
|
||||
let
|
||||
(* arrange *)
|
||||
val app = TestUtils.init "hello world"
|
||||
val app = AppWith.idx (app, 6)
|
||||
|
||||
(* act *)
|
||||
val {buffer, cursorIdx, ...} = TestUtils.updateMany (app, "yw")
|
||||
|
||||
(* assert *)
|
||||
val expectedString = "hello "
|
||||
val actualString = LineGap.toString buffer
|
||||
|
||||
val expectedIdx = 5
|
||||
|
||||
val stringIsExpected = expectedString = actualString
|
||||
val cursorIsExpected = cursorIdx = expectedIdx
|
||||
in
|
||||
Expect.isTrue (stringIsExpected andalso cursorIsExpected)
|
||||
end)
|
||||
]
|
||||
|
||||
val tests = [yhYank, ylYank, ykYank, yjYank, yyYank, ywYank]
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user