Commit 60cb6583 authored by pfdietz's avatar pfdietz

Added tests for error handling in LOOP syntax, FOR-AS-IN-LIST iteration...

Added tests for error handling in LOOP syntax, FOR-AS-IN-LIST iteration control, and destructuring in LOOPs.  Also, checks for the final values of loop arithmetic index variables.
parent 026914b0
......@@ -75,6 +75,7 @@
(load "iteration.lsp")
(load "loop.lsp")
(load "loop1.lsp")
(load "loop2.lsp")
;;; Tests of conses
......
......@@ -172,3 +172,58 @@
a b c i))
(0 2 4 6 8)
3 2 1 3)
(deftest loop.1.33
(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))
(deftest loop.1.35
(loop for x below 5 collect x)
(0 1 2 3 4))
(deftest loop.1.36
(loop for x below 20 by 3 collect x)
(0 3 6 9 12 15 18))
(deftest loop.1.37
(loop for x by 3 below 20 collect x)
(0 3 6 9 12 15 18))
(deftest loop.1.38
(loop for x of-type fixnum from 1 to 5 collect x)
(1 2 3 4 5))
;;; The following provides an example where an incorrect
;;; implementation will assign X an out-of-range value
;;; at the end.
(deftest loop.1.39
(loop for x of-type (integer 1 5) from 1 to 5 collect x)
(1 2 3 4 5))
;;; Test that the index variable achieves the inclusive
;;; upper bound, but does not exceed it.
(deftest loop.1.40
(loop for x from 1 to 5 do nil finally (return x))
5)
;;; Test that the index variable acheives the exclusive
;;; upper bound, but does not exceed it.
(deftest loop.1.41
(loop for x from 1 below 5 do nil finally (return x))
4)
(deftest loop.1.42
(loop for x from 10 downto 0 do nil finally (return x))
0)
(deftest loop.1.43
(loop for x from 10 above 0 do nil finally (return x))
1)
;-*- Mode: Lisp -*-
;;;; Author: Paul Dietz
;;;; Created: Sat Oct 26 13:45:45 2002
;;;; Contains: Tests of the FOR-AS-IN-LIST loop iteration control form,
;;;; and of destructuring in loop forms
(in-package :cl-test)
(deftest loop.2.1
(loop for x in '(1 2 3) sum x)
6)
(deftest loop.2.2
(loop for x in '(1 2 3 4)
do (when (evenp x) (return x)))
2)
(deftest loop.2.3
(classify-error (loop for x in '(a . b) collect x))
type-error)
(deftest loop.2.4
(let ((x nil))
(loop for e in '(a b c d) do (push e x))
x)
(d c b a))
(deftest loop.2.5
(loop for e in '(a b c d e f) by #'cddr
collect e)
(a c e))
(deftest loop.2.6
(loop for e in '(a b c d e f g) by #'cddr
collect e)
(a c e g))
(deftest loop.2.7
(loop for e in '(a b c d e f)
by #'(lambda (l) (and (cdr l) (cons (car l) (cddr l))))
collect e)
(a a a a a a))
(deftest loop.2.8
(loop for (x . y) in '((a . b) (c . d) (e . f))
collect (list x y))
((a b) (c d) (e f)))
(deftest loop.2.9
(loop for (x nil y) in '((a b c) (d e f) (g h i))
collect (list x y))
((a c) (d f) (g i)))
(deftest loop.2.10
(loop for (x y) of-type fixnum in '((1 2) (3 4) (5 6))
collect (+ x y))
(3 7 11))
(deftest loop.2.10
(loop for (x y) of-type fixnum in '((1 2) (3 4) (5 6))
collect (+ x y))
(3 7 11))
(deftest loop.2.11
(loop for (x y) of-type (fixnum fixnum) in '((1 2) (3 4) (5 6))
collect (+ x y))
(3 7 11))
(deftest loop.2.11
(loop for (x . y) of-type (fixnum . fixnum) in '((1 . 2) (3 . 4) (5 . 6))
collect (+ x y))
(3 7 11))
(deftest loop.2.12
(classify-error
(loop for x in '(a b c)
for x in '(d e f) collect x))
programm-error)
(deftest loop.2.13
(classify-error
(loop for (x . x) in '((a b) (c d)) collect x))
programm-error)
(deftest loop.2.14
(loop for nil in nil do (return t))
nil)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment