source: trunk/source/tests/ansi-tests/loop12.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: 4.4 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Sun Nov 17 08:47:43 2002
4;;;; Contains: Tests for ALWAYS, NEVER, THEREIS
5
6(in-package :cl-test)
7
8;;; Tests of ALWAYS clauses
9
10(deftest loop.12.1
11  (loop for i in '(1 2 3 4) always (< i 10))
12  t)
13
14(deftest loop.12.2
15  (loop for i in nil always nil)
16  t)
17
18(deftest loop.12.3
19  (loop for i in '(a) always nil)
20  nil)
21
22(deftest loop.12.4
23  (loop for i in '(1 2 3 4 5 6 7)
24        always t
25        until (> i 5))
26  t)
27
28(deftest loop.12.5
29  (loop for i in '(1 2 3 4 5 6 7)
30        always (< i 6)
31        until (>= i 5))
32  t)
33
34(deftest loop.12.6
35  (loop for x in '(a b c d e) always x)
36  t)
37
38(deftest loop.12.7
39  (loop for x in '(1 2 3 4 5 6)
40        always (< x 20)
41        never (> x 10))
42  t)
43
44(deftest loop.12.8
45  (loop for x in '(1 2 3 4 5 6)
46        always (< x 20)
47        never (> x 5))
48  nil)
49
50(deftest loop.12.9
51  (loop for x in '(1 2 3 4 5 6)
52        never (> x 5)
53        always (< x 20))
54  nil)
55
56(deftest loop.12.10
57  (loop for x in '(1 2 3 4 5)
58        always (< x 10)
59        finally (return 'good))
60  good)
61
62(deftest loop.12.11
63  (loop for x in '(1 2 3 4 5)
64        always (< x 3)
65        finally (return 'bad))
66  nil)
67
68(deftest loop.12.12
69  (loop for x in '(1 2 3 4 5 6)
70        always t
71        when (= x 4) do (loop-finish))
72  t)
73
74(deftest loop.12.13
75  (loop for x in '(1 2 3 4 5 6)
76        do (loop-finish)
77        always nil)
78  t)
79
80;;; Tests of NEVER
81
82(deftest loop.12.21
83  (loop for i in '(1 2 3 4) never (> i 10))
84  t)
85
86(deftest loop.12.22
87  (loop for i in nil never t)
88  t)
89
90(deftest loop.12.23
91  (loop for i in '(a) never t)
92  nil)
93
94(deftest loop.12.24
95  (loop for i in '(1 2 3 4 5 6 7)
96        never nil
97        until (> i 5))
98  t)
99
100(deftest loop.12.25
101  (loop for i in '(1 2 3 4 5 6 7)
102        never (>= i 6)
103        until (>= i 5))
104  t)
105
106(deftest loop.12.26
107  (loop for x in '(a b c d e) never (not x))
108  t)
109
110(deftest loop.12.30
111  (loop for x in '(1 2 3 4 5)
112        never (>= x 10)
113        finally (return 'good))
114  good)
115
116(deftest loop.12.31
117  (loop for x in '(1 2 3 4 5)
118        never (>= x 3)
119        finally (return 'bad))
120  nil)
121
122(deftest loop.12.32
123  (loop for x in '(1 2 3 4 5 6)
124        never nil
125        when (= x 4) do (loop-finish))
126  t)
127
128(deftest loop.12.33
129  (loop for x in '(1 2 3 4 5 6)
130        do (loop-finish)
131        never t)
132  t)
133
134;;; Tests of THEREIS
135
136(deftest loop.12.41
137  (loop for x in '(1 2 3 4 5)
138        thereis (and (eqlt x 3) 'good))
139  good)
140
141(deftest loop.12.42
142  (loop for x in '(nil nil a nil nil)
143        thereis x)
144  a)
145
146(deftest loop.12.43
147  (loop for x in '(1 2 3 4 5)
148        thereis (eql x 4)
149        when (eql x 2) do (loop-finish))
150  nil)
151
152;;; Error cases
153
154(deftest loop.12.error.50
155  (signals-error
156   (loop for i from 1 to 10
157         collect i
158         always (< i 20))
159   program-error)
160  t)
161
162(deftest loop.12.error.50a
163  (signals-error
164   (loop for i from 1 to 10
165         always (< i 20)
166         collect i)
167   program-error)
168  t)
169
170(deftest loop.12.error.51
171  (signals-error
172   (loop for i from 1 to 10
173         collect i
174         never (> i 20))
175   program-error)
176  t)
177
178(deftest loop.12.error.51a
179  (signals-error
180   (loop for i from 1 to 10
181         never (> i 20)
182         collect i)
183   program-error)
184  t)
185
186(deftest loop.12.error.52
187  (signals-error
188   (loop for i from 1 to 10
189         collect i
190         thereis (> i 20))
191   program-error)
192  t)
193
194(deftest loop.12.error.52a
195  (signals-error
196   (loop for i from 1 to 10
197         thereis (> i 20)
198         collect i)
199   program-error)
200  t)
201
202;;; Non-error cases
203
204(deftest loop.12.53
205  (loop for i from 1 to 10
206        collect i into foo
207        always (< i 20))
208  t)
209
210(deftest loop.12.53a
211  (loop for i from 1 to 10
212        always (< i 20)
213        collect i into foo)
214  t)
215
216(deftest loop.12.54
217  (loop for i from 1 to 10
218        collect i into foo
219        never (> i 20))
220  t)
221
222(deftest loop.12.54a
223  (loop for i from 1 to 10
224        never (> i 20)
225        collect i into foo)
226  t)
227
228(deftest loop.12.55
229  (loop for i from 1 to 10
230        collect i into foo
231        thereis i)
232  1)
233
234(deftest loop.12.55a
235  (loop for i from 1 to 10
236        thereis i
237        collect i into foo)
238  1)
239
240;;; Test that explicit calls to macroexpand in subforms
241;;; are done in the correct environment
242
243(deftest loop.12.56
244  (macrolet
245   ((%m (z) z))
246   (loop for i in '(1 2 3 4) always (expand-in-current-env (%m (< i 10)))))
247  t)
248
249(deftest loop.12.57
250  (macrolet
251   ((%m (z) z))
252   (loop for i in '(1 2 3 4) always (expand-in-current-env (%m t))))
253  t)
254
255(deftest loop.12.58
256  (macrolet
257   ((%m (z) z))
258   (loop for i in '(1 2 3 4) never (expand-in-current-env (%m (>= i 10)))))
259  t)
260
261(deftest loop.12.59
262  (macrolet
263   ((%m (z) z))
264   (loop for i in '(1 2 3 4) never (expand-in-current-env (%m t))))
265  nil)
266
267(deftest loop.12.60
268  (macrolet
269   ((%m (z) z))
270   (loop for i in '(1 2 3 4)
271         thereis (expand-in-current-env (%m (and (>= i 2) (+ i 1))))))
272  3)
273
274
Note: See TracBrowser for help on using the repository browser.