File: loop7.lsp

package info (click to toggle)
cl-ansi-tests 20071218-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 7,000 kB
  • ctags: 22,025
  • sloc: lisp: 134,798; makefile: 144
file content (243 lines) | stat: -rw-r--r-- 6,359 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Mon Nov 11 21:40:05 2002
;;;; Contains: Tests for FOR-AS-PACKAGE clause for LOOP

(in-package :cl-test)

(defpackage "LOOP.CL-TEST.1"
  (:use)
  (:intern "FOO" "BAR" "BAZ")
  (:export "A" "B" "C"))

(defpackage "LOOP.CL-TEST.2"
  (:use "LOOP.CL-TEST.1")
  (:intern "X" "Y" "Z"))

(deftest loop.7.1
  (sort (mapcar #'symbol-name
		(loop for x being the symbols of "LOOP.CL-TEST.1" collect x))
	#'string<)
  ("A" "B" "BAR" "BAZ" "C" "FOO"))

(deftest loop.7.2
  (sort (mapcar #'symbol-name
		(loop for x being each symbol of "LOOP.CL-TEST.1" collect x))
	#'string<)
  ("A" "B" "BAR" "BAZ" "C" "FOO"))

(deftest loop.7.3
  (sort (mapcar #'symbol-name
		(loop for x being the symbol of "LOOP.CL-TEST.1" collect x))
	#'string<)
  ("A" "B" "BAR" "BAZ" "C" "FOO"))

(deftest loop.7.4
  (sort (mapcar #'symbol-name
		(loop for x being each symbols of "LOOP.CL-TEST.1" collect x))
	#'string<)
  ("A" "B" "BAR" "BAZ" "C" "FOO"))

(deftest loop.7.5
  (sort (mapcar #'symbol-name
		(loop for x being the symbols in "LOOP.CL-TEST.1" collect x))
	#'string<)
  ("A" "B" "BAR" "BAZ" "C" "FOO"))

(deftest loop.7.6
  (sort (mapcar #'symbol-name
		(loop for x being each symbol in "LOOP.CL-TEST.1" collect x))
	#'string<)
  ("A" "B" "BAR" "BAZ" "C" "FOO"))

(deftest loop.7.7
  (sort (mapcar #'symbol-name
		(loop for x being the symbol in "LOOP.CL-TEST.1" collect x))
	#'string<)
  ("A" "B" "BAR" "BAZ" "C" "FOO"))

(deftest loop.7.8
  (sort (mapcar #'symbol-name
		(loop for x being each symbols in "LOOP.CL-TEST.1" collect x))
	#'string<)
  ("A" "B" "BAR" "BAZ" "C" "FOO"))

(deftest loop.7.9
  (sort (mapcar #'symbol-name
		(loop for x being the external-symbols of "LOOP.CL-TEST.1" collect x))
	#'string<)
  ("A" "B" "C"))

(deftest loop.7.10
  (sort (mapcar #'symbol-name
		(loop for x being each external-symbol in "LOOP.CL-TEST.1" collect x))
	#'string<)
  ("A" "B" "C"))

(deftest loop.7.11
  (sort (mapcar #'symbol-name
		(loop for x being each external-symbol in (find-package "LOOP.CL-TEST.1") collect x))
	#'string<)
  ("A" "B" "C"))

(deftest loop.7.12
  (sort (mapcar #'symbol-name
		(loop for x being each external-symbol in :LOOP.CL-TEST.1 collect x))
	#'string<)
  ("A" "B" "C"))

(deftest loop.7.13
  (sort (mapcar #'symbol-name
		(loop for x being the symbols of "LOOP.CL-TEST.2" collect x))
	#'string<)
  ("A" "B" "C" "X" "Y" "Z"))

(deftest loop.7.14
  (sort (mapcar #'symbol-name
		(loop for x being the present-symbols of "LOOP.CL-TEST.2" collect x))
	#'string<)
  ("X" "Y" "Z"))

;;; According to the ANSI CL spec, "If the package for the iteration is not supplied,
;;; the current package is used."  Thse next tests are of the cases that the package
;;; is not supplied in the loop form.

(deftest loop.7.15
  (let ((*package* (find-package "LOOP.CL-TEST.1")))
    (sort (mapcar #'symbol-name (loop for x being each symbol collect x))
	  #'string<))
  ("A" "B" "BAR" "BAZ" "C" "FOO"))

(deftest loop.7.16
  (let ((*package* (find-package "LOOP.CL-TEST.1")))
    (sort (mapcar #'symbol-name (loop for x being each external-symbol collect x))
	  #'string<))
  ("A" "B" "C"))

(deftest loop.7.17
  (let ((*package* (find-package "LOOP.CL-TEST.2")))
    (sort (mapcar #'symbol-name (loop for x being each present-symbol collect x))
	  #'string<))
  ("X" "Y" "Z"))

;;; Cases where the package doesn't exist.  According to the standard,
;;; (section 6.1.2.1.7), this should cause a pacakge-error.

(deftest loop.7.18
  (let ()
    (ignore-errors (delete-package "LOOP.MISSING.PACKAGE"))
    (signals-error
     (loop for x being each symbol of "LOOP.MISSING.PACKAGE" collect x)
     package-error))
  t)

(deftest loop.7.19
  (let ()
    (ignore-errors (delete-package "LOOP.MISSING.PACKAGE"))
    (signals-error
     (loop for x being each present-symbol of "LOOP.MISSING.PACKAGE"
	   collect x)
     package-error))
  t)

(deftest loop.7.20
  (let ()
    (ignore-errors (delete-package "LOOP.MISSING.PACKAGE"))
    (signals-error
     (loop for x being each external-symbol of "LOOP.MISSING.PACKAGE"
	   collect x)
     package-error))
  t)

;;; NIL d-var-specs

(deftest loop.7.21
  (loop for nil being the symbols of "LOOP.CL-TEST.1" count t)
  6)
    
(deftest loop.7.22
  (loop for nil being the external-symbols of "LOOP.CL-TEST.1" count t)
  3)
    
(deftest loop.7.23
  (loop for nil being the present-symbols of "LOOP.CL-TEST.2" count t)
  3)

;;; Type specs

(deftest loop.7.24
  (loop for x t being the symbols of "LOOP.CL-TEST.1" count x)
  6)
    
(deftest loop.7.25
  (loop for x t being the external-symbols of "LOOP.CL-TEST.1" count x)
  3)
    
(deftest loop.7.26
  (loop for x t being the present-symbols of "LOOP.CL-TEST.2" count x)
  3)

(deftest loop.7.27
  (loop for x of-type symbol being the symbols of "LOOP.CL-TEST.1" count x)
  6)
    
(deftest loop.7.28
  (loop for x of-type symbol being the external-symbols of "LOOP.CL-TEST.1" count x)
  3)
    
(deftest loop.7.29
  (loop for x of-type symbol being the present-symbols of "LOOP.CL-TEST.2" count x)
  3)

;;; Tests of the 'as' form

(deftest loop.7.30
  (sort (mapcar #'symbol-name
		(loop as x being the symbols of "LOOP.CL-TEST.1" collect x))
	#'string<)
  ("A" "B" "BAR" "BAZ" "C" "FOO"))

(deftest loop.7.31
  (sort (mapcar #'symbol-name
		(loop as x being each symbol of "LOOP.CL-TEST.1" collect x))
	#'string<)
  ("A" "B" "BAR" "BAZ" "C" "FOO"))

(deftest loop.7.32
  (sort (mapcar #'symbol-name
		(loop as x being the symbol of "LOOP.CL-TEST.1" collect x))
	#'string<)
  ("A" "B" "BAR" "BAZ" "C" "FOO"))

;;; Test that explicit calls to macroexpand in subforms
;;; are done in the correct environment

(deftest loop.7.33
  (macrolet
   ((%m (z) z))
   (sort (mapcar #'symbol-name
		 (loop for x being the symbols of
		       (expand-in-current-env (%m "LOOP.CL-TEST.1"))
		       collect x))
	 #'string<))
  ("A" "B" "BAR" "BAZ" "C" "FOO"))

(deftest loop.7.34
  (macrolet
   ((%m (z) z))
   (sort (mapcar #'symbol-name
		 (loop for x being the external-symbols of
		       (expand-in-current-env (%m "LOOP.CL-TEST.1"))
		       collect x))
	 #'string<))
  ("A" "B" "C"))

(deftest loop.7.35
  (macrolet
   ((%m (z) z))
   (sort (mapcar #'symbol-name
		 (loop for x being the present-symbols of
		       (expand-in-current-env (%m "LOOP.CL-TEST.2"))
		       collect x))
	 #'string<))
  ("X" "Y" "Z"))