make-string-output-stream.lsp 3.81 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 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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sat Feb 14 19:42:07 2004
;;;; Contains: Tests of MAKE-STRING-OUTPUT-STREAM

(in-package :cl-test)

(deftest make-string-output-stream.1
  (let ((s (make-string-output-stream)))
    (values
     (notnot (typep s 'stream))
     (notnot (typep s 'string-stream))
     (input-stream-p s)
     (notnot (output-stream-p s))
     (notnot (open-stream-p s))))
  t t nil t t)

(deftest make-string-output-stream.2
  (let ((s (make-string-output-stream :element-type 'character)))
    (values
     (notnot (typep s 'stream))
     (notnot (typep s 'string-stream))
     (input-stream-p s)
     (notnot (output-stream-p s))
     (notnot (open-stream-p s))))
  t t nil t t)

(deftest make-string-output-stream.3
  (let ((s (make-string-output-stream :element-type 'base-char)))
    (values
     (notnot (typep s 'stream))
     (notnot (typep s 'string-stream))
     (input-stream-p s)
     (notnot (output-stream-p s))
     (notnot (open-stream-p s))))
  t t nil t t)

(deftest make-string-output-stream.4
  :notes (:nil-vectors-are-strings)
  (let ((s (make-string-output-stream :element-type nil)))
    (values
     (notnot (typep s 'stream))
     (notnot (typep s 'string-stream))
     (input-stream-p s)
     (notnot (output-stream-p s))
     (notnot (open-stream-p s))))
  t t nil t t)

(deftest make-string-output-stream.5
  (let ((s (make-string-output-stream :allow-other-keys nil)))
    (values
     (notnot (typep s 'stream))
     (notnot (typep s 'string-stream))
     (input-stream-p s)
     (notnot (output-stream-p s))
     (notnot (open-stream-p s))))
  t t nil t t)

(deftest make-string-output-stream.6
  (let ((s (make-string-output-stream :allow-other-keys t :foo 'bar)))
    (values
     (notnot (typep s 'stream))
     (notnot (typep s 'string-stream))
     (input-stream-p s)
     (notnot (output-stream-p s))
     (notnot (open-stream-p s))))
  t t nil t t)

(deftest make-string-output-stream.7
  (let ((s (make-string-output-stream :foo 'bar :allow-other-keys t
sds's avatar
sds committed
71 72
                                      :allow-other-keys nil
                                      :foo2 'x)))
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
    (values
     (notnot (typep s 'stream))
     (notnot (typep s 'string-stream))
     (input-stream-p s)
     (notnot (output-stream-p s))
     (notnot (open-stream-p s))))
  t t nil t t)

(deftest make-string-output-stream.8
  (let ((s (make-string-output-stream)))
    (write-string "abc" s)
    (write-string "def" s)
    (get-output-stream-string s))
  "abcdef")

(deftest make-string-output-stream.9
  (let ((s (make-string-output-stream :element-type 'character)))
    (write-string "abc" s)
    (write-string "def" s)
    (get-output-stream-string s))
  "abcdef")

(deftest make-string-output-stream.10
  (let ((s (make-string-output-stream :element-type 'base-char)))
    (write-string "abc" s)
    (write-string "def" s)
    (get-output-stream-string s))
  "abcdef")

(deftest make-string-output-stream.11
  :notes (:nil-vectors-are-strings)
  (let ((s (make-string-output-stream :element-type nil)))
    (get-output-stream-string s))
  "")

108 109 110 111 112 113 114
(deftest make-string-output-stream.12
  :notes (:nil-vectors-are-strings)
  (let ((s (make-string-output-stream :element-type nil)))
    (typep #\a (array-element-type (get-output-stream-string s))))
  nil)

(deftest make-string-output-stream.13
115 116 117 118 119
  (let ((s (make-string-output-stream)))
    (values
     (close s)
     (open-stream-p s)))
  t nil)
120 121 122 123 124 125 126 127 128 129 130 131 132

;;; Error tests

(deftest make-string-output-stream.error.1
  (signals-error (make-string-output-stream nil) program-error)
  t)

(deftest make-string-output-stream.error.2
  (signals-error (make-string-output-stream :foo nil) program-error)
  t)

(deftest make-string-output-stream.error.3
  (signals-error (make-string-output-stream :allow-other-keys nil
sds's avatar
sds committed
133 134
                                            :foo 'bar)
                 program-error)
135 136 137 138 139
  t)