source: trunk/source/tests/ansi-tests/read.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: 3.1 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Fri Dec 31 07:52:06 2004
4;;;; Contains: Tests of READ
5
6(in-package :cl-test)
7
8;;; Input stream designators
9
10(deftest read.1
11  (block done
12    (with-input-from-string
13     (is "1 2 3")
14     (with-output-to-string
15       (os)
16       (with-open-stream
17        (*terminal-io* (make-two-way-stream is os))
18        (return-from done (read t))))))
19  1)
20
21(deftest read.2
22  (with-input-from-string
23   (*standard-input* "1 2 3")
24   (read nil))
25  1)
26
27(deftest read.3
28  (with-input-from-string
29   (*standard-input* "1 2 3")
30   (read))
31  1)
32
33(deftest read.4
34  (with-input-from-string
35   (s "1 2 3")
36   (read s))
37  1)
38
39;;; eof handling
40
41(deftest read.5
42  (with-input-from-string (s "") (read s nil))
43  nil)
44
45(deftest read.6
46  (with-input-from-string (s "") (read s nil 'foo))
47  foo)
48
49(deftest read.7
50  (with-input-from-string (s "1") (read s))
51  1)
52
53(deftest read.8
54  (let ((*package* (find-package "CL-TEST")))
55    (with-input-from-string (s "X") (read s)))
56  |X|)
57
58(deftest read.9
59  (with-input-from-string (s "1.2") (read s))
60  1.2)
61
62(deftest read.10
63  (with-input-from-string (s "1.0s0") (read s))
64  1.0s0)
65
66(deftest read.11
67  (with-input-from-string (s "1.0f0") (read s))
68  1.0f0)
69
70(deftest read.12
71  (with-input-from-string (s "1.0d0") (read s))
72  1.0d0)
73
74(deftest read.13
75  (with-input-from-string (s "1.0l0") (read s))
76  1.0l0)
77
78(deftest read.14
79  (with-input-from-string (s "()") (read s))
80  nil)
81
82(deftest read.15
83  (with-input-from-string (s "(1 2 3)") (read s))
84  (1 2 3))
85
86;;; Throwing away whitespace chars
87
88(deftest read.16
89  (with-standard-io-syntax
90   (with-input-from-string
91    (s ":ABC X")
92    (assert (eq (read s) :|ABC|))
93    (read-char s)))
94  #\X)
95
96(deftest read.17
97  (with-standard-io-syntax
98   (with-input-from-string
99    (s ":ABC  X")
100    (assert (eq (read s) :|ABC|))
101    (read-char s)))
102  #\Space)
103
104(deftest read.18
105  (with-standard-io-syntax
106   (with-input-from-string
107    (s ":ABC(")
108    (assert (eq (read s) :|ABC|))
109    (read-char s)))
110  #\()
111
112;;; eof value
113
114(deftest read.19
115  (with-input-from-string
116   (s "")
117   (read s nil 'foo))
118  foo)                   
119
120;;; Error tests
121
122(deftest read.error.1
123  (signals-error (with-input-from-string (s "") (read s)) end-of-file)
124  t)
125
126(deftest read.error.2
127  (signals-error (with-input-from-string (s "") (read s)) stream-error)
128  t)
129
130(deftest read.error.3
131  (signals-error (with-input-from-string (s "") (read s t)) stream-error)
132  t)
133
134(deftest read.error.4
135  (signals-error (with-input-from-string (s "(") (read s nil)) end-of-file)
136  t)
137
138(deftest read.error.5
139  (signals-error (with-input-from-string (s "(") (read s t)) end-of-file)
140  t)
141
142(deftest read.error.6
143  (signals-error (with-input-from-string (s "#(") (read s t)) end-of-file)
144  t)
145
146(deftest read.error.7
147  (signals-error (with-input-from-string (s "#S(") (read s t)) end-of-file)
148  t)
149
150;;; Note -- cannot easily test calls with RECURSIVE-P set to T
151;;; These have to be done from reader macro functions so that READ is not
152;;; called without having any requisite dynamic environment created
153;;; around the call.
154
155(deftest read.error.8
156  (signals-error
157   (with-input-from-string
158    (s "1 2 3")
159    (read s nil nil nil nil))
160   program-error)
161  t)
Note: See TracBrowser for help on using the repository browser.