source: trunk/source/tests/ansi-tests/loop11.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.9 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Sat Nov 16 21:39:33 2002
4;;;; Contains: Tests for loop termination clauses REPEAT, WHILE and UNTIL
5
6(in-package :cl-test)
7
8;;; Tests of REPEAT
9
10(deftest loop.11.1
11  (let ((z 0))
12    (values
13     (loop repeat 10 do (incf z))
14     z))
15  nil
16  10)
17
18(deftest loop.11.2
19  (loop repeat 10 collect 'a)
20  (a a a a a a a a a a))
21
22(deftest loop.11.3
23  (let ((z 0))
24    (loop repeat 0 do (incf z))
25    z)
26  0)
27
28(deftest loop.11.4
29  (let ((z 0))
30    (loop repeat -1 do (incf z))
31    z)
32  0)
33
34(deftest loop.11.5
35  (let ((z 0))
36    (loop repeat -1.5 do (incf z))
37    z)
38  0)
39
40(deftest loop.11.6
41  (let ((z 0))
42    (loop repeat -1000000000000 do (incf z))
43    z)
44  0)
45
46(deftest loop.11.7
47  (let ((z 0))
48    (loop repeat 10 do (incf z) (loop-finish))
49    z)
50  1)
51
52;;; (deftest loop.11.8
53;;;  (loop repeat 3 for i in '(a b c d e) collect i)
54;;;  (a b c))
55
56;;; Enough implementors have complained about this test that
57;;; I'm removing it.  The standard is self-contradictory
58;;; on whether REPEAT can occur later in a LOOP form.
59
60;;; (deftest loop.11.9
61;;;  (loop for i in '(a b c d e) collect i repeat 3)
62;;;  (a b c))
63
64
65;;; Tests of WHILE
66
67(deftest loop.11.10
68  (loop with i = 0 while (< i 10) collect (incf i))
69  (1 2 3 4 5 6 7 8 9 10))
70
71(deftest loop.11.11
72  (loop with i = 0 while (if (< i 10) t (return 'good))
73        collect (incf i))
74  good)
75
76(deftest loop.11.12
77  (loop with i = 0
78        while (< i 10) collect (incf i)
79        while (< i 10) collect (incf i)
80        while (< i 10) collect (incf i))
81  (1 2 3 4 5 6 7 8 9 10))
82
83(deftest loop.11.13
84  (loop with i = 0 while (< i 10) collect (incf i)
85        finally (return 'done))
86  done)
87
88(deftest loop.11.14
89  (loop for i in '(a b c)
90        while nil
91        collect i)
92  nil)
93
94(deftest loop.11.15
95  (loop for i in '(a b c)
96        collect i
97        while nil)
98  (a))
99
100(deftest loop.11.16
101  (loop for i in '(a b c)
102        while t
103        collect i)
104  (a b c))
105
106(deftest loop.11.17
107  (loop for i in '(a b c)
108        collect i
109        while t)
110  (a b c))
111
112(deftest loop.11.18
113  (loop for i from 1 to 10
114        while (< i 6)
115        finally (return i))
116  6)
117
118;;; Tests of UNTIL
119
120(deftest loop.11.20
121  (loop with i = 0 until (>= i 10) collect (incf i))
122  (1 2 3 4 5 6 7 8 9 10))
123
124(deftest loop.11.21
125  (loop with i = 0 while (if (< i 10) t (return 'good))
126        collect (incf i))
127  good)
128
129(deftest loop.11.22
130  (loop with i = 0
131        until (>= i 10) collect (incf i)
132        until (>= i 10) collect (incf i)
133        until (>= i 10) collect (incf i))
134  (1 2 3 4 5 6 7 8 9 10))
135
136(deftest loop.11.23
137  (loop with i = 0 until (>= i 10) collect (incf i)
138        finally (return 'done))
139  done)
140
141(deftest loop.11.24
142  (loop for i in '(a b c)
143        until t
144        collect i)
145  nil)
146
147(deftest loop.11.25
148  (loop for i in '(a b c)
149        collect i
150        until t)
151  (a))
152
153(deftest loop.11.26
154  (loop for i in '(a b c)
155        until nil
156        collect i)
157  (a b c))
158
159(deftest loop.11.27
160  (loop for i in '(a b c)
161        collect i
162        until nil)
163  (a b c))
164
165(deftest loop.11.28
166  (loop for i from 1 to 10
167        until (>= i 6)
168        finally (return i))
169  6)
170
171;;; More tests of a bug that showed up in c.l.l
172
173(deftest loop.11.29
174  (loop for i in '(4 8 9 A 13)
175        when (eq i 'a) return :good
176        while (< i 12) collect i)
177  :good)
178
179(deftest loop.11.30
180  (loop for i in '(4 8 9 A 13)
181        unless (numberp i) return :good
182        while (< i 12) collect i)
183  :good)
184
185(deftest loop.11.31
186  (loop for i in '(4 8 9 A 13)
187        when (eq i 'a) return :good
188        until (> i 12) collect i)
189  :good)
190
191(deftest loop.11.32
192  (loop for i in '(4 8 9 A 13)
193        unless (numberp i) return :good
194        until (> i 12) collect i)
195  :good)
196
197(deftest loop.11.33
198  (loop for i in '(4 8 9 A 13)
199        if (not (numberp i)) return :good end
200        while (< i 12) collect i)
201  :good)
202
203(deftest loop.11.34
204  (loop for i in '(4 8 9 A 13)
205        if (not (numberp i)) return :good end
206        until (> i 12) collect i)
207  :good)
208
209;;; Test that explicit calls to macroexpand in subforms
210;;; are done in the correct environment
211
212(deftest loop.11.35
213  (macrolet
214   ((%m (z) z))
215   (loop repeat (expand-in-current-env (%m 5)) collect 'x))
216  (x x x x x))
Note: See TracBrowser for help on using the repository browser.