source: trunk/source/tests/ansi-tests/loop8.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: 3.0 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Tue Nov 12 06:30:14 2002
4;;;; Contains: Tests of LOOP local variable initialization
5
6(in-package :cl-test)
7
8(deftest loop.8.1
9  (loop with x = 1 do (return x))
10  1)
11
12(deftest loop.8.2
13  (loop with x = 1
14        with y = (1+ x) do (return (list x y)))
15  (1 2))
16
17(deftest loop.8.3
18  (let ((y 2))
19    (loop with x = y
20          with y = (1+ x) do (return (list x y))))
21  (2 3))
22
23(deftest loop.8.4
24  (let (a b)
25    (loop with a = 1
26          and b = (list a)
27          and c = (list b)
28          return (list a b c)))
29  (1 (nil) (nil)))
30
31
32;;; type specs
33
34(deftest loop.8.5
35  (loop with a t = 1 return a)
36  1)
37
38(deftest loop.8.6
39  (loop with a fixnum = 2 return a)
40  2)
41
42(deftest loop.8.7
43  (loop with a float = 3.0 return a)
44  3.0)
45
46(deftest loop.8.8
47  (loop with a of-type string = "abc" return a)
48  "abc")
49
50(deftest loop.8.9
51  (loop with (a b) = '(1 2) return (list b a))
52  (2 1))
53
54(deftest loop.8.10
55  (loop with (a b) of-type (fixnum fixnum) = '(3 4) return (+ a b))
56  7)
57
58(deftest loop.8.11
59  (loop with a of-type fixnum return a)
60  0)
61
62(deftest loop.8.12
63  (loop with a of-type float return a)
64  0.0)
65
66(deftest loop.8.13
67  (loop with a of-type t return a)
68  nil)
69
70(deftest loop.8.14
71  (loop with a t return a)
72  nil)
73
74(deftest loop.8.15
75  (loop with a t and b t return (list a b))
76  (nil nil))
77
78(deftest loop.8.16
79  (loop with (a b c) of-type (fixnum float t) return (list a b c))
80  (0 0.0 nil))
81
82(deftest loop.8.17
83  (loop with nil = nil return nil)
84  nil)
85
86;;; The NIL block of a loop encloses the entire loop.
87
88(deftest loop.8.18
89  (loop with nil = (return t) return nil)
90  t)
91
92(deftest loop.8.19
93  (loop with (nil a) = '(1 2) return a)
94  2)
95
96(deftest loop.8.20
97  (loop with (a nil) = '(1 2) return a)
98  1)
99
100(deftest loop.8.21
101  (loop with b = 3
102        and (a nil) = '(1 2) return (list a b))
103  (1 3))
104
105(deftest loop.8.22
106  (loop with b = 3
107        and (nil a) = '(1 2) return (list a b))
108  (2 3))
109
110;;; The NIL block of a loop encloses the entire loop.
111
112(deftest loop.8.23
113  (loop
114   with a = 1
115   and  b = (return 2)
116   return 3)
117  2)
118
119;;; Test that explicit calls to macroexpand in subforms
120;;; are done in the correct environment
121
122(deftest loop.8.24
123  (macrolet
124   ((%m (z) z))
125   (loop with x = (expand-in-current-env (%m 1)) do (return x)))
126  1)
127
128;;; Error cases
129
130;;; The spec says (in section 6.1.1.7) that:
131;;; "An error of type program-error is signaled (at macro expansion time)
132;;;  if the same variable is bound twice in any variable-binding clause
133;;;  of a single loop expression. Such variables include local variables,
134;;;  iteration control variables, and variables found by destructuring."
135;;;
136;;; This is somewhat ambiguous.  Test loop.8.error.1 binds A twice in
137;;; the same clause, but loop.8.error.2 binds A in two different clauses.
138;;; I am interpreting the spec as ruling out the latter as well.
139
140(deftest loop.8.error.1
141  (signals-error
142   (loop with a = 1
143         and  a = 2 return a)
144   program-error)
145  t)
146
147(deftest loop.8.error.2
148  (signals-error
149   (loop with a = 1
150         with a = 2 return a)
151   program-error)
152  t)
Note: See TracBrowser for help on using the repository browser.