Files
sml-projects/test/test-utils.sml

72 lines
1.8 KiB
Standard ML
Raw Normal View History

2025-08-20 13:50:57 +01:00
structure TestUtils =
struct
fun init bufferString =
let val buffer = LineGap.fromString bufferString
in AppType.init (buffer, 0, 0, Time.now ())
end
2025-08-20 13:50:57 +01:00
fun update (app, cmd) =
AppUpdate.update (app, cmd, Time.now ())
2025-09-20 08:09:35 +01:00
fun updateMany (app, str) =
let
fun loop (pos, app) =
if pos = String.size str then
app
else
let
val chr = String.sub (str, pos)
val chr = InputMsg.CHAR_EVENT chr
val app = update (app, chr)
in
loop (pos + 1, app)
end
in
loop (0, app)
end
2026-01-07 06:33:10 +00:00
fun expectYank (app: AppType.app_type, expectedString) =
let
open MailboxType
open DrawMsg
open Railroad
open Railroad.Test
fun loop (hd :: tl) =
(case hd of
DRAW (YANK actualString) =>
if actualString = expectedString then
Expect.isTrue (actualString = expectedString)
else
let
val () = print
("expectedString = [" ^ expectedString ^ "]\n")
val () = print ("actualString = [" ^ actualString ^ "]\n")
val () = print "\n"
in
Expect.isTrue (actualString = expectedString)
end
| _ => loop tl)
| loop ([]) =
let val () = print "no string yanked\n"
in Expect.isTrue false
end
in
loop (#msgs app)
end
fun expectNoYank (app: AppType.app_type) =
let
open MailboxType
open DrawMsg
open Railroad
open Railroad.Test
fun loop (DRAW (YANK _) :: _) = Expect.isTrue false
| loop (hd :: tl) = loop tl
| loop ([]) = Expect.isTrue true
in
loop (#msgs app)
end
2025-08-20 13:50:57 +01:00
end