define-modify-macro.lsp 2.74 KB
Newer Older
1 2 3 4 5 6 7 8
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sat Oct 19 11:42:14 2002
;;;; Contains: Tests of DEFINE-MODIFY-MACRO

(in-package :cl-test)

(deftest define-modify-macro.1
9
  (values
sds's avatar
sds committed
10 11 12
   (eval '(define-modify-macro dmm1-appendf (&rest args)
            append "Append lists onto a list"))
   (eval
13 14
    '(let ((u '(p q r)) v)
       (list
sds's avatar
sds committed
15 16 17 18 19 20
        (setq v u)
        (dmm1-appendf u '(a b c d))
        (dmm1-appendf u ())
        (dmm1-appendf u '(e f g))
        u
        v))))
21
  dmm1-appendf
22 23 24 25 26 27
  ((p q r)
   (p q r a b c d)
   (p q r a b c d)
   (p q r a b c d e f g)
   (p q r a b c d e f g)
   (p q r)))
28 29

(deftest define-modify-macro.2
30 31 32 33 34
  (values
   (eval '(define-modify-macro new-incf (&optional (delta 1)) +))
   (eval
    '(let ((i 10))
       (list
sds's avatar
sds committed
35 36 37
        (new-incf i)
        (new-incf i 100)
        i))))
38
  new-incf
39
  (11 111 111))
40 41

(deftest define-modify-macro.3
42 43 44 45
  (values
   (eval '(define-modify-macro new-incf1 (&optional (delta 1)) +))
   (eval
    '(let ((a (vector 0 0 0 0 0))
sds's avatar
sds committed
46
           (i 1))
47
       (list
sds's avatar
sds committed
48 49 50
        (new-incf1 (aref a (incf i)))
        a
        i))))
51 52
  new-incf1
  (1 #(0 0 1 0 0) 2))
53 54

(deftest define-modify-macro.4
55 56 57 58
  (values
   (eval '(define-modify-macro new-incf2 (&optional (delta 1)) +))
   (eval
    '(let ((a (vector 0 0 0 0 0))
sds's avatar
sds committed
59
           (i 1))
60
       (list
sds's avatar
sds committed
61 62 63
        (new-incf2 (aref a (incf i)) (incf i))
        a
        i))))
64 65
  new-incf2
  (3 #(0 0 3 0 0) 3))
66

67
;;; (deftest define-modify-macro.error.1
68 69
;;;   (signals-error (define-modify-macro)  program-error)
;;;   t)
sds's avatar
sds committed
70
;;;
71
;;; (deftest define-modify-macro.error.2
72 73
;;;   (signals-error (define-modify-macro dfm-error-1) program-error)
;;;   t)
sds's avatar
sds committed
74
;;;
75
;;; (deftest define-modify-macro.error.3
76 77
;;;   (signals-error (define-modify-macro dfm-error-2 ()) program-error)
;;;   t)
sds's avatar
sds committed
78
;;;
79
;;; (deftest define-modify-macro.error.4
80
;;;   (signals-error (define-modify-macro dfm-error-2 () nil "Documentation"
sds's avatar
sds committed
81
;;;                 "extra illegal argument")
82 83
;;;                   program-error)
;;;   t)
84

85 86
(def-macro-test define-modify-macro.error.1
  (define-modify-macro nonexistent-modify-macro () foo))
87 88 89 90 91 92 93 94 95 96 97 98 99 100

;;; Documentation tests

(deftest define-modify-macro.documentation.1
  (let ((sym (gensym)))
    (eval `(define-modify-macro ,sym (&optional (delta 1)) +))
    (values
     (documentation sym 'function)
     (documentation (macro-function sym) 'function)
     (documentation (macro-function sym) t)))
  nil nil nil)

(deftest define-modify-macro.documentation.2
  (let ((sym (gensym))
sds's avatar
sds committed
101
        (doc "DMM-DOC"))
102 103 104 105 106 107
    (eval `(define-modify-macro ,sym (&optional (delta 1)) + ,doc))
    (values
     (equalt doc (or (documentation sym 'function) doc))
     (equalt doc (or (documentation (macro-function sym) 'function) doc))
     (equalt doc (or (documentation (macro-function sym) t) doc))))
  t t t)