tstreams.nim 968 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. _heh_
  9. '''
  10. nimout: '''
  11. I
  12. AM
  13. GROOT
  14. '''
  15. disabled: "windows"
  16. """
  17. import streams
  18. block tstreams:
  19. var outp = newFileStream(stdout)
  20. var inp = newFileStream(stdin)
  21. writeLine(outp, "Hello! What is your name?")
  22. var line = readLine(inp)
  23. writeLine(outp, "Nice name: " & line)
  24. block tstreams2:
  25. var
  26. fs = newFileStream("amissingfile.txt")
  27. line = ""
  28. echo "fs is: ",repr(fs)
  29. if not isNil(fs):
  30. while fs.readLine(line):
  31. echo line
  32. fs.close()
  33. block tstreams3:
  34. try:
  35. var fs = openFileStream("shouldneverexist.txt")
  36. except IoError:
  37. echo "threw exception"
  38. static:
  39. var s = newStringStream("I\nAM\nGROOT")
  40. for line in s.lines:
  41. echo line
  42. s.close
  43. # bug #12410
  44. var a = newStringStream "hehohihahuhyh"
  45. a.readDataStrImpl = nil
  46. var buffer = "_ooo_"
  47. doAssert a.readDataStr(buffer, 1..3) == 3
  48. echo buffer