srfi-6.test 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. ;;;; srfi-6.test --- test suite for SRFI-6 -*- scheme -*-
  2. ;;;;
  3. ;;;; Copyright (C) 2003, 2006 Free Software Foundation, Inc.
  4. ;;;;
  5. ;;;; This program is free software; you can redistribute it and/or modify
  6. ;;;; it under the terms of the GNU General Public License as published by
  7. ;;;; the Free Software Foundation; either version 2, or (at your option)
  8. ;;;; any later version.
  9. ;;;;
  10. ;;;; This program is distributed in the hope that it will be useful,
  11. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;;;; GNU General Public License for more details.
  14. ;;;;
  15. ;;;; You should have received a copy of the GNU General Public License
  16. ;;;; along with this software; see the file COPYING. If not, write to
  17. ;;;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18. ;;;; Boston, MA 02110-1301 USA
  19. (use-modules (test-suite lib))
  20. ;; use #:select to see that the bindings we expect are indeed exported
  21. (use-modules ((srfi srfi-6)
  22. #:select ((open-input-string . open-input-string)
  23. (open-output-string . open-output-string)
  24. (get-output-string . get-output-string))))
  25. (with-test-prefix "open-input-string"
  26. (pass-if "eof on empty"
  27. (let ((port (open-input-string "")))
  28. (eof-object? (read-char port))))
  29. (pass-if "read-char"
  30. (let ((port (open-input-string "xyz")))
  31. (and (char=? #\x (read-char port))
  32. (char=? #\y (read-char port))
  33. (char=? #\z (read-char port))
  34. (eof-object? (read-char port)))))
  35. (with-test-prefix "unread-char"
  36. (pass-if "one char"
  37. (let ((port (open-input-string "")))
  38. (unread-char #\x port)
  39. (and (char=? #\x (read-char port))
  40. (eof-object? (read-char port)))))
  41. (pass-if "after eof"
  42. (let ((port (open-input-string "")))
  43. (and (eof-object? (read-char port))
  44. (begin
  45. (unread-char #\x port)
  46. (and (char=? #\x (read-char port))
  47. (eof-object? (read-char port)))))))
  48. (pass-if "order"
  49. (let ((port (open-input-string "")))
  50. (unread-char #\x port)
  51. (unread-char #\y port)
  52. (unread-char #\z port)
  53. (and (char=? #\z (read-char port))
  54. (char=? #\y (read-char port))
  55. (char=? #\x (read-char port))
  56. (eof-object? (read-char port)))))))
  57. (with-test-prefix "open-output-string"
  58. (pass-if "empty"
  59. (let ((port (open-output-string)))
  60. (string=? "" (get-output-string port))))
  61. (pass-if "xyz"
  62. (let ((port (open-output-string)))
  63. (display "xyz" port)
  64. (string=? "xyz" (get-output-string port))))
  65. (pass-if "seek"
  66. (let ((port (open-output-string)))
  67. (display "abcdef" port)
  68. (seek port 2 SEEK_SET)
  69. (display "--" port)
  70. (string=? "ab--ef" (get-output-string port)))))