source: trunk/source/tests/ansi-tests/loop17.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: 2.4 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Thu Nov 21 09:48:38 2002
4;;;; Contains: Miscellaneous loop tests
5
6(in-package :cl-test)
7
8;;; Initially and finally take multiple forms,
9;;; and execute them in the right order
10(deftest loop.17.1
11  (loop
12   with x = 0
13   initially (incf x 1) (incf x (+ x x))
14   initially (incf x (+ x x x))
15   until t
16   finally (incf x 100) (incf x (+ x x))
17   finally (return x))
18  336)
19
20(deftest loop.17.2
21  (loop
22   with x = 0
23   until t
24   initially (incf x 1) (incf x (+ x x))
25   finally (incf x 100) (incf x (+ x x))
26   initially (incf x (+ x x x))
27   finally (return x))
28  336)
29
30(deftest loop.17.3
31  (let ((x 0))
32    (loop
33     with y = (incf x 1)
34     initially (incf x 2)
35     until t
36     finally (return (values x y))))
37  3 1)
38
39(deftest loop.17.4
40  (loop
41   doing (return 'a)
42   finally (return 'b))
43  a)
44
45(deftest loop.17.5
46  (loop
47   return 'a
48   finally (return 'b))
49  a)
50
51(deftest loop.17.6
52  (let ((x 0))
53    (tagbody
54     (loop
55      do (go done)
56      finally (incf x))
57     done)
58    x)
59  0)
60
61(deftest loop.17.7
62  (let ((x 0))
63    (catch 'done
64      (loop
65       do (throw 'done nil)
66       finally (incf x)))
67    x)
68  0)
69
70(deftest loop.17.8
71  (loop
72   for x in '(1 2 3)
73   collect x
74   finally (return 'good))
75  good)
76
77(deftest loop.17.9
78  (loop
79   for x in '(1 2 3)
80   append (list x)
81   finally (return 'good))
82  good)
83
84(deftest loop.17.10
85  (loop
86   for x in '(1 2 3)
87   nconc (list x)
88   finally (return 'good))
89  good)
90
91(deftest loop.17.11
92  (loop
93   for x in '(1 2 3)
94   count (> x 1)
95   finally (return 'good))
96  good)
97
98(deftest loop.17.12
99  (loop
100   for x in '(1 2 3)
101   sum x
102   finally (return 'good))
103  good)
104
105(deftest loop.17.13
106  (loop
107   for x in '(1 2 3)
108   maximize x
109   finally (return 'good))
110  good)
111
112(deftest loop.17.14
113  (loop
114   for x in '(1 2 3)
115   minimize x
116   finally (return 'good))
117  good)
118
119;;; iteration clause grouping
120
121(deftest loop.17.20
122  (loop
123   for i from 1 to 5
124   for j = 0 then (+ j i)
125   collect j)
126  (0 2 5 9 14))
127
128(deftest loop.17.21
129  (loop
130   for i from 1 to 5
131   and j = 0 then (+ j i)
132   collect j)
133  (0 1 3 6 10))
134
135;;; Test that explicit calls to macroexpand in subforms
136;;; are done in the correct environment
137
138(deftest loop.17.22
139  (macrolet
140   ((%m (z) z))
141   (loop with x = 0
142         initially (expand-in-current-env (%m (incf x)))
143         until t
144         finally (expand-in-current-env (%m (return x)))))
145  1)
Note: See TracBrowser for help on using the repository browser.