1 ;;;; miscellaneous side-effectful tests of the MOP
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; While most of SBCL is derived from the CMU CL system, the test
7 ;;;; files (like this one) were written from scratch after the fork
10 ;;;; This software is in the public domain and is provided with
11 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
12 ;;;; more information.
14 ;;; this file tests the accessor method class portion of the protocol
15 ;;; for Initialization of Class Metaobjects.
17 (defclass my-class
(standard-class) ())
18 (defmethod sb-mop:validate-superclass
((a my-class
) (b standard-class
)) t
)
20 (defclass my-reader
(sb-mop:standard-reader-method
) ())
21 (defclass my-writer
(sb-mop:standard-writer-method
) ())
25 (defmethod sb-mop:reader-method-class
((c my-class
) s
&rest initargs
)
26 (declare (ignore initargs
))
27 (push (cons (sb-mop:slot-definition-name s
) 'reader
) *calls
*)
28 (find-class 'my-reader
))
29 (defmethod sb-mop:writer-method-class
((c my-class
) s
&rest initargs
)
30 (declare (ignore initargs
))
31 (push (cons (sb-mop:slot-definition-name s
) 'writer
) *calls
*)
32 (find-class 'my-writer
))
38 (:metaclass my-class
))
40 (with-test (:name
(:mop-19
1))
41 (assert (= (length *calls
*) 4))
42 (assert (= (count 'a
*calls
* :key
#'car
) 1))
43 (assert (= (count 'b
*calls
* :key
#'car
) 1))
44 (assert (= (count 'c
*calls
* :key
#'car
) 2))
45 (assert (= (count 'reader
*calls
* :key
#'cdr
) 2))
46 (assert (= (count 'writer
*calls
* :key
#'cdr
) 2))
47 (let ((method (find-method #'a nil
(list (find-class 'foo
)))))
48 (assert (eq (class-of method
) (find-class 'my-reader
))))
49 (let ((method (find-method #'b nil
(list (find-class t
) (find-class 'foo
)))))
50 (assert (eq (class-of method
) (find-class 'my-writer
)))))
52 (defclass my-other-class
(my-class) ())
53 (defmethod sb-mop:validate-superclass
((a my-other-class
) (b standard-class
)) t
)
55 (defclass my-other-reader
(sb-mop:standard-reader-method
) ())
57 (defclass my-direct-slot-definition
(sb-mop:standard-direct-slot-definition
) ())
59 (defmethod sb-mop:direct-slot-definition-class
((c my-other-class
) &rest args
)
60 (declare (ignore args
))
61 (find-class 'my-direct-slot-definition
))
63 (defmethod sb-mop:reader-method-class
:around
64 (class (s my-direct-slot-definition
) &rest initargs
)
65 (declare (ignore initargs
))
66 (find-class 'my-other-reader
))
71 (:metaclass my-other-class
))
73 (with-test (:name
(:mop-19
2))
74 (let ((method (find-method #'d nil
(list (find-class 'bar
)))))
75 (assert (eq (class-of method
) (find-class 'my-other-reader
))))
76 (let ((method (find-method #'e nil
(list (find-class t
) (find-class 'bar
)))))
77 (assert (eq (class-of method
) (find-class 'my-writer
)))))