done addint to hjkl movement tests
This commit is contained in:
@@ -79,7 +79,6 @@ struct
|
|||||||
|
|
||||||
(* act *)
|
(* act *)
|
||||||
val app = TestUtils.update (app, CHAR_EVENT #"h")
|
val app = TestUtils.update (app, CHAR_EVENT #"h")
|
||||||
val () = print (Int.toString (#cursorIdx app))
|
|
||||||
in
|
in
|
||||||
(* assert *)
|
(* assert *)
|
||||||
Expect.isTrue (#cursorIdx app = 6)
|
Expect.isTrue (#cursorIdx app = 6)
|
||||||
@@ -269,7 +268,9 @@ struct
|
|||||||
(* arrange *)
|
(* arrange *)
|
||||||
val str = "hello \nworld \ntime to go\n"
|
val str = "hello \nworld \ntime to go\n"
|
||||||
val app = TestUtils.init str
|
val app = TestUtils.init str
|
||||||
val app = AppWith.idx (app, 15)
|
|
||||||
|
val initialCursorIdx = 15
|
||||||
|
val app = AppWith.idx (app, initialCursorIdx)
|
||||||
|
|
||||||
(* act *)
|
(* act *)
|
||||||
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"j")
|
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"j")
|
||||||
@@ -279,11 +280,11 @@ struct
|
|||||||
* but we are counting String.size str - 2 as the end
|
* but we are counting String.size str - 2 as the end
|
||||||
* because, in Vim, saved files always end with \n
|
* because, in Vim, saved files always end with \n
|
||||||
* but the last char, \n, is not visible *)
|
* but the last char, \n, is not visible *)
|
||||||
val isAtEnd = cursorIdx = String.size str - 2
|
val isAtEnd = cursorIdx = initialCursorIdx
|
||||||
in
|
in
|
||||||
Expect.isTrue isAtEnd
|
Expect.isTrue isAtEnd
|
||||||
end)
|
end)
|
||||||
, test "leaves cursor at same idx when already at end of buffer" (fn _ =>
|
, test "leaves cursor at same idx when already on last line" (fn _ =>
|
||||||
let
|
let
|
||||||
(* arrange *)
|
(* arrange *)
|
||||||
val str = "hello \nworld \ntime to go\n"
|
val str = "hello \nworld \ntime to go\n"
|
||||||
@@ -303,11 +304,26 @@ struct
|
|||||||
in
|
in
|
||||||
Expect.isTrue isAtEnd
|
Expect.isTrue isAtEnd
|
||||||
end)
|
end)
|
||||||
|
, test
|
||||||
|
"goes to next char when cursor is on a newline \
|
||||||
|
\and next char is not a newline"
|
||||||
|
(fn _ =>
|
||||||
|
let
|
||||||
|
(* arrange *)
|
||||||
|
val str = "hello\n\nworld\n"
|
||||||
|
val app = TestUtils.init str
|
||||||
|
val app = AppWith.idx (app, 5)
|
||||||
|
|
||||||
|
(* act *)
|
||||||
|
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"j")
|
||||||
|
in
|
||||||
|
(* assert *)
|
||||||
|
Expect.isTrue (cursorIdx = 7)
|
||||||
|
end)
|
||||||
]
|
]
|
||||||
|
|
||||||
val kMove = describe "move motion 'k'"
|
val kMove = describe "move motion 'k'"
|
||||||
[ test "moves cursur up one column in contiguous string when column = 0"
|
[ test "moves cursur up one column when column = 0" (fn _ =>
|
||||||
(fn _ =>
|
|
||||||
let
|
let
|
||||||
(* arrange *)
|
(* arrange *)
|
||||||
val app = TestUtils.init "0__\n4___\n9___\n14_"
|
val app = TestUtils.init "0__\n4___\n9___\n14_"
|
||||||
@@ -325,8 +341,7 @@ struct
|
|||||||
in
|
in
|
||||||
Expect.isTrue (c1 andalso c2 andalso c3)
|
Expect.isTrue (c1 andalso c2 andalso c3)
|
||||||
end)
|
end)
|
||||||
, test "moves cursur up one column in contiguous string when column = 1"
|
, test "moves cursur up one column when column = 1" (fn _ =>
|
||||||
(fn _ =>
|
|
||||||
let
|
let
|
||||||
(* arrange *)
|
(* arrange *)
|
||||||
val app = TestUtils.init "_w_\n_5__\n_10_\n_15"
|
val app = TestUtils.init "_w_\n_5__\n_10_\n_15"
|
||||||
@@ -344,8 +359,7 @@ struct
|
|||||||
in
|
in
|
||||||
Expect.isTrue (c1 andalso c2 andalso c3)
|
Expect.isTrue (c1 andalso c2 andalso c3)
|
||||||
end)
|
end)
|
||||||
, test "moves cursur up one column in contiguous string when column = 2"
|
, test "moves cursur up one column when column = 2" (fn _ =>
|
||||||
(fn _ =>
|
|
||||||
let
|
let
|
||||||
(* arrange *)
|
(* arrange *)
|
||||||
val app = TestUtils.init "__2\n__6\n__10\n__15\n"
|
val app = TestUtils.init "__2\n__6\n__10\n__15\n"
|
||||||
@@ -363,24 +377,22 @@ struct
|
|||||||
in
|
in
|
||||||
Expect.isTrue (c1 andalso c2 andalso c3)
|
Expect.isTrue (c1 andalso c2 andalso c3)
|
||||||
end)
|
end)
|
||||||
, test
|
, test "goes to first newline when encountering two consecutive newlines"
|
||||||
"skips '\\n' when cursor is on '\\n',\
|
|
||||||
\prev-char is '\\n' and prev-prev char is not '\\n'"
|
|
||||||
(fn _ =>
|
(fn _ =>
|
||||||
let
|
let
|
||||||
(* arrange *)
|
(* arrange *)
|
||||||
val app = TestUtils.init "hello\n\n world\n"
|
val str = "hello\n\n world\n"
|
||||||
val app = AppWith.idx (app, 6)
|
val app = TestUtils.init str
|
||||||
|
val app = AppWith.idx (app, 7)
|
||||||
|
|
||||||
(* act *)
|
(* act *)
|
||||||
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"k")
|
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"k")
|
||||||
|
val isOnFirstNewline = cursorIdx = 5
|
||||||
(* assert *)
|
|
||||||
val isSkipped = cursorIdx = 0
|
|
||||||
in
|
in
|
||||||
Expect.isTrue isSkipped
|
(* assert *)
|
||||||
|
Expect.isTrue isOnFirstNewline
|
||||||
end)
|
end)
|
||||||
, test "leaves cursor at same idx when already at start of buffer" (fn _ =>
|
, test "leaves cursor at same idx when already on first line" (fn _ =>
|
||||||
let
|
let
|
||||||
(* arrange *)
|
(* arrange *)
|
||||||
val str = "hello \nworld \ntime to go\n"
|
val str = "hello \nworld \ntime to go\n"
|
||||||
@@ -392,14 +404,46 @@ struct
|
|||||||
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"k")
|
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"k")
|
||||||
|
|
||||||
(* assert *)
|
(* assert *)
|
||||||
(* String.size str - 1 is a valid char position
|
|
||||||
* but we are counting String.size str - 2 as the end
|
|
||||||
* because, in Vim, saved files always end with \n
|
|
||||||
* but the last char, \n, is not visible *)
|
|
||||||
val isAtStart = cursorIdx = 0
|
val isAtStart = cursorIdx = 0
|
||||||
in
|
in
|
||||||
Expect.isTrue isAtStart
|
Expect.isTrue isAtStart
|
||||||
end)
|
end)
|
||||||
|
, test
|
||||||
|
"goes to last column of previous line when cursor is \
|
||||||
|
\on a column greater than the number of columns in the previous line"
|
||||||
|
(fn _ =>
|
||||||
|
let
|
||||||
|
(* arrange *)
|
||||||
|
val str =
|
||||||
|
"hello world\n\
|
||||||
|
\now a quite long line is next\n"
|
||||||
|
|
||||||
|
val app = TestUtils.init str
|
||||||
|
val app = AppWith.idx (app, String.size str - 2)
|
||||||
|
|
||||||
|
(* act *)
|
||||||
|
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"k")
|
||||||
|
in
|
||||||
|
(* assert *)
|
||||||
|
Expect.isTrue (cursorIdx = 10)
|
||||||
|
end)
|
||||||
|
, test
|
||||||
|
"when on a newline and there is a double-newline \
|
||||||
|
\right before the cursor, goes to the first newline"
|
||||||
|
(fn _ =>
|
||||||
|
let
|
||||||
|
(* arrange *)
|
||||||
|
val str = "hello\n\n\nworld\n"
|
||||||
|
|
||||||
|
val app = TestUtils.init str
|
||||||
|
val app = AppWith.idx (app, 7)
|
||||||
|
|
||||||
|
(* act *)
|
||||||
|
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"k")
|
||||||
|
in
|
||||||
|
(* assert *)
|
||||||
|
Expect.isTrue (cursorIdx = 5)
|
||||||
|
end)
|
||||||
]
|
]
|
||||||
|
|
||||||
val wMove = describe "move motion 'w'"
|
val wMove = describe "move motion 'w'"
|
||||||
|
|||||||
Reference in New Issue
Block a user