tstreams.nim 317 B

1234567891011121314151617181920212223
  1. discard """
  2. output: '''
  3. I
  4. AM
  5. GROOT
  6. '''
  7. """
  8. import streams
  9. var s = newStringStream("I\nAM\nGROOT")
  10. doAssert s.peekStr(1) == "I"
  11. doAssert s.peekChar() == 'I'
  12. for line in s.lines:
  13. echo line
  14. s.close
  15. var s2 = newStringStream("abc")
  16. doAssert s2.readAll == "abc"
  17. s2.write("def")
  18. doAssert s2.data == "abcdef"
  19. s2.close