make-synonym-stream.lsp 2.59 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Wed Jan 28 06:54:33 2004
;;;; Contains: Tests of MAKE-SYNONYM-STREAM

(in-package :cl-test)

(deftest make-synonym-stream.1
  (with-input-from-string
   (*s* "abcde")
   (declare (special *s*))
   (let ((ss (make-synonym-stream '*s*)))
     (assert (typep ss 'stream))
     (assert (typep ss 'synonym-stream))
     (assert (input-stream-p ss))
16 17 18 19
     (assert (not (output-stream-p ss)))
     (assert (open-stream-p ss))
     (assert (streamp ss))
     (assert (stream-element-type ss))
20 21 22 23 24 25 26 27 28
     (values
      (read-char *s*)
      (read-char ss)
      (read-char *s*)
      (read-char ss)
      (read-char ss))))
  #\a #\b #\c #\d #\e)


29 30
;;; This test was wrong (section 21.1.4)
#|
31 32 33 34 35 36 37 38
(deftest make-synonym-stream.2
   (let ((ss (make-synonym-stream '*s*)))
     (with-input-from-string
      (*s* "z")
      (declare (special *s*))
      (assert (typep ss 'stream))
      (assert (typep ss 'synonym-stream))
      (assert (input-stream-p ss))
39 40 41 42
      (assert (not (output-stream-p ss)))
      (assert (open-stream-p ss))
      (assert (streamp ss))
      (assert (stream-element-type ss))
43 44
      (read-char ss)))
   #\z)
45
|#
46 47 48 49 50 51 52 53 54

(deftest make-synonym-stream.3
  (with-output-to-string
   (*s*)
   (declare (special *s*))
   (let ((ss (make-synonym-stream '*s*)))
     (assert (typep ss 'stream))
     (assert (typep ss 'synonym-stream))
     (assert (output-stream-p ss))
55 56 57 58
     (assert (not (input-stream-p ss)))
     (assert (open-stream-p ss))
     (assert (streamp ss))
     (assert (stream-element-type ss))
59 60 61 62 63 64
     (write-char #\a *s*)
     (write-char #\b ss)
     (write-char #\x *s*)
     (write-char #\y ss)))
  "abxy")

65 66 67 68 69 70 71 72 73 74 75 76 77
(deftest make-synonym-stream.4
  (let ((ss (make-synonym-stream '*terminal-io*)))
     (assert (typep ss 'stream))
     (assert (typep ss 'synonym-stream))
     (assert (output-stream-p ss))
     (assert (input-stream-p ss))
     (assert (open-stream-p ss))
     (assert (streamp ss))
     (assert (stream-element-type ss))
     nil)
  nil)


78
;;; FIXME
79
;;; Add tests for: close,
80 81 82 83 84
;;;  peek-char, read-char-no-hang, terpri, fresh-line, unread-char,
;;;  read-line, write-line, write-string, read-sequence, write-sequence,
;;;  read-byte, write-byte, listen, clear-input, finish-output, force-output,
;;;  clear-output, format, print, prin1, princ

85 86 87 88 89 90 91 92 93 94 95
;;; Error cases

(deftest make-synonym-stream.error.1
  (signals-error (make-synonym-stream) program-error)
  t)

(deftest make-synonym-stream.error.2
  (signals-error (make-synonym-stream '*standard-input* nil) program-error)
  t)

(deftest make-synonym-stream.error.3
pfdietz's avatar
pfdietz committed
96
  (check-type-error #'make-synonym-stream #'symbolp)
97
  nil)