lean4-htt/tests/lean/run/3546.lean
Henrik Böving 7776852d22
feat: revamp file IO, this time Windows compatible (#4950)
This implements a naive version of `getline` because Windows does not
have `getline`. Given the fact that `FILE` has buffered IO, calling
`fgetc` in a loop is not as big of a performance hazard as it might seem
at first glance.

The proper solution to this would of course be to have our own buffered
IO so we are fully in charge of the buffer. In this situation we could
check the entire buffer for a newline at once instead of char by char.
However that is not going to happen for the near future so I propose we
stay with this implementation. If reading individual lines of a file
does truly end up being the performance bottle neck we have already
won^^.
2024-08-07 22:33:37 +02:00

14 lines
430 B
Text

def test : IO Unit := do
let tmpFile := "3546.tmp"
let firstLine := "foo\u0000bar\n"
let content := firstLine ++ "hello world\nbye"
IO.FS.writeFile tmpFile content
let handle ← IO.FS.Handle.mk tmpFile .read
let firstReadLine ← handle.getLine
let cond := firstLine == firstReadLine && firstReadLine.length == 8 -- paranoid
IO.println cond
IO.FS.removeFile tmpFile
/-- info: true -/
#guard_msgs in
#eval test