/core/io/streams/c/c-tests.factor

http://github.com/abeaumont/factor · Factor · 33 lines · 26 code · 5 blank · 2 comment · 0 complexity · fe4588a6ad93a52c9ea4730a4061e9d6 MD5 · raw file

  1. USING: tools.test io.files io.files.temp io io.streams.c
  2. io.encodings.ascii strings destructors kernel specialized-arrays
  3. alien.c-types math alien.data ;
  4. SPECIALIZED-ARRAY: int
  5. IN: io.streams.c.tests
  6. [ "hello world" ] [
  7. "hello world" "test.txt" temp-file ascii set-file-contents
  8. "test.txt" temp-file "rb" fopen <c-reader> stream-contents
  9. >string
  10. ] unit-test
  11. ! Writing specialized arrays to binary streams
  12. [ ] [
  13. "test.txt" temp-file "wb" fopen <c-writer> [
  14. int-array{ 1 2 3 } write
  15. ] with-output-stream
  16. ] unit-test
  17. [ int-array{ 1 2 3 } ] [
  18. "test.txt" temp-file "rb" fopen <c-reader> [
  19. 3 4 * read
  20. ] with-input-stream
  21. int cast-array
  22. ] unit-test
  23. ! Writing strings to binary streams should fail
  24. [
  25. "test.txt" temp-file "wb" fopen <c-writer> [
  26. "OMGFAIL" write
  27. ] with-output-stream
  28. ] must-fail