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 contains simple tests for COMPUTE-SLOTS :AROUND
15 ;;; respecting the order requested by the primary method.
17 ;;; COMPUTE-SLOTS :AROUND respecting requested order
18 (defclass slot-rearrangement-class
(standard-class)
20 (defmethod sb-mop:compute-slots
((c slot-rearrangement-class
))
21 (reverse (call-next-method)))
22 (defmethod sb-mop:validate-superclass
((c slot-rearrangement-class
)
25 (defclass rearranged-class
()
26 ((a :initarg
:a
:initform
1)
27 (b :initarg
:b
:initform
2))
28 (:metaclass slot-rearrangement-class
))
30 (with-test (:name
(:compute-slots
:standard-class
:order
))
31 (let ((class (find-class 'rearranged-class
)))
32 (sb-mop:finalize-inheritance class
)
33 (assert (equal (mapcar #'sb-mop
:slot-definition-name
34 (sb-mop:class-slots class
))
36 (with-test (:name
(:compute-slots
:standard-class
:slots
))
37 (let ((r (make-instance 'rearranged-class
))
38 (r2 (make-instance 'rearranged-class
:a
3 :b
4)))
39 (assert (eql (slot-value r
'a
) 1))
40 (assert (eql (slot-value r
'b
) 2))
41 (assert (eql (slot-value r2
'a
) 3))
42 (assert (eql (slot-value r2
'b
) 4))))
44 (defclass funcallable-slot-rearrangement-class
(sb-mop:funcallable-standard-class
)
46 (defmethod sb-mop:compute-slots
((c funcallable-slot-rearrangement-class
))
47 (reverse (call-next-method)))
48 (defmethod sb-mop:validate-superclass
((c funcallable-slot-rearrangement-class
)
49 (s sb-mop
:funcallable-standard-class
))
51 (defclass funcallable-rearranged-class
()
52 ((a :initarg
:a
:initform
1)
53 (b :initarg
:b
:initform
2))
54 (:metaclass funcallable-slot-rearrangement-class
))
56 (with-test (:name
(:compute-slots
:funcallable-standard-class
:order
))
57 (let ((class (find-class 'funcallable-rearranged-class
)))
58 (sb-mop:finalize-inheritance class
)
59 (assert (equal (mapcar #'sb-mop
:slot-definition-name
60 (sb-mop:class-slots class
))
63 (with-test (:name
(:compute-slots
:funcallable-standard-class
:slots
))
64 (let ((r (make-instance 'funcallable-rearranged-class
))
65 (r2 (make-instance 'funcallable-rearranged-class
:a
3 :b
4)))
66 (assert (eql (slot-value r
'a
) 1))
67 (assert (eql (slot-value r
'b
) 2))
68 (assert (eql (slot-value r2
'a
) 3))
69 (assert (eql (slot-value r2
'b
) 4))))
71 (with-test (:name
(:compute-slots
:funcallable-standard-clas
:function
))
72 (let ((r (make-instance 'funcallable-rearranged-class
)))
73 (sb-mop:set-funcallable-instance-function r
(lambda (x) (list "Hello, World!" x
)))
74 (assert (equal (funcall r
3) '("Hello, World!" 3)))))