Files
enso/tests/test.nim

54 lines
1.2 KiB
Nim

import enso
import std/[options, strformat, sugar]
proc unsafe_void(str: string) =
echo str
proc unsafe_int(str: string): int =
echo str
result = 1
func main() =
run strput("Hello from Enso!")
let
out_void: IO[void] = lift () => unsafe_void("void")
out_int: IO[int] = lift () => unsafe_int("int")
out_void()
run strput(fmt"{out_int()}")
let get_filename: IO[string] =
proc(): string =
let name: IO[string] = readln(stdin)
echo "Enter the file name:"
name()
let
nested: IO[IO[Option[string]]] = get_filename.map(fileread)
joined: IO[Option[string]] = nested.join
join_opt: Option[string] = joined()
if join_opt.isSome:
run strput(join_opt.get)
else:
run strput("joined had no data")
let
flat: IO[Option[string]] = get_filename.flatmap(fileread)
flat_opt: Option[string] = flat()
if flat_opt.isSome:
run strput(flat_opt.get)
else:
run strput("flat had no data")
let writer: IO[Option[Unit]] = filewrite("Hello world!\n", "test.txt")
if writer().isSome:
run strput("Successfully wrote test.txt!")
else:
run strput("Could not write test.txt!")
when isMainModule:
main()