and.lsp 1.43 KB
Newer Older
pfdietz's avatar
pfdietz committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Fri Oct 18 07:23:48 2002
;;;; Contains: Tests for AND

(in-package :cl-test)

(deftest and.1
  (and)
  t)

(deftest and.2
  (and nil)
  nil)

(deftest and.3
  (and 'a)
  a)

(deftest and.4
  (and (values 'a 'b 'c))
  a b c)

(deftest and.5 (and (values)))

(deftest and.6
  (and (values t nil) 'a)
  a)

(deftest and.7
  (and nil (values 'a 'b 'c))
  nil)

(deftest and.8
35
36
37
38
39
40
41
  (and (values 1 nil) (values nil 2))
  nil 2)

(deftest and.9
  (and (values nil t) t)
  nil)

42
43
44
45
46
47
48
;;; Test that explicit calls to macroexpand in subforms
;;; are done in the correct environment

(deftest and.10
  (macrolet
   ((%m (z) z))
   (and (expand-in-current-env (%m :a))
sds's avatar
sds committed
49
50
        (expand-in-current-env (%m :b))
        (expand-in-current-env (%m :c))))
51
52
53
54
  :c)

;;; Error tests

55
(deftest and.order.1
pfdietz's avatar
pfdietz committed
56
57
  (let ((x 0))
    (values (and nil (incf x))
sds's avatar
sds committed
58
            x))
pfdietz's avatar
pfdietz committed
59
60
  nil 0)

61
62
63
64
(deftest and.order.2
  (let ((i 0) a b c d)
    (values
     (and (setf a (incf i))
sds's avatar
sds committed
65
66
67
          (setf b (incf i))
          (setf c (incf i))
          (setf d (incf i)))
68
69
70
     i a b c d))
  4 4 1 2 3 4)

71
(deftest and.error.1
72
  (signals-error (funcall (macro-function 'and))
sds's avatar
sds committed
73
                 program-error)
74
  t)
75
76

(deftest and.error.2
77
  (signals-error (funcall (macro-function 'and) '(and))
sds's avatar
sds committed
78
                 program-error)
79
  t)
80
81

(deftest and.error.3
82
  (signals-error (funcall (macro-function 'and) '(and) nil nil)
sds's avatar
sds committed
83
                 program-error)
84
  t)