tstreams.nim 805 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. discard """
  2. input: "Arne"
  3. output: '''
  4. Hello! What is your name?
  5. Nice name: Arne
  6. fs is: nil
  7. threw exception
  8. '''
  9. nimout: '''
  10. I
  11. AM
  12. GROOT
  13. '''
  14. disabled: "windows"
  15. """
  16. import streams
  17. block tstreams:
  18. var outp = newFileStream(stdout)
  19. var inp = newFileStream(stdin)
  20. writeLine(outp, "Hello! What is your name?")
  21. var line = readLine(inp)
  22. writeLine(outp, "Nice name: " & line)
  23. block tstreams2:
  24. var
  25. fs = newFileStream("amissingfile.txt")
  26. line = ""
  27. echo "fs is: ",repr(fs)
  28. if not isNil(fs):
  29. while fs.readLine(line):
  30. echo line
  31. fs.close()
  32. block tstreams3:
  33. try:
  34. var fs = openFileStream("shouldneverexist.txt")
  35. except IoError:
  36. echo "threw exception"
  37. static:
  38. var s = newStringStream("I\nAM\nGROOT")
  39. for line in s.lines:
  40. echo line
  41. s.close