fix tests which broke due to a design decision (how to handle newlines)
This commit is contained in:
@@ -119,18 +119,60 @@ struct
|
|||||||
(* assert *)
|
(* assert *)
|
||||||
Expect.isTrue (oldCursorIdx = 0 andalso cursorIdx = 1)
|
Expect.isTrue (oldCursorIdx = 0 andalso cursorIdx = 1)
|
||||||
end)
|
end)
|
||||||
, test "does not move cursor when cursorIdx is at end of buffer" (fn _ =>
|
, test
|
||||||
let
|
"does not move cursor when cursorIdx is at end of buffer \
|
||||||
(* arrange *)
|
\and last char is a newline preceded by a newline"
|
||||||
val app = TestUtils.init "hello world\n"
|
(fn _ =>
|
||||||
val app = AppWith.idx (app, 11)
|
let
|
||||||
|
(* arrange *)
|
||||||
|
val str = "hello world\n\n"
|
||||||
|
val initialCursorIdx = String.size str - 1
|
||||||
|
|
||||||
(* act *)
|
val app = TestUtils.init str
|
||||||
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"l")
|
val app = AppWith.idx (app, initialCursorIdx)
|
||||||
in
|
|
||||||
(* assert *)
|
(* act *)
|
||||||
Expect.isTrue (cursorIdx = 11)
|
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"l")
|
||||||
end)
|
in
|
||||||
|
(* assert *)
|
||||||
|
Expect.isTrue (cursorIdx = initialCursorIdx)
|
||||||
|
end)
|
||||||
|
, test
|
||||||
|
"does not move cursor when cursorIdx is at end of buffer \
|
||||||
|
\and last char is a non-newline preceded by a non-newline"
|
||||||
|
(fn _ =>
|
||||||
|
let
|
||||||
|
(* arrange *)
|
||||||
|
val str = "hello world"
|
||||||
|
val initialCursorIdx = String.size str - 1
|
||||||
|
|
||||||
|
val app = TestUtils.init str
|
||||||
|
val app = AppWith.idx (app, initialCursorIdx)
|
||||||
|
|
||||||
|
(* act *)
|
||||||
|
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"l")
|
||||||
|
in
|
||||||
|
(* assert *)
|
||||||
|
Expect.isTrue (cursorIdx = initialCursorIdx)
|
||||||
|
end)
|
||||||
|
, test
|
||||||
|
"does not move cursor when cursorIdx is at end of buffer \
|
||||||
|
\and last char is a newline preceded by a non-newline"
|
||||||
|
(fn _ =>
|
||||||
|
let
|
||||||
|
(* arrange *)
|
||||||
|
val str = "hello world\n"
|
||||||
|
val initialCursorIdx = String.size str - 2
|
||||||
|
|
||||||
|
val app = TestUtils.init str
|
||||||
|
val app = AppWith.idx (app, initialCursorIdx)
|
||||||
|
|
||||||
|
(* act *)
|
||||||
|
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"l")
|
||||||
|
in
|
||||||
|
(* assert *)
|
||||||
|
Expect.isTrue (cursorIdx = initialCursorIdx)
|
||||||
|
end)
|
||||||
, test "moves cursor to char past newline when newline is preceded by char"
|
, test "moves cursor to char past newline when newline is preceded by char"
|
||||||
(fn _ =>
|
(fn _ =>
|
||||||
let
|
let
|
||||||
@@ -460,7 +502,7 @@ struct
|
|||||||
val str = "hello\nworld\n\n"
|
val str = "hello\nworld\n\n"
|
||||||
|
|
||||||
val app = TestUtils.init str
|
val app = TestUtils.init str
|
||||||
val app = AppWith.idx (app, 11)
|
val app = AppWith.idx (app, 12)
|
||||||
|
|
||||||
(* act *)
|
(* act *)
|
||||||
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"k")
|
val {cursorIdx, ...} = TestUtils.update (app, CHAR_EVENT #"k")
|
||||||
@@ -590,7 +632,7 @@ struct
|
|||||||
Expect.isTrue chrIsEnd
|
Expect.isTrue chrIsEnd
|
||||||
end)
|
end)
|
||||||
, test
|
, test
|
||||||
"moves cursor to newline when cursor is on the last word \
|
"moves cursor to second newline when cursor is on the last word \
|
||||||
\and the file ends with two newlines"
|
\and the file ends with two newlines"
|
||||||
(fn _ =>
|
(fn _ =>
|
||||||
let
|
let
|
||||||
@@ -602,7 +644,7 @@ struct
|
|||||||
val app = TestUtils.update (app, CHAR_EVENT #"w")
|
val app = TestUtils.update (app, CHAR_EVENT #"w")
|
||||||
in
|
in
|
||||||
(* assert *)
|
(* assert *)
|
||||||
Expect.isTrue (#cursorIdx app = 5)
|
Expect.isTrue (#cursorIdx app = 6)
|
||||||
end)
|
end)
|
||||||
, test
|
, test
|
||||||
"does not move to or past newline when cursor is on last word \
|
"does not move to or past newline when cursor is on last word \
|
||||||
|
|||||||
Reference in New Issue
Block a user