refactor tests a bit by putting LineGap-creation functionality into TestUtils.init, and make sure we also add a Unix-style newline to the end of the string if it doesn't already have one

This commit is contained in:
2025-09-20 03:44:48 +01:00
parent c29afbdb7c
commit 2e77175187
3 changed files with 137 additions and 270 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -17,10 +17,7 @@ struct
fun applyChars (historyString, app) = updateLoop (0, historyString, app)
fun appFromText text =
let val buffer = LineGap.fromString text
in TestUtils.init buffer
end
fun appFromText text = TestUtils.init text
fun loadFromFile (io, acc) =
case TextIO.inputLine io of
@@ -36,22 +33,19 @@ struct
str
end
val initialApp = appFromText initialText
val charEventTests = describe "CHAR_EVENT regressions"
[ test "SearchList.goToNum vector bounds regression (1)" (fn _ =>
let
val app = appFromText initialText
val app = TestUtils.init initialText
val history = "G12dk"
val newApp = applyChars (history, app)
in
(* just expect that we do not fail or throw an exception *)
Expect.isTrue true
end)
,
test "idk yet" (fn _ =>
, test "No error raised when moving cursor up/down after deleting" (fn _ =>
let
val app = appFromText initialText
val app = TestUtils.init initialText
val history =
"16G18ddjjjjjjjjjdkdkdkjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj"
val newApp = applyChars (history, app)

View File

@@ -1,7 +1,18 @@
structure TestUtils =
struct
fun init buffer =
AppType.init (buffer, 0, 0, Time.now ())
fun withUnixLineEndings str =
if String.size str > 0 andalso String.sub (str, String.size str - 1) = #"\n" then
str
else
str ^ "\n"
fun init bufferString =
let
val bufferString = withUnixLineEndings bufferString
val buffer = LineGap.fromString bufferString
in
AppType.init (buffer, 0, 0, Time.now ())
end
fun update (app, cmd) =
AppUpdate.update (app, cmd, Time.now ())