loop13.lsp 9.28 KB
Newer Older
1 2 3
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sun Nov 17 12:37:45 2002
4
;;;; Contains: Tests of DO, DOING, RETURN in LOOP.  Tests of NAMED loops
5 6 7 8 9 10 11 12 13 14 15 16 17

(in-package :cl-test)

(deftest loop.13.1
  (loop do (return 10))
  10)

(deftest loop.13.2
  (loop doing (return 10))
  10)

(deftest loop.13.3
  (loop for i from 0 below 100 by 7
sds's avatar
sds committed
18
        when (> i 50) return i)
19 20
  56)

21 22 23
(deftest loop.13.4
  (let ((x 0))
    (loop do
sds's avatar
sds committed
24 25
          (incf x)
          (when (= x 10) (return x))))
26 27 28 29 30 31 32 33 34 35 36 37 38 39
  10)

(deftest loop.13.5
  (loop return 'a)
  a)

(deftest loop.13.6
  (loop return (values)))

(deftest loop.13.7
  (loop return (values 1 2))
  1 2)

(deftest loop.13.8
pfdietz's avatar
pfdietz committed
40
  (let* ((limit (min 1000 (1- (min call-arguments-limit
sds's avatar
sds committed
41 42 43
                                   multiple-values-limit))))
         (vals (make-list limit :initial-element :a))
         (vals2 (multiple-value-list (eval `(loop return (values ,@vals))))))
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
    (equalt vals vals2))
  t)

(deftest loop.13.9
  (loop named foo return 'a)
  a)

(deftest loop.13.10
  (block nil
    (return (loop named foo return :good))
    :bad)
  :good)

(deftest loop.13.11
  (block nil
    (loop named foo do (return :good))
    :bad)
  :good)

(deftest loop.13.12
  (loop named foo with a = (return-from foo :good) return :bad)
  :good)

(deftest loop.13.13
  (loop named foo
        with b = 1
sds's avatar
sds committed
70
        and a = (return-from foo :good) return :bad)
71 72 73 74
  :good)

(deftest loop.13.14
  (loop named foo
sds's avatar
sds committed
75
        for a = (return-from foo :good) return :bad)
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
  :good)

(deftest loop.13.15
  (loop named foo for a in (return-from foo :good))
  :good)

(deftest loop.13.16
  (loop named foo for a from (return-from foo :good) return :bad)
  :good)

(deftest loop.13.17
  (loop named foo for a on (return-from foo :good) return :bad)
  :good)

(deftest loop.13.18
  (loop named foo for a across (return-from foo :good) return :bad)
  :good)

(deftest loop.13.19
  (loop named foo for a being the hash-keys of (return-from foo :good)
sds's avatar
sds committed
96
        return :bad)
97 98 99 100
  :good)

(deftest loop.13.20
  (loop named foo for a being the symbols of (return-from foo :good)
sds's avatar
sds committed
101
        return :bad)
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
  :good)

(deftest loop.13.21
  (loop named foo repeat (return-from foo :good) return :bad)
  :good)

(deftest loop.13.22
  (loop named foo for i from 0 to (return-from foo :good) return :bad)
  :good)

(deftest loop.13.23
  (loop named foo for i from 0 to 10 by (return-from foo :good) return :bad)
  :good)

(deftest loop.13.24
  (loop named foo for i from 10 downto (return-from foo :good) return :bad)
  :good)

(deftest loop.13.25
  (loop named foo for i from 10 above (return-from foo :good) return :bad)
  :good)

(deftest loop.13.26
  (loop named foo for i from 10 below (return-from foo :good) return :bad)
  :good)

(deftest loop.13.27
  (loop named foo for i in '(a b c) by (return-from foo :good) return :bad)
  :good)

(deftest loop.13.28
  (loop named foo for i on '(a b c) by (return-from foo :good) return :bad)
  :good)

(deftest loop.13.29
  (loop named foo for i = 1 then (return-from foo :good))
  :good)

(deftest loop.13.30
  (loop named foo for x in '(a b c) collect (return-from foo :good))
  :good)

(deftest loop.13.31
  (loop named foo for x in '(a b c) append (return-from foo :good))
  :good)

(deftest loop.13.32
  (loop named foo for x in '(a b c) nconc (return-from foo :good))
  :good)

(deftest loop.13.33
  (loop named foo for x in '(a b c) count (return-from foo :good))
  :good)

(deftest loop.13.34
  (loop named foo for x in '(a b c) sum (return-from foo :good))
  :good)

(deftest loop.13.35
  (loop named foo for x in '(a b c) maximize (return-from foo :good))
  :good)

(deftest loop.13.36
  (loop named foo for x in '(a b c) minimize (return-from foo :good))
  :good)

(deftest loop.13.37
  (loop named foo for x in '(a b c) thereis (return-from foo :good))
  :good)

(deftest loop.13.38
  (loop named foo for x in '(a b c) always (return-from foo :good))
  :good)

(deftest loop.13.39
  (loop named foo for x in '(a b c) never (return-from foo :good))
  :good)

(deftest loop.13.40
  (loop named foo for x in '(a b c) until (return-from foo :good))
  :good)

(deftest loop.13.41
  (loop named foo for x in '(a b c) while (return-from foo :good))
  :good)

(deftest loop.13.42
  (loop named foo for x in '(a b c) when (return-from foo :good) return :bad)
  :good)

(deftest loop.13.43
  (loop named foo for x in '(a b c) unless (return-from foo :good) return :bad)
  :good)

(deftest loop.13.44
  (loop named foo for x in '(a b c) if (return-from foo :good) return :bad)
  :good)

(deftest loop.13.45
  (loop named foo for x in '(a b c) return (return-from foo :good))
  :good)

(deftest loop.13.46
  (loop named foo initially (return-from foo :good) return :bad)
  :good)

(deftest loop.13.47
  (loop named foo do (loop-finish) finally (return-from foo :good))
  :good)


(deftest loop.13.52
  (block nil
    (loop named foo with a = (return :good) return :bad)
    :bad)
  :good)

(deftest loop.13.53
  (block nil
    (loop named foo
sds's avatar
sds committed
222 223
          with b = 1
          and a = (return :good) return :bad)
224 225 226 227 228 229
    :bad)
  :good)

(deftest loop.13.54
  (block nil
    (loop named foo
sds's avatar
sds committed
230
          for a = (return :good) return :bad)
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
    :bad)
  :good)

(deftest loop.13.55
  (block nil
    (loop named foo for a in (return :good))
    :bad)
  :good)

(deftest loop.13.56
  (block nil
    (loop named foo for a from (return :good) return :bad)
    :bad)
  :good)

(deftest loop.13.57
  (block nil
    (loop named foo for a on (return :good) return :bad)
    :bad)
  :good)

(deftest loop.13.58
  (block nil
    (loop named foo for a across (return :good) return :bad)
    :bad)
  :good)

(deftest loop.13.59
  (block nil
    (loop named foo for a being the hash-keys of (return :good)
sds's avatar
sds committed
261
          return :bad)
262 263 264 265 266 267
    :bad)
  :good)

(deftest loop.13.60
  (block nil
    (loop named foo for a being the symbols of (return :good)
sds's avatar
sds committed
268
          return :bad)
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
    :bad)
  :good)

(deftest loop.13.61
  (block nil
    (loop named foo repeat (return :good) return :bad)
    :bad)
  :good)

(deftest loop.13.62
  (block nil
    (loop named foo for i from 0 to (return :good) return :bad)
    :bad)
  :good)

(deftest loop.13.63
  (block nil
    (loop named foo for i from 0 to 10 by (return :good) return :bad)
    :bad)
  :good)

(deftest loop.13.64
  (block nil
    (loop named foo for i from 10 downto (return :good) return :bad)
    :bad)
  :good)

(deftest loop.13.65
  (block nil
    (loop named foo for i from 10 above (return :good) return :bad)
    :bad)
  :good)

(deftest loop.13.66
  (block nil
    (loop named foo for i from 10 below (return :good) return :bad)
    :bad)
  :good)

(deftest loop.13.67
  (block nil
    (loop named foo for i in '(a b c) by (return :good) return :bad)
    :bad)
  :good)

(deftest loop.13.68
  (block nil
    (loop named foo for i on '(a b c) by (return :good) return :bad)
    :bad)
  :good)

(deftest loop.13.69
  (block nil
    (loop named foo for i = 1 then (return :good))
    :bad)
  :good)

(deftest loop.13.70
  (block nil
    (loop named foo for x in '(a b c) collect (return :good))
    :bad)
  :good)

(deftest loop.13.71
  (block nil
    (loop named foo for x in '(a b c) append (return :good))
    :bad)
  :good)

(deftest loop.13.72
  (block nil
    (loop named foo for x in '(a b c) nconc (return :good))
    :bad)
  :good)

(deftest loop.13.73
  (block nil
    (loop named foo for x in '(a b c) count (return :good))
    :bad)
  :good)

(deftest loop.13.74
  (block nil
    (loop named foo for x in '(a b c) sum (return :good))
    :bad)
  :good)

(deftest loop.13.75
  (block nil
    (loop named foo for x in '(a b c) maximize (return :good))
    :bad)
  :good)

(deftest loop.13.76
  (block nil
    (loop named foo for x in '(a b c) minimize (return :good))
    :bad)
  :good)

(deftest loop.13.77
  (block nil
    (loop named foo for x in '(a b c) thereis (return :good))
    :bad)
  :good)

(deftest loop.13.78
  (block nil
    (loop named foo for x in '(a b c) always (return :good))
    :bad)
  :good)

(deftest loop.13.79
  (block nil
    (loop named foo for x in '(a b c) never (return :good))
    :bad)
  :good)

(deftest loop.13.80
  (block nil
    (loop named foo for x in '(a b c) until (return :good))
    :bad)
  :good)

(deftest loop.13.81
  (block nil
    (loop named foo for x in '(a b c) while (return :good))
    :bad)
  :good)

(deftest loop.13.82
  (block nil
    (loop named foo for x in '(a b c) when (return :good) return :bad)
    :bad)
  :good)

(deftest loop.13.83
  (block nil
    (loop named foo for x in '(a b c) unless (return :good) return :bad)
    :bad)
  :good)

(deftest loop.13.84
  (block nil
    (loop named foo for x in '(a b c) if (return :good) return :bad)
    :bad)
  :good)

(deftest loop.13.85
  (block nil
    (loop named foo for x in '(a b c) return (return :good))
    :bad)
  :good)

(deftest loop.13.86
  (block nil
    (loop named foo initially (return :good) return :bad)
    :bad)
  :good)

(deftest loop.13.87
  (block nil
    (loop named foo do (loop-finish) finally (return :good))
    :bad)
  :good)
433

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

437 438 439 440 441 442 443 444 445 446
(deftest loop.13.88
  (macrolet
   ((%m (z) z))
   (loop do (expand-in-current-env (%m (return 10)))))
  10)

(deftest loop.13.89
  (macrolet
   ((%m (z) z))
   (loop for i from 0 below 100 by 7
sds's avatar
sds committed
447
         when (> i 50) return (expand-in-current-env (%m i))))
448 449 450 451 452 453 454
  56)

(deftest loop.13.90
  (macrolet
   ((%m (z) z))
   (loop return (expand-in-current-env (%m 'a))))
  a)