source: trunk/source/tests/ansi-tests/with-input-from-string.lsp @ 8991

Last change on this file since 8991 was 8991, checked in by gz, 12 years ago

Check in the gcl ansi test suite (original, in preparation for making local changes)

File size: 5.6 KB
RevLine 
[8991]1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Sat Feb 14 20:13:02 2004
4;;;; Contains: Tests of WITH-INPUT-FROM-STRING
5
6(in-package :cl-test)
7
8(deftest with-input-from-string.1
9  (with-input-from-string
10   (s "abc")
11   (values (read-char s) (read-char s) (read-char s) (read-char s nil :eof)))
12  #\a #\b #\c :eof)
13
14(deftest with-input-from-string.2
15  (with-input-from-string (s "abc"))
16  nil)
17
18(deftest with-input-from-string.3
19  (with-input-from-string (s "abc") (declare (optimize speed)))
20  nil)
21
22(deftest with-input-from-string.3a
23  (with-input-from-string (s "abc")
24                          (declare (optimize speed))
25                          (declare (optimize space)))
26  nil)
27
28(deftest with-input-from-string.4
29  (with-input-from-string
30   (s "abc")
31   (declare (optimize safety))
32   (read-char s)
33   (read-char s))
34  #\b)
35
36(deftest with-input-from-string.5
37  (let ((i nil))
38    (values
39     (with-input-from-string
40      (s "abc" :index i))
41     i))
42  nil 0)
43
44(deftest with-input-from-string.6
45  (let ((i (list nil)))
46    (values
47     (with-input-from-string
48      (s "abc" :index (car i)))
49     i))
50  nil (0))
51
52(deftest with-input-from-string.7
53  (let ((i nil))
54    (values
55     (with-input-from-string
56      (s "abc" :index i)
57      (list i (read-char s) i (read-char s) i))
58     i))
59  (nil #\a nil #\b nil) 2)
60
61(deftest with-input-from-string.9
62  (with-input-from-string
63   (s "abc")
64   (values
65    (notnot (typep s 'stream))
66    (notnot (typep s 'string-stream))
67    (notnot (open-stream-p s))
68    (notnot (input-stream-p s))
69    (output-stream-p s)))
70  t t t t nil)
71
72(deftest with-input-from-string.10
73  :notes (:nil-vectors-are-strings)
74  (with-input-from-string
75   (s (make-array 0 :element-type nil))
76   (values
77    (notnot (typep s 'stream))
78    (notnot (typep s 'string-stream))
79    (notnot (open-stream-p s))
80    (notnot (input-stream-p s))
81    (output-stream-p s)))
82  t t t t nil)
83
84(deftest with-input-from-string.11
85  (with-input-from-string
86   (s (make-array 3 :element-type 'character :initial-contents "abc"))
87   (values
88    (notnot (typep s 'stream))
89    (notnot (typep s 'string-stream))
90    (notnot (open-stream-p s))
91    (notnot (input-stream-p s))
92    (output-stream-p s)
93    (read-line s)))
94  t t t t nil "abc")
95
96(deftest with-input-from-string.12
97  (with-input-from-string
98   (s (make-array 3 :element-type 'base-char :initial-contents "abc"))
99   (values
100    (notnot (typep s 'stream))
101    (notnot (typep s 'string-stream))
102    (notnot (open-stream-p s))
103    (notnot (input-stream-p s))
104    (output-stream-p s)
105    (read-line s)))
106  t t t t nil "abc")
107
108(deftest with-input-from-string.13
109  (with-input-from-string
110   (s "abcdef" :start 2)
111   (values
112    (notnot (typep s 'stream))
113    (notnot (typep s 'string-stream))
114    (notnot (open-stream-p s))
115    (notnot (input-stream-p s))
116    (output-stream-p s)
117    (read-line s)))
118  t t t t nil "cdef")
119
120(deftest with-input-from-string.14
121  (with-input-from-string
122   (s "abcdef" :end 3)
123   (values
124    (notnot (typep s 'stream))
125    (notnot (typep s 'string-stream))
126    (notnot (open-stream-p s))
127    (notnot (input-stream-p s))
128    (output-stream-p s)
129    (read-line s)))
130  t t t t nil "abc")
131
132(deftest with-input-from-string.15
133  (with-input-from-string
134   (s "abcdef" :start 1 :end 5)
135   (values
136    (notnot (typep s 'stream))
137    (notnot (typep s 'string-stream))
138    (notnot (open-stream-p s))
139    (notnot (input-stream-p s))
140    (output-stream-p s)
141    (read-line s)))
142  t t t t nil "bcde")
143
144(deftest with-input-from-string.16
145  (with-input-from-string
146   (s "abcdef" :start 1 :end nil)
147   (values
148    (notnot (typep s 'stream))
149    (notnot (typep s 'string-stream))
150    (notnot (open-stream-p s))
151    (notnot (input-stream-p s))
152    (output-stream-p s)
153    (read-line s)))
154  t t t t nil "bcdef")
155
156(deftest with-input-from-string.17
157  (let ((i 2))
158    (values
159     (with-input-from-string
160      (s "abcdef" :index i :start i)
161      (read-char s))
162     i))
163  #\c 3)
164
165;;; Test that there is no implicit tagbody
166
167(deftest with-input-from-string.18
168  (block done
169    (tagbody
170     (with-input-from-string
171      (s "abc")
172      (go 1)
173      1
174      (return-from done :bad))
175     1
176     (return-from done :good)))
177  :good)
178
179;;; Free declaration scope
180
181(deftest with-input-from-string.19
182  (block done
183    (let ((x :bad))
184      (declare (special x))
185      (let ((x :good))
186        (with-input-from-string (s (return-from done x))
187                                (declare (special x))))))
188  :good)
189
190(deftest with-input-from-string.20
191  (block done
192    (let ((x :bad))
193      (declare (special x))
194      (let ((x :good))
195        (with-input-from-string (s "abc" :start (return-from done x))
196                                (declare (special x))))))
197  :good)
198
199(deftest with-input-from-string.21
200  (block done
201    (let ((x :bad))
202      (declare (special x))
203      (let ((x :good))
204        (with-input-from-string (s "abc" :end (return-from done x))
205                                (declare (special x))))))
206  :good)
207
208;;; index is not updated if the form exits abnormally
209
210(deftest with-input-from-string.22
211  (let ((i nil))
212    (values
213     (block done
214       (with-input-from-string (s "abcde" :index i) (return-from done (read-char s))))
215     i))
216  #\a nil)
217
218;;; Test that explicit calls to macroexpand in subforms
219;;; are done in the correct environment
220
221(deftest with-input-from-string.23
222  (macrolet
223   ((%m (z) z))
224   (with-input-from-string (s (expand-in-current-env (%m "123")))
225                          (read-char s)))
226  #\1)
227
228(deftest with-input-from-string.24
229  (macrolet
230   ((%m (z) z))
231   (with-input-from-string (s "123" :start (expand-in-current-env (%m 1)))
232                           (read-char s)))
233  #\2)
234
235(deftest with-input-from-string.25
236  (macrolet
237   ((%m (z) z))
238   (with-input-from-string (s "123" :start 0
239                              :end (expand-in-current-env (%m 0)))
240                           (read-char s nil nil)))
241  nil)
242
243
244;;; FIXME: Add more tests on specialized strings.
245
Note: See TracBrowser for help on using the repository browser.