constantp.lsp 1.76 KB
Newer Older
1 2 3 4 5 6 7 8 9
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Mon Jan 13 19:12:17 2003
;;;; Contains: Tests for CONSTANTP

;;; See also defconstant.lsp

(in-package :cl-test)

10 11
;;; Error tests

12
(deftest constantp.error.1
13 14
  (signals-error (constantp) program-error)
  t)
15 16

(deftest constantp.error.2
17 18
  (signals-error (constantp nil nil nil) program-error)
  t)
19

20
;;; Non-error tests
21 22

(deftest constantp.1
23
  (check-predicate #'(lambda (e) (or (symbolp e) (consp e) (constantp e))))
24 25 26
  nil)

(deftest constantp.2
27
  (notnot-mv (constantp t))
28
  t)
sds's avatar
sds committed
29

30
(deftest constantp.3
31
  (notnot-mv (constantp nil))
32 33 34
  t)

(deftest constantp.4
35
  (notnot-mv (constantp :foo))
36 37 38 39 40 41 42 43 44
  t)

(deftest constantp.5
  (constantp (gensym))
  nil)

(defconstant constantp-test-symbol 1)

(defmacro constantp-macro (form &environment env)
45
  (notnot-mv (constantp form env)))
46 47 48 49

(deftest constantp.6
  (constantp-macro constantp-test-symbol)
  t)
sds's avatar
sds committed
50

51 52 53 54 55
(deftest constantp.7
  (constantp '(incf x))
  nil)

(deftest constantp.8
56
  (notnot-mv (constantp 1 nil))
57 58 59
  t)

(deftest constantp.9
60
  (notnot-mv (constantp ''(((foo)))))
61 62
  t)

63
(deftest constantp.10
64
  (notnot-mv (constantp 'pi))
65 66
  t)

67 68 69 70
(defmacro macro-for-constantp.11 (x) x)

(deftest constantp.11
  (macrolet ((macro-for-constantp.11 (y)
sds's avatar
sds committed
71 72
               (declare (ignore y))
               '*standard-input*))
73
    (macrolet ((%m (&environment env)
sds's avatar
sds committed
74 75 76
                 (if (constantp '(macro-for-constantp.11 0) env)
                     :bad
                     :good)))
77 78
      (%m)))
  :good)
sds's avatar
sds committed
79

80

81
(deftest constantp.order.1
82 83 84 85 86 87 88
  (let ((i 0))
    (values
     (notnot (constantp (progn (incf i) 1)))
     i))
  t 1)

(deftest constantp.order.2
89 90 91
  (let ((i 0) x y)
    (values
     (notnot (constantp (progn (setf x (incf i)) 1)
sds's avatar
sds committed
92
                        (progn (setf y (incf i)) nil)))
93 94 95
     i x y))
  t 2 1 2)

sds's avatar
sds committed
96

97