make-concatenated-stream.lsp 8.45 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sat Feb 14 08:41:18 2004
;;;; Contains: Tests of MAKE-CONCATENATED-STREAM

(in-package :cl-test)

(deftest make-concatenated-stream.1
  (let ((s (make-concatenated-stream)))
    (read s nil :eof))
  :eof)

(deftest make-concatenated-stream.2
  (let ((s (make-concatenated-stream)))
    (notnot-mv (input-stream-p s)))
  t)

(deftest make-concatenated-stream.3
  (let ((s (make-concatenated-stream)))
    (output-stream-p s))
  nil)

23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
(deftest make-concatenated-stream.4
  (let ((s (make-concatenated-stream)))
    (notnot-mv (streamp s)))
  t)

(deftest make-concatenated-stream.5
  (let ((s (make-concatenated-stream)))
    (notnot-mv (typep s 'stream)))
  t)

(deftest make-concatenated-stream.6
  (let ((s (make-concatenated-stream)))
    (notnot-mv (typep s 'concatenated-stream)))
  t)

(deftest make-concatenated-stream.7
  (let ((s (make-concatenated-stream)))
    (notnot-mv (open-stream-p s)))
  t)

(deftest make-concatenated-stream.8
  (let ((s (make-concatenated-stream *standard-input*)))
    (notnot-mv (stream-element-type s)))
  t)

(deftest make-concatenated-stream.9
  (let ((pn #p"tmp.dat")
sds's avatar
sds committed
50
        (element-type '(unsigned-byte 8)))
51
    (with-open-file (s pn :direction :output :element-type element-type
sds's avatar
sds committed
52 53
                       :if-exists :supersede)
                    (dolist (b '(1 5 9 13)) (write-byte b s)))
54 55 56 57 58
    (with-open-file
     (s1 pn :direction :input :element-type element-type)
     (with-open-file
      (s2 pn :direction :input :element-type element-type)
      (let ((s (make-concatenated-stream s1 s2)))
sds's avatar
sds committed
59
        (loop repeat 8 collect (read-byte s))))))
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
  (1 5 9 13 1 5 9 13))

(deftest make-concatenated-stream.10
  (let ((s (make-concatenated-stream)))
    (read-byte s nil :eof))
  :eof)

(deftest make-concatenated-stream.11
  (let ((s (make-concatenated-stream)))
    (peek-char nil s nil :eof))
  :eof)

(deftest make-concatenated-stream.12
  (with-input-from-string
   (s1 "a")
   (with-input-from-string
    (s2 "b")
    (let ((s (make-concatenated-stream s1 s2)))
      (values
       (peek-char nil s)
       (read-char s)
       (peek-char nil s)
       (read-char s)
       (peek-char nil s nil :eof)))))
  #\a #\a #\b #\b :eof)

(deftest make-concatenated-stream.13
  (with-input-from-string
   (s1 "  a  ")
   (with-input-from-string
    (s2 "  b  ")
    (let ((s (make-concatenated-stream s1 s2)))
      (values
       (peek-char t s)
       (read-char s)
       (peek-char t s)
       (read-char s)
       (peek-char t s nil :eof)))))
  #\a #\a #\b #\b :eof)

(deftest make-concatenated-stream.14
  (with-input-from-string
   (s1 "a")
   (with-input-from-string
    (s2 "b")
    (let ((s (make-concatenated-stream s1 s2)))
      (values
       (read-char s)
       (unread-char #\a s)
       (read-char s)
       (read-char s)
       (unread-char #\b s)
       (read-char s)
       (read-char s nil :eof)))))
  #\a nil #\a #\b nil #\b :eof)

(deftest make-concatenated-stream.15
  (let ((s (make-concatenated-stream)))
    (read-char-no-hang s nil :eof))
  :eof)

(deftest make-concatenated-stream.16
  (with-input-from-string
   (s1 "a")
   (with-input-from-string
    (s2 "b")
    (let ((s (make-concatenated-stream s1 s2)))
      (values
       (read-char-no-hang s)
       (read-char-no-hang s)
       (read-char-no-hang s nil :eof)))))
  #\a #\b :eof)

133 134 135 136 137 138 139
(deftest make-concatenated-stream.17
  (with-input-from-string
   (s1 "a")
   (with-input-from-string
    (s2 "b")
    (let ((s (make-concatenated-stream s1 s2)))
      (multiple-value-bind (str mnp)
sds's avatar
sds committed
140 141
          (read-line s)
        (values str (notnot mnp))))))
142 143 144 145 146 147 148 149 150
  "ab" t)

(deftest make-concatenated-stream.18
  (with-input-from-string
   (s1 "ab")
   (with-input-from-string
    (s2 "")
    (let ((s (make-concatenated-stream s1 s2)))
      (multiple-value-bind (str mnp)
sds's avatar
sds committed
151 152
          (read-line s)
        (values str (notnot mnp))))))
153 154 155 156 157 158 159 160 161
  "ab" t)

(deftest make-concatenated-stream.19
  (with-input-from-string
   (s1 "")
   (with-input-from-string
    (s2 "ab")
    (let ((s (make-concatenated-stream s1 s2)))
      (multiple-value-bind (str mnp)
sds's avatar
sds committed
162 163
          (read-line s)
        (values str (notnot mnp))))))
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
  "ab" t)

(deftest make-concatenated-stream.20
  (with-input-from-string
   (s1 "ab")
   (with-input-from-string
    (s2 (concatenate 'string (string #\Newline) "def"))
    (let ((s (make-concatenated-stream s1 s2)))
      (read-line s))))
  "ab" nil)

(deftest make-concatenated-stream.21
  (with-input-from-string
   (s1 "")
   (with-input-from-string
    (s2 "")
    (let ((s (make-concatenated-stream s1 s2)))
      (multiple-value-bind (str mnp)
sds's avatar
sds committed
182 183
          (read-line s nil :eof)
        (values str (notnot mnp))))))
184 185 186 187
  :eof t)

(deftest make-concatenated-stream.22
  (let ((pn #p"tmp.dat")
sds's avatar
sds committed
188
        (element-type '(unsigned-byte 8)))
189
    (with-open-file (s pn :direction :output :element-type element-type
sds's avatar
sds committed
190 191
                       :if-exists :supersede)
                    (dolist (b '(1 5 9 13)) (write-byte b s)))
192 193 194 195 196
    (with-open-file
     (s1 pn :direction :input :element-type element-type)
     (with-open-file
      (s2 pn :direction :input :element-type element-type)
      (let ((s (make-concatenated-stream s1 s2))
sds's avatar
sds committed
197 198 199 200
            (x (vector nil nil nil nil nil nil nil nil)))
        (values
         (read-sequence x s)
         x)))))
201 202 203 204 205
  8
  #(1 5 9 13 1 5 9 13))

(deftest make-concatenated-stream.23
  (let ((pn #p"tmp.dat")
sds's avatar
sds committed
206
        (element-type '(unsigned-byte 8)))
207
    (with-open-file (s pn :direction :output :element-type element-type
sds's avatar
sds committed
208 209
                       :if-exists :supersede)
                    (dolist (b '(1 5 9 13)) (write-byte b s)))
210 211 212 213 214
    (with-open-file
     (s1 pn :direction :input :element-type element-type)
     (with-open-file
      (s2 pn :direction :input :element-type element-type)
      (let ((s (make-concatenated-stream s1 s2))
sds's avatar
sds committed
215 216 217 218
            (x (vector nil nil nil nil nil nil)))
        (values
         (read-sequence x s)
         x)))))
219 220 221 222 223
  6
  #(1 5 9 13 1 5))

(deftest make-concatenated-stream.24
  (let ((pn #p"tmp.dat")
sds's avatar
sds committed
224
        (element-type '(unsigned-byte 8)))
225
    (with-open-file (s pn :direction :output :element-type element-type
sds's avatar
sds committed
226 227
                       :if-exists :supersede)
                    (dolist (b '(1 5 9 13)) (write-byte b s)))
228 229 230 231 232
    (with-open-file
     (s1 pn :direction :input :element-type element-type)
     (with-open-file
      (s2 pn :direction :input :element-type element-type)
      (let ((s (make-concatenated-stream s1 s2))
sds's avatar
sds committed
233 234 235 236
            (x (vector nil nil nil nil nil nil nil nil nil nil)))
        (values
         (read-sequence x s)
         x)))))
237 238 239 240 241 242 243 244 245 246
  8
  #(1 5 9 13 1 5 9 13 nil nil))

(deftest make-concatenated-stream.25
  (close (make-concatenated-stream))
  t)

(deftest make-concatenated-stream.26
  (let ((s (make-concatenated-stream)))
    (values (prog1 (close s) (close s))
sds's avatar
sds committed
247
            (open-stream-p s)))
248 249 250 251 252 253 254 255 256 257 258 259 260 261
  t nil)

(deftest make-concatenated-stream.27
  (with-input-from-string
   (s1 "abc")
   (let ((s (make-concatenated-stream s1)))
     (values
      (notnot (open-stream-p s1))
      (notnot (open-stream-p s))
      (close s)
      (notnot (open-stream-p s1))
      (open-stream-p s))))
  t t t t nil)

262 263 264 265 266 267 268
(deftest make-concatenated-stream.28
  (with-input-from-string
   (s1 "a")
   (let ((s (make-concatenated-stream s1)))
     (notnot-mv (listen s))))
  t)

pfdietz's avatar
pfdietz committed
269
(deftest make-concatenated-stream.28a
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
  (listen (make-concatenated-stream))
  nil)

(deftest make-concatenated-stream.29
  (with-input-from-string
   (s1 "")
   (let ((s (make-concatenated-stream s1)))
     (listen s)))
  nil)

(deftest make-concatenated-stream.30
  (with-input-from-string
   (s1 "")
   (with-input-from-string
    (s2 "a")
    (let ((s (make-concatenated-stream s1 s2)))
      (notnot-mv (listen s)))))
  t)

(deftest make-concatenated-stream.31
  (with-input-from-string
   (s1 "")
   (with-input-from-string
    (s2 "")
    (let ((s (make-concatenated-stream s1 s2)))
      (listen s))))
  nil)

298 299 300 301 302 303 304 305 306 307
(deftest make-concatenated-stream.32
  (clear-input (make-concatenated-stream))
  nil)

(deftest make-concatenated-stream.33
  (with-input-from-string
   (s1 "abc")
   (clear-input (make-concatenated-stream s1)))
  nil)

308 309 310 311
;;; Error cases

(deftest make-concatenated-stream.error.1
  (loop for x in *mini-universe*
sds's avatar
sds committed
312 313 314
        unless (or (and (streamp x) (input-stream-p x))
                   (eval `(signals-error (make-concatenated-stream ',x) t)))
        collect x)
315 316 317 318
  nil)

(deftest make-concatenated-stream.error.2
  (loop for x in *streams*
sds's avatar
sds committed
319 320 321
        unless (or (and (streamp x) (input-stream-p x))
                   (eval `(signals-error (make-concatenated-stream ',x) t)))
        collect x)
322 323
  nil)