macroexpand.lsp 1.88 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sat May 28 13:43:00 2005
;;;; Contains: Tests of MACROEXPAND

(in-package :cl-test)

(deftest macroexpand.error.1
  (signals-error (macroexpand) program-error)
  t)

(deftest macroexpand.error.2
  (signals-error (macroexpand 'x nil nil) program-error)
  t)

;;; Non-error tests

(deftest macroexpand.1
19 20 21
  (check-predicate
   #'(lambda (x)
       (or (symbolp x) (consp x)
sds's avatar
sds committed
22 23 24 25
           (let ((vals (multiple-value-list (macroexpand x))))
             (and (= (length vals) 2)
                  (eql (car vals) x)
                  (null (cadr vals)))))))
26 27 28
  nil)

(deftest macroexpand.2
29 30 31
  (check-predicate
   #'(lambda (x)
       (or (symbolp x) (consp x)
sds's avatar
sds committed
32 33 34 35
           (let ((vals (multiple-value-list (macroexpand x nil))))
             (and (= (length vals) 2)
                  (eql (car vals) x)
                  (null (cadr vals)))))))
36 37 38
  nil)

(deftest macroexpand.3
pfdietz's avatar
pfdietz committed
39 40
  (macrolet
      ((%m (&environment env)
sds's avatar
sds committed
41 42 43 44 45 46 47
           `(quote
             ,(check-predicate
               #'(lambda (x) (or (symbolp x) (consp x)
                                 (let ((vals (multiple-value-list (macroexpand x env))))
                                   (and (= (length vals) 2)
                                        (eql (car vals) x)
                                        (null (cadr vals))))))))))
48 49 50 51 52 53
    (%m))
  nil)

(deftest macroexpand.4
  (macrolet ((%m () ''foo))
    (macrolet ((%m2 (&environment env)
sds's avatar
sds committed
54
                    (macroexpand '(%m) env)))
55 56 57
      (%m2)))
  foo)

pfdietz's avatar
pfdietz committed
58 59
(deftest macroexpand.5
  (let ((form (list (gensym)))
sds's avatar
sds committed
60
        (i 0))
pfdietz's avatar
pfdietz committed
61 62 63 64
    (values
     (equalt (macroexpand (progn (incf i) form)) form)
     i))
  t 1)
65

pfdietz's avatar
pfdietz committed
66 67
(deftest macroexpand.6
  (let ((form (list (gensym)))
sds's avatar
sds committed
68
        (i 0) a b)
pfdietz's avatar
pfdietz committed
69 70
    (values
     (equalt (macroexpand (progn (setf a (incf i)) form)
sds's avatar
sds committed
71 72
                          (progn (setf b (incf i)) nil))
             form)
pfdietz's avatar
pfdietz committed
73 74
     i a b))
  t 2 1 2)