From c8a1700aaa11a25469f822f13ad36c37cf854d05 Mon Sep 17 00:00:00 2001
From: pfdietz <pfdietz@localhost>
Date: Mon, 28 Oct 2002 04:50:59 +0000
Subject: [PATCH] Added more loop tests, for LOOP-AS-ON-LIST and
 LOOP-FOR-AS-EQUAL iteration controls.

---
 ansi-tests/gclload2.lsp |   2 +
 ansi-tests/loop1.lsp    |   4 --
 ansi-tests/loop2.lsp    |  46 ++++++++++++++
 ansi-tests/loop3.lsp    | 136 ++++++++++++++++++++++++++++++++++++++++
 ansi-tests/loop4.lsp    |  21 +++++++
 5 files changed, 205 insertions(+), 4 deletions(-)
 create mode 100644 ansi-tests/loop3.lsp
 create mode 100644 ansi-tests/loop4.lsp

diff --git a/ansi-tests/gclload2.lsp b/ansi-tests/gclload2.lsp
index f06695b1..7f66edca 100644
--- a/ansi-tests/gclload2.lsp
+++ b/ansi-tests/gclload2.lsp
@@ -76,6 +76,8 @@
 (load "loop.lsp")
 (load "loop1.lsp")
 (load "loop2.lsp")
+(load "loop3.lsp")
+(load "loop4.lsp")
 
 ;;; Tests of conses
 
diff --git a/ansi-tests/loop1.lsp b/ansi-tests/loop1.lsp
index 7f01c5f0..37f9c75b 100644
--- a/ansi-tests/loop1.lsp
+++ b/ansi-tests/loop1.lsp
@@ -177,10 +177,6 @@
   (loop for x from 1 upto 5 collect x)
   (1 2 3 4 5))
 
-(deftest loop.1.33
-  (loop for x from 1 upto 5 collect x)
-  (1 2 3 4 5))
-
 (deftest loop.1.34
   (loop for x from 1 to 4.0 collect x)
   (1 2 3 4))
diff --git a/ansi-tests/loop2.lsp b/ansi-tests/loop2.lsp
index 8f634414..336679fe 100644
--- a/ansi-tests/loop2.lsp
+++ b/ansi-tests/loop2.lsp
@@ -87,7 +87,53 @@
   (loop for nil in nil do (return t))
   nil)
 
+(deftest loop.2.17
+  (let ((x '(a b c)))
+    (values
+     x
+     (loop for x in '(d e f) collect (list x))
+     x))
+  (a b c)
+  ((d) (e) (f))
+  (a b c))
+
+(deftest loop.2.18
+  (loop for x of-type (integer 0 10) in '(2 4 6 7) sum x)
+  19)
+  
+;;; Tests of the 'AS' form
+
+(deftest loop.2.19
+  (loop as x in '(1 2 3) sum x)
+  6)
 
+(deftest loop.2.20
+  (loop as x in '(a b c)
+	as y in '(1 2 3)
+	collect (list x y))
+  ((a 1) (b 2) (c 3)))
 
+(deftest loop.2.21
+  (loop as x in '(a b c)
+	for y in '(1 2 3)
+	collect (list x y))
+  ((a 1) (b 2) (c 3)))
+
+(deftest loop.2.22
+  (loop for x in '(a b c)
+	as y in '(1 2 3)
+	collect (list x y))
+  ((a 1) (b 2) (c 3)))
+
+(deftest loop.2.23
+  (let (a b (i 0))
+    (values
+     (loop for e in (progn (setf a (incf i))
+			   '(a b c d e f g))
+	   by (progn (setf b (incf i)) #'cddr)
+	   collect e)
+     a b i))
+  (a c e g)
+  1 2 2)
 
 
diff --git a/ansi-tests/loop3.lsp b/ansi-tests/loop3.lsp
new file mode 100644
index 00000000..9fe3051a
--- /dev/null
+++ b/ansi-tests/loop3.lsp
@@ -0,0 +1,136 @@
+;-*- Mode:     Lisp -*-
+;;;; Author:   Paul Dietz
+;;;; Created:  Sun Oct 27 08:36:36 2002
+;;;; Contains: Tests of FOR-ON-AS-LIST iteration control in LOOP
+
+(in-package :cl-test)
+
+(deftest loop.3.1
+  (loop for x on '(1 2 3) sum (car x))
+  6)
+
+(deftest loop.3.2
+  (loop for x on '(1 2 3 4)
+	do (when (evenp (car x)) (return x)))
+  (2 3 4))
+
+
+(deftest loop.3.3
+  (loop for x on '(a b c . d) collect (car x))
+  (a b c))
+
+(deftest loop.3.4
+  (let ((x nil))
+    (loop for e on '(a b c d) do (push (car e) x))
+    x)
+  (d c b a))
+
+(deftest loop.3.5
+  (loop for e on '(a b c d e f) by #'cddr
+	collect (car e))
+  (a c e))
+
+(deftest loop.3.6
+  (loop for e on '(a b c d e f g) by #'cddr
+	collect (car e))
+  (a c e g))
+
+(deftest loop.3.7
+  (loop for e on '(a b c d e f)
+	by #'(lambda (l) (and (cdr l) (cons (car l) (cddr l))))
+	collect (car e))
+  (a a a a a a))
+
+(deftest loop.3.8
+  (loop for ((x . y)) on '((a . b) (c . d) (e . f))
+	collect (list x y))
+  ((a b) (c d) (e f)))
+
+(deftest loop.3.9
+  (loop for ((x nil y)) on '((a b c) (d e f) (g h i))
+	collect (list x y))
+  ((a c) (d f) (g i)))
+
+(deftest loop.3.10
+  (loop for ((x y)) of-type (fixnum) on '((1 2) (3 4) (5 6))
+	collect (+ x y))
+  (3 7 11))
+
+(deftest loop.3.11
+  (loop for ((x y)) of-type (fixnum) on '((1 2) (3 4) (5 6))
+	collect (+ x y))
+  (3 7 11))
+
+(deftest loop.3.12
+  (loop for ((x y)) of-type ((fixnum fixnum)) on '((1 2) (3 4) (5 6))
+	collect (+ x y))
+  (3 7 11))
+
+(deftest loop.3.13
+  (loop for ((x . y)) of-type ((fixnum . fixnum)) on '((1 . 2) (3 . 4) (5 . 6))
+	collect (+ x y))
+  (3 7 11))
+
+(deftest loop.3.14
+  (classify-error
+   (loop for x on '(a b c)
+	 for x on '(d e f) collect x))
+  programm-error)
+
+(deftest loop.3.15
+  (classify-error
+   (loop for (x . x) on '((a b) (c d)) collect x))
+  programm-error)
+
+(deftest loop.3.16
+  (loop for nil on nil do (return t))
+  nil)
+
+(deftest loop.3.17
+  (let ((x '(a b c)))
+    (values
+     x
+     (loop for x on '(d e f) collect x)
+     x))
+  (a b c)
+  ((d e f) (e f) (f))
+  (a b c))
+
+(deftest loop.3.18
+  (loop for (x) of-type ((integer 0 10)) on '(2 4 6 7) sum x)
+  19)
+  
+;;; Tests of the 'AS' form
+
+(deftest loop.3.19
+  (loop as x on '(1 2 3) sum (car x))
+  6)
+
+(deftest loop.3.20
+  (loop as x on '(a b c)
+	as y on '(1 2 3)
+	collect (list (car x) (car y)))
+  ((a 1) (b 2) (c 3)))
+
+(deftest loop.3.21
+  (loop as x on '(a b c)
+	for y on '(1 2 3)
+	collect (list (car x) (car y)))
+  ((a 1) (b 2) (c 3)))
+
+(deftest loop.3.22
+  (loop for x on '(a b c)
+	as y on '(1 2 3)
+	collect (list (car x) (car y)))
+  ((a 1) (b 2) (c 3)))
+
+(deftest loop.3.23
+  (let (a b (i 0))
+    (values
+     (loop for e on (progn (setf a (incf i))
+			   '(a b c d e f g))
+	   by (progn (setf b (incf i)) #'cddr)
+	   collect (car e))
+     a b i))
+  (a c e g)
+  1 2 2)
diff --git a/ansi-tests/loop4.lsp b/ansi-tests/loop4.lsp
new file mode 100644
index 00000000..e29da999
--- /dev/null
+++ b/ansi-tests/loop4.lsp
@@ -0,0 +1,21 @@
+;-*- 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))
+
+
-- 
GitLab