File: macro-function.lsp

package info (click to toggle)
cl-ansi-tests 20071218-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 7,000 kB
  • ctags: 22,025
  • sloc: lisp: 134,798; makefile: 144
file content (146 lines) | stat: -rw-r--r-- 3,067 bytes parent folder | download | duplicates (3)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Fri Jun  3 22:17:34 2005
;;;; Contains: Tests of MACRO-FUNCTION

(in-package :cl-test)

(deftest macro-function.1
  (loop for n in *cl-macro-symbols*
	unless (macro-function n)
	collect n)
  nil)

(deftest macro-function.2
  (loop for n in *cl-macro-symbols*
	unless (macro-function n nil)
	collect n)
  nil)

(deftest macro-function.3
  (loop for n in *cl-macro-symbols*
	unless (eval `(macrolet ((%m (s &environment env)
				     (list 'quote
					   (macro-function s env))))
			(%m ,n)))
	collect n)
  nil)

(deftest macro-function.4
  (macro-function (gensym))
  nil)

(deftest macro-function.5
  (remove-if-not #'macro-function *cl-function-symbols*)
  nil)

(deftest macro-function.6
  (remove-if-not #'macro-function *cl-accessor-symbols*)
  nil)

(deftest macro-function.7
  (let ((fn
	 (macrolet ((%m () 16))
	   (macrolet ((%n (&environment env)
			  (list 'quote (macro-function '%m env))))
	     (%n)))))
    (values
     (notnot (functionp fn))
     (funcall fn '(%m) nil)))
  t 16)

(deftest macro-function.8
  (let ((sym (gensym)))
    (setf (macro-function sym) (macro-function 'pop))
    (eval `(let ((x '(a b c)))
	     (values 
	      (,sym x)
	      x))))
  a (b c))

(deftest macro-function.9
  (let ((sym (gensym)))
    (setf (macro-function sym nil) (macro-function 'pop))
    (eval `(let ((x '(a b c)))
	     (values 
	      (,sym x)
	      x))))
  a (b c))

(deftest macro-function.10
  (let ((sym (gensym)))
    (eval `(defun ,sym (x) :bad))
    (setf (macro-function sym) (macro-function 'pop))
    (eval `(let ((x '(a b c)))
	     (values 
	      (,sym x)
	      x))))
  a (b c))

(deftest macro-function.11
  (let ((fn
	 (flet ((%m () 16))
	   (macrolet ((%n (&environment env)
			  (list 'quote (macro-function '%m env))))
	     (%n)))))
     fn)
  nil)

(deftest macro-function.12
  (let ((sym (gensym)))
    (eval `(defmacro ,sym () t))
    (let ((i 0))
      (values
       (funcall (macro-function (progn (incf i) sym)) (list sym) nil)
       i)))
  t 1)

(deftest macro-function.13
  (let ((sym (gensym)))
    (eval `(defmacro ,sym () t))
    (let ((i 0) a b)
      (values
       (funcall (macro-function (progn (setf a (incf i)) sym)
				(progn (setf b (incf i)) nil))
		(list sym) nil)
       i a b)))
  t 2 1 2)

(deftest macro-function.14
  (let ((sym (gensym))
	(i 0))
    (setf (macro-function (progn (incf i) sym)) (macro-function 'pop))
    (values 
     (eval `(let ((x '(a b c)))
	      (list
	       (,sym x)
	       x)))
     i))
  (a (b c)) 1)

(deftest macro-function.15
  (let ((sym (gensym))
	(i 0) a b)
    (setf (macro-function (progn (setf a (incf i)) sym)
			  (progn (setf b (incf i)) nil))
	  (macro-function 'pop))
    (values 
     (eval `(let ((x '(a b c)))
	      (list
	       (,sym x)
	       x)))
     i a b))
  (a (b c)) 2 1 2)



;;; Error tests

(deftest macro-function.error.1
  (signals-error (macro-function) program-error)
  t)

(deftest macro-function.error.2
  (signals-error (macro-function 'pop nil nil) program-error)
  t)