loop4.lsp 2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sun Oct 27 22:46:39 2002
;;;; Contains: Tests for LOOP FOR-AS-EQUAL-THEN

(in-package :cl-test)

(deftest loop.4.1
  (loop
   for x = 1 then (1+ x)
   until (> x 5)
   collect x)
  (1 2 3 4 5))

(deftest loop.4.2
  (loop
   for i from 1 to 10
   for j = (1+ i) collect j)
  (2 3 4 5 6 7 8 9 10 11))

21 22 23 24 25 26 27 28
(deftest loop.4.3
  (loop
   for i from 1 to 10
   for j of-type integer = (1+ i) collect j)
  (2 3 4 5 6 7 8 9 10 11))

(deftest loop.4.4
  (loop for e on '(a b c d e)
sds's avatar
sds committed
29 30
        for (x . y) = e
        collect x)
31 32 33 34
  (a b c d e))

(deftest loop.4.5
  (loop for (x . y) = '(a b c d e) then y
sds's avatar
sds committed
35 36
        while x
        collect x)
37 38 39 40 41
  (a b c d e))

;;; Error cases

(deftest loop.4.6
42
  (signals-error
43
   (loop for (x . x) = '(nil nil nil)
sds's avatar
sds committed
44
         until x count t)
45 46
   program-error)
  t)
47 48

(deftest loop.4.7
49
  (signals-error
50
   (macroexpand '(loop for (x . x) = '(nil nil nil)
sds's avatar
sds committed
51
                       until x count t))
52 53
   program-error)
  t)
54

55
(deftest loop.4.8
56
  (signals-error
57
   (macroexpand '(loop for x = '(nil nil nil)
sds's avatar
sds committed
58
                       for x = 1 count x until t))
59 60
   program-error)
  t)
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

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

(deftest loop.4.9
  (macrolet
   ((%m (z) z))
   (loop
    for x = (expand-in-current-env (%m 1)) then (1+ x)
    until (> x 5)
    collect x))
  (1 2 3 4 5))

(deftest loop.4.10
  (macrolet
   ((%m (z) z))
   (loop
    for x = 1 then (expand-in-current-env (%m (1+ x)))
    until (> x 5)
    collect x))
  (1 2 3 4 5))

(deftest loop.4.11
  (macrolet
   ((%m (z) z))
   (loop
    for x = 1 then (1+ x)
    until (expand-in-current-env (%m (> x 5)))
    collect x))
  (1 2 3 4 5))

(deftest loop.4.12
  (macrolet
   ((%m (z) z))
   (loop
    for x = 1 then (1+ x)
    while (expand-in-current-env (%m (<= x 5)))
    collect x))
  (1 2 3 4 5))

(deftest loop.4.13
  (macrolet
   ((%m (z) z))
   (loop
    for x = 1 then (1+ x)
    until (> x 5)
    collect (expand-in-current-env (%m x))))
  (1 2 3 4 5))