tfile_rw.nim 589 B

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