tfile_rw.nim 544 B

1234567891011121314151617181920212223
  1. # test file read write in vm
  2. import os, strutils
  3. const filename = splitFile(currentSourcePath).dir / "tfile_rw.txt"
  4. const mytext = "line1\nline2\nline3"
  5. static:
  6. writeFile(filename, mytext)
  7. const myfile_str = staticRead(filename)
  8. const myfile_str2 = readFile(filename)
  9. const myfile_str_seq = readLines(filename, 3)
  10. static:
  11. doAssert myfile_str == mytext
  12. doAssert myfile_str2 == mytext
  13. doAssert myfile_str_seq[0] == "line1"
  14. doAssert myfile_str_seq[1] == "line2"
  15. doAssert myfile_str_seq.join("\n") == mytext
  16. removeFile(filename)