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

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

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

File size: 6.3 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Sat Jan  1 14:50:09 2005
4;;;; Contains: Tests of READ-FROM-STRING
5
6(in-package :cl-test)
7
8(deftest read-from-string.1
9  (let ((*package* (find-package :cl-test)))
10    (do-special-strings
11     (s "123")
12     (let ((vals (multiple-value-list (read-from-string s))))
13       (assert (= (length vals) 2))
14       (assert (eql (first vals) 123))
15       (assert (member (second vals) '(3 4))))))
16  nil)
17
18(deftest read-from-string.2
19  (let ((*package* (find-package :cl-test)))
20    (do-special-strings
21     (s "XYZ   ")
22     (let ((vals (multiple-value-list (read-from-string s))))
23       (assert (equal vals '(|XYZ| 4))))))
24  nil)
25
26(deftest read-from-string.3
27  (let ((*package* (find-package :cl-test)))
28    (do-special-strings
29     (s "(1 2 3)X")
30     (let ((vals (multiple-value-list (read-from-string s))))
31       (assert (equal vals '((1 2 3) 7))))))
32  nil)
33
34(deftest read-from-string.4
35  (do-special-strings
36     (s "")
37     (let ((vals (multiple-value-list (read-from-string s nil :good))))
38       (assert (= (length vals) 2))
39       (assert (equal (first vals) :good))
40       (assert (member (second vals) '(0 1)))))
41  nil)
42
43(deftest read-from-string.5
44  (let ((*package* (find-package :cl-test)))
45    (do-special-strings
46     (s "71235")
47     (let ((vals (multiple-value-list
48                  (read-from-string s t nil :start 1 :end 4))))
49       (assert (equal vals '(123 4))))))
50  nil)
51
52(deftest read-from-string.6
53  (let ((*package* (find-package :cl-test)))
54    (do-special-strings
55     (s "7123  ")
56     (let ((vals (multiple-value-list
57                  (read-from-string s t nil :start 1))))
58       (assert (equal vals '(123 5))))))
59  nil)
60
61
62(deftest read-from-string.7
63  (let ((*package* (find-package :cl-test)))
64    (do-special-strings
65     (s "7123  ")
66     (let ((vals (multiple-value-list
67                  (read-from-string s t nil :end 4))))
68       (assert (equal vals '(7123 4))))))
69  nil)
70
71(deftest read-from-string.8
72  (let ((*package* (find-package :cl-test)))
73    (do-special-strings
74     (s "7123")
75     (let ((vals (multiple-value-list
76                  (read-from-string s nil 'foo :start 2 :end 2))))
77       (assert (equal vals '(foo 2))))))
78  nil)
79
80(deftest read-from-string.9
81  (let ((*package* (find-package :cl-test)))
82    (do-special-strings
83     (s "123  ")
84     (let ((vals (multiple-value-list
85                  (read-from-string s t nil :preserve-whitespace t))))
86       (assert (equal vals '(123 3))))))
87  nil)
88
89(deftest read-from-string.10
90  (let ((*package* (find-package :cl-test)))
91    (do-special-strings
92     (s (concatenate 'string "( )" (string #\Newline)))
93     (let ((vals (multiple-value-list
94                  (read-from-string s t nil :preserve-whitespace t))))
95       (assert (equal vals '(nil 3))))))
96  nil)
97
98;;; Multiple keywords
99
100(deftest read-from-string.11
101  (let ((*package* (find-package :cl-test)))
102    (do-special-strings
103     (s "7123  ")
104     (let ((vals (multiple-value-list
105                  (read-from-string s t nil :start 1 :start 2))))
106       (assert (equal vals '(123 5))))))
107  nil)
108
109(deftest read-from-string.12
110  (let ((*package* (find-package :cl-test)))
111    (do-special-strings
112     (s "7123  ")
113     (let ((vals (multiple-value-list
114                  (read-from-string s t nil :end 4 :end 2))))
115       (assert (equal vals '(7123 4))))))
116  nil)
117
118(deftest read-from-string.13
119  (let ((*package* (find-package :cl-test)))
120    (do-special-strings
121     (s (concatenate 'string "( )" (string #\Newline)))
122     (let ((vals (multiple-value-list
123                  (read-from-string s t nil :preserve-whitespace t
124                                    :preserve-whitespace nil))))
125       (assert (equal vals '(nil 3))))))
126  nil)
127
128;;; Allow other keys
129
130(deftest read-from-string.14
131  (with-standard-io-syntax
132   (let ((*package* (find-package :cl-test)))
133     (do-special-strings
134      (s "abc   ")
135      (let ((vals (multiple-value-list
136                   (read-from-string s t nil :allow-other-keys nil))))
137        (assert (equal vals '(|ABC| 4)) (vals) "VALS is ~A" vals)))))
138  nil)
139
140(deftest read-from-string.15
141  (let ((*package* (find-package :cl-test)))
142    (do-special-strings
143     (s "123   ")
144     (let ((vals (multiple-value-list
145                  (read-from-string s t nil :foo 'bar :allow-other-keys t))))
146       (assert (equal vals '(123 4)) (vals) "VALS is ~A" vals))))
147  nil)
148
149(deftest read-from-string.16
150  (let ((*package* (find-package :cl-test)))
151    (do-special-strings
152     (s "123   ")
153     (let ((vals (multiple-value-list
154                  (read-from-string s t nil :allow-other-keys t
155                                    :allow-other-keys nil :foo 'bar))))
156       (assert (equal vals '(123 4)) (vals) "VALS is ~A" vals))))
157  nil)
158
159;;; default for :end
160
161(deftest read-from-string.17
162  (let ((*package* (find-package :cl-test)))
163    (do-special-strings
164     (s "XYZ   ")
165     (let ((vals (multiple-value-list (read-from-string s t nil :end nil))))
166       (assert (equal vals '(|XYZ| 4))))))
167  nil)
168
169;;; TODO  Add tests for reading from strings containing non-base characters
170
171;;; Error tests
172
173(deftest read-from-string.error.1
174  (signals-error (read-from-string "") error)
175  t)
176
177(deftest read-from-string.error.2
178  (signals-error (read-from-string "(A B ") error)
179  t)
180
181(deftest read-from-string.error.3
182  (signals-error (read-from-string "" t) error)
183  t)
184
185(deftest read-from-string.error.4
186  (signals-error (read-from-string "" t nil) error)
187  t)
188
189(deftest read-from-string.error.5
190  (signals-error (read-from-string "(A B " nil) error)
191  t)
192
193(deftest read-from-string.error.6
194  (signals-error (read-from-string "(A B " t) error)
195  t)
196
197(deftest read-from-string.error.7
198  (signals-error (read-from-string "123" t nil :start 0 :end 0) error)
199  t)
200
201(deftest read-from-string.error.8
202  (signals-error (read-from-string) program-error)
203  t)
204
205(deftest read-from-string.error.9
206  (signals-error (read-from-string "A" nil t :bad-keyword t) program-error)
207  t)
208
209
210(deftest read-from-string.error.10
211  (signals-error (read-from-string "A" nil t
212                                   :bad-keyword t
213                                   :allow-other-keys nil)
214                 program-error)
215  t)
216
217(deftest read-from-string.error.11
218  (signals-error (read-from-string "A" nil t
219                                   :bad-keyword t
220                                   :allow-other-keys nil
221                                   :allow-other-keys t)
222                 program-error)
223  t)
224
225(deftest read-from-string.error.12
226  (signals-error (read-from-string "A" nil t
227                                   :allow-other-keys nil
228                                   :allow-other-keys t
229                                   :bad-keyword t)
230                 program-error)
231  t)
232
233(deftest read-from-string.error.13
234  (signals-error (read-from-string "A" nil t :start)
235                 program-error)
236  t)
237
238
Note: See TracBrowser for help on using the repository browser.