source: trunk/source/tests/ansi-tests/multiple-value-bind.lsp @ 8991

Last change on this file since 8991 was 8991, checked in by gz, 11 years ago

Check in the gcl ansi test suite (original, in preparation for making local changes)

File size: 2.6 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Fri Oct 18 23:16:23 2002
4;;;; Contains: Tests for MULTIPLE-VALUE-BIND
5
6(in-package :cl-test)
7
8(deftest multiple-value-bind.1
9  (multiple-value-bind (x y z) (values 1 2 3)
10    (declare (type integer x))
11    (declare (type integer y))
12    (declare (type integer z))
13    (list z y x))
14  (3 2 1))
15
16(deftest multiple-value-bind.2
17  (multiple-value-bind (x y z) (values 1 2 3)
18    (let ((x 4))
19      (list x y z)))
20  (4 2 3))
21
22(deftest multiple-value-bind.3
23  (multiple-value-bind (x y z) (values 1 2 3 4 5 6)
24    (list x y z))
25  (1 2 3))
26
27(deftest multiple-value-bind.4
28  (multiple-value-bind (x y z) (values 1 2)
29    (list x y z))
30  (1 2 nil))
31
32(deftest multiple-value-bind.5
33  (multiple-value-bind () (values 1 2) (values 'a 'b 'c))
34  a b c)
35
36(deftest multiple-value-bind.6
37  (multiple-value-bind (x y z) (values)
38    (list x y z))
39  (nil nil nil))
40
41(deftest multiple-value-bind.7
42  (let ((z 0) x y)
43    (declare (special z))
44    (values
45     (flet ((%x () (symbol-value 'x))
46            (%y () (symbol-value 'y))
47            (%z () (symbol-value 'z)))
48       (multiple-value-bind (x y z) (values 1 2 3)
49         (declare (special x y))
50         (list (%x) (%y) (%z))))
51     x y z))
52  (1 2 0) nil nil 0)
53
54;;; No implicit tagbody
55(deftest multiple-value-bind.8
56  (block nil
57    (tagbody
58     (multiple-value-bind (x) nil
59       (go 10)
60       10
61       (return 'bad))
62     10
63     (return 'good)))
64  good)
65
66;;; Works with single values
67(deftest multiple-value-bind.9
68  (multiple-value-bind (x y z) :foo (list x y z))
69  (:foo nil nil))
70
71(deftest multiple-value-bind.10
72  (multiple-value-bind (x) :foo x)
73  :foo)
74
75(deftest multiple-value-bind.11
76  (multiple-value-bind () :foo)
77  nil)
78
79(deftest multiple-value-bind.12
80  (multiple-value-bind () (values))
81  nil)
82
83(deftest multiple-value-bind.13
84  (multiple-value-bind () (values 1 2 3 4 5))
85  nil)
86
87;;; Test that explicit calls to macroexpand in subforms
88;;; are done in the correct environment
89
90(deftest multiple-value-bind.14
91  (macrolet
92   ((%m (z) z))
93   (multiple-value-bind (x y z)
94                        (expand-in-current-env (%m (values 1 2 3)))
95                        (list x y z)))
96  (1 2 3))
97
98;;; Error cases
99
100(deftest multiple-value-bind.error.1
101  (signals-error (funcall (macro-function 'multiple-value-bind))
102                 program-error)
103  t)
104 
105(deftest multiple-value-bind.error.2
106  (signals-error (funcall (macro-function 'multiple-value-bind)
107                           '(multiple-value-bind nil nil))
108                 program-error)
109  t)
110
111(deftest multiple-value-bind.error.3
112  (signals-error (funcall (macro-function 'multiple-value-bind)
113                           '(multiple-value-bind nil nil)
114                           nil nil)
115                 program-error)
116  t)
Note: See TracBrowser for help on using the repository browser.