aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorStefan Monnier2014-12-22 22:05:46 -0500
committerStefan Monnier2014-12-22 22:05:46 -0500
commitee93d7ad4291a0946efe3197481cfbeff92f29b8 (patch)
tree4ff0ca7149c5bead965c4e3e49d104af1cf42e1c /test
parentd4a12e7a9a46bbff2f9c4d59ecc284621634a2e8 (diff)
downloademacs-ee93d7ad4291a0946efe3197481cfbeff92f29b8.tar.gz
emacs-ee93d7ad4291a0946efe3197481cfbeff92f29b8.zip
* lisp/emacs-lisp/eieio*.el: Remove "name" field of objects
* lisp/emacs-lisp/eieio-base.el (clone) <eieio-instance-inheritor>: Use call-next-method. (eieio-constructor): Rename from `constructor'. (eieio-persistent-convert-list-to-object): Drop objname. (eieio-persistent-validate/fix-slot-value): Don't hardcode eieio--object-num-slots. (eieio-named): Use a normal slot. (slot-missing) <eieio-named>: Remove. (eieio-object-name-string, eieio-object-set-name-string, clone) <eieio-named>: New methods. * lisp/emacs-lisp/eieio-core.el (eieio--defalias): Follow aliases. (eieio--object): Remove `name' field. (eieio-defclass): Adjust to new convention where constructors don't take an "object name" any more. (eieio--defgeneric-init-form, eieio--defmethod): Follow aliases. (eieio-validate-slot-value, eieio-oset-default) (eieio-slot-name-index): Don't hardcode eieio--object-num-slots. (eieio-generic-call-primary-only): Simplify. * lisp/emacs-lisp/eieio-custom.el (eieio-widget-test): Remove dummy arg. (eieio-object-value-get): Use eieio-object-set-name-string. * lisp/emacs-lisp/eieio.el (make-instance): Simplify by not adding an object name argument. (eieio-object-name): Use eieio-object-name-string. (eieio--object-names): New const. (eieio-object-name-string, eieio-object-set-name-string): Re-implement using a hashtable rather than a built-in slot. (eieio-constructor): Rename from `constructor'. Remove `newname' arg. (clone): Don't mess with the object's "name". * test/automated/eieio-test-persist.el (persistent-with-objs-slot-subs): The type FOO-child is the same as FOO. * test/automated/eieio-tests.el: Remove dummy object names.
Diffstat (limited to 'test')
-rw-r--r--test/automated/eieio-test-methodinvoke.el5
-rw-r--r--test/automated/eieio-test-persist.el2
-rw-r--r--test/automated/eieio-tests.el62
3 files changed, 35 insertions, 34 deletions
diff --git a/test/automated/eieio-test-methodinvoke.el b/test/automated/eieio-test-methodinvoke.el
index 20b47a771d8..3f86d8fcc99 100644
--- a/test/automated/eieio-test-methodinvoke.el
+++ b/test/automated/eieio-test-methodinvoke.el
@@ -174,17 +174,18 @@
174(defclass C-base2 () ()) 174(defclass C-base2 () ())
175(defclass C (C-base1 C-base2) ()) 175(defclass C (C-base1 C-base2) ())
176 176
177;; Just use the obsolete name once, to make sure it also works.
177(defmethod constructor :STATIC ((p C-base1) &rest args) 178(defmethod constructor :STATIC ((p C-base1) &rest args)
178 (eieio-test-method-store) 179 (eieio-test-method-store)
179 (if (next-method-p) (call-next-method)) 180 (if (next-method-p) (call-next-method))
180 ) 181 )
181 182
182(defmethod constructor :STATIC ((p C-base2) &rest args) 183(defmethod eieio-constructor :STATIC ((p C-base2) &rest args)
183 (eieio-test-method-store) 184 (eieio-test-method-store)
184 (if (next-method-p) (call-next-method)) 185 (if (next-method-p) (call-next-method))
185 ) 186 )
186 187
187(defmethod constructor :STATIC ((p C) &rest args) 188(defmethod eieio-constructor :STATIC ((p C) &rest args)
188 (eieio-test-method-store) 189 (eieio-test-method-store)
189 (call-next-method) 190 (call-next-method)
190 ) 191 )
diff --git a/test/automated/eieio-test-persist.el b/test/automated/eieio-test-persist.el
index d6f53cd9db2..00de3cf0d7c 100644
--- a/test/automated/eieio-test-persist.el
+++ b/test/automated/eieio-test-persist.el
@@ -175,7 +175,7 @@ persistent class.")
175 175
176(defclass persistent-with-objs-slot-subs (eieio-persistent) 176(defclass persistent-with-objs-slot-subs (eieio-persistent)
177 ((pnp :initarg :pnp 177 ((pnp :initarg :pnp
178 :type (or null persist-not-persistent-child) 178 :type (or null persist-not-persistent)
179 :initform nil)) 179 :initform nil))
180 "Class for testing the saving of slots with objects in them.") 180 "Class for testing the saving of slots with objects in them.")
181 181
diff --git a/test/automated/eieio-tests.el b/test/automated/eieio-tests.el
index 87151f6a0da..91ddfc4fcf3 100644
--- a/test/automated/eieio-tests.el
+++ b/test/automated/eieio-tests.el
@@ -157,7 +157,7 @@
157(ert-deftest eieio-test-02-abstract-class () 157(ert-deftest eieio-test-02-abstract-class ()
158 ;; Abstract classes cannot be instantiated, so this should throw an 158 ;; Abstract classes cannot be instantiated, so this should throw an
159 ;; error 159 ;; error
160 (should-error (abstract-class "Test"))) 160 (should-error (abstract-class)))
161 161
162(defgeneric generic1 () "First generic function") 162(defgeneric generic1 () "First generic function")
163 163
@@ -179,7 +179,7 @@
179 "Method generic1 that can take a non-object." 179 "Method generic1 that can take a non-object."
180 not-an-object) 180 not-an-object)
181 181
182 (let ((ans-obj (generic1 (class-a "test"))) 182 (let ((ans-obj (generic1 (class-a)))
183 (ans-num (generic1 666))) 183 (ans-num (generic1 666)))
184 (should (eq ans-obj 'monkey)) 184 (should (eq ans-obj 'monkey))
185 (should (eq ans-num 666)))) 185 (should (eq ans-num 666))))
@@ -200,7 +200,7 @@ Argument C is the class bound to this static method."
200 ;; Call static method on a class and see if it worked 200 ;; Call static method on a class and see if it worked
201 (static-method-class-method static-method-class 'class) 201 (static-method-class-method static-method-class 'class)
202 (should (eq (oref static-method-class some-slot) 'class)) 202 (should (eq (oref static-method-class some-slot) 'class))
203 (static-method-class-method (static-method-class "test") 'object) 203 (static-method-class-method (static-method-class) 'object)
204 (should (eq (oref static-method-class some-slot) 'object))) 204 (should (eq (oref static-method-class some-slot) 'object)))
205 205
206(ert-deftest eieio-test-05-static-method-2 () 206(ert-deftest eieio-test-05-static-method-2 ()
@@ -216,7 +216,7 @@ Argument C is the class bound to this static method."
216 216
217 (static-method-class-method static-method-class-2 'class) 217 (static-method-class-method static-method-class-2 'class)
218 (should (eq (oref static-method-class-2 some-slot) 'moose-class)) 218 (should (eq (oref static-method-class-2 some-slot) 'moose-class))
219 (static-method-class-method (static-method-class-2 "test") 'object) 219 (static-method-class-method (static-method-class-2) 'object)
220 (should (eq (oref static-method-class-2 some-slot) 'moose-object))) 220 (should (eq (oref static-method-class-2 some-slot) 'moose-object)))
221 221
222 222
@@ -230,14 +230,14 @@ Argument C is the class bound to this static method."
230(defvar eitest-b nil) 230(defvar eitest-b nil)
231(ert-deftest eieio-test-06-allocate-objects () 231(ert-deftest eieio-test-06-allocate-objects ()
232 ;; allocate an object to use 232 ;; allocate an object to use
233 (should (setq eitest-ab (class-ab "abby"))) 233 (should (setq eitest-ab (class-ab)))
234 (should (setq eitest-a (class-a "aye"))) 234 (should (setq eitest-a (class-a)))
235 (should (setq eitest-b (class-b "fooby")))) 235 (should (setq eitest-b (class-b))))
236 236
237(ert-deftest eieio-test-07-make-instance () 237(ert-deftest eieio-test-07-make-instance ()
238 (should (make-instance 'class-ab)) 238 (should (make-instance 'class-ab))
239 (should (make-instance 'class-a :water 'cho)) 239 (should (make-instance 'class-a :water 'cho))
240 (should (make-instance 'class-b "a name"))) 240 (should (make-instance 'class-b)))
241 241
242(defmethod class-cn ((a class-a)) 242(defmethod class-cn ((a class-a))
243 "Try calling `call-next-method' when there isn't one. 243 "Try calling `call-next-method' when there isn't one.
@@ -354,7 +354,7 @@ METHOD is the method that was attempting to be called."
354 (call-next-method) 354 (call-next-method)
355 (oset a test-tag 1)) 355 (oset a test-tag 1))
356 356
357 (let ((ca (class-a "class act"))) 357 (let ((ca (class-a)))
358 (should-not (/= (oref ca test-tag) 2)))) 358 (should-not (/= (oref ca test-tag) 2))))
359 359
360 360
@@ -403,7 +403,7 @@ METHOD is the method that was attempting to be called."
403 (t (call-next-method)))) 403 (t (call-next-method))))
404 404
405(ert-deftest eieio-test-17-virtual-slot () 405(ert-deftest eieio-test-17-virtual-slot ()
406 (setq eitest-vsca (virtual-slot-class "eitest-vsca" :base-value 1)) 406 (setq eitest-vsca (virtual-slot-class :base-value 1))
407 ;; Check slot values 407 ;; Check slot values
408 (should (= (oref eitest-vsca :base-value) 1)) 408 (should (= (oref eitest-vsca :base-value) 1))
409 (should (= (oref eitest-vsca :derived-value) 2)) 409 (should (= (oref eitest-vsca :derived-value) 2))
@@ -418,7 +418,7 @@ METHOD is the method that was attempting to be called."
418 418
419 ;; should also be possible to initialize instance using virtual slot 419 ;; should also be possible to initialize instance using virtual slot
420 420
421 (setq eitest-vscb (virtual-slot-class "eitest-vscb" :derived-value 5)) 421 (setq eitest-vscb (virtual-slot-class :derived-value 5))
422 (should (= (oref eitest-vscb :base-value) 4)) 422 (should (= (oref eitest-vscb :base-value) 4))
423 (should (= (oref eitest-vscb :derived-value) 5))) 423 (should (= (oref eitest-vscb :derived-value) 5)))
424 424
@@ -444,7 +444,7 @@ METHOD is the method that was attempting to be called."
444 ;; After setting 'water to 'moose, make sure a new object has 444 ;; After setting 'water to 'moose, make sure a new object has
445 ;; the right stuff. 445 ;; the right stuff.
446 (oset-default (eieio-object-class eitest-a) water 'penguin) 446 (oset-default (eieio-object-class eitest-a) water 'penguin)
447 (should (eq (oref (class-a "foo") water) 'penguin)) 447 (should (eq (oref (class-a) water) 'penguin))
448 448
449 ;; Revert the above 449 ;; Revert the above
450 (defmethod slot-unbound ((a class-a) &rest foo) 450 (defmethod slot-unbound ((a class-a) &rest foo)
@@ -458,12 +458,12 @@ METHOD is the method that was attempting to be called."
458 ;; We should not be able to set a string here 458 ;; We should not be able to set a string here
459 (should-error (oset eitest-ab water "a string, not a symbol") :type 'invalid-slot-type) 459 (should-error (oset eitest-ab water "a string, not a symbol") :type 'invalid-slot-type)
460 (should-error (oset eitest-ab classslot "a string, not a symbol") :type 'invalid-slot-type) 460 (should-error (oset eitest-ab classslot "a string, not a symbol") :type 'invalid-slot-type)
461 (should-error (class-a "broken-type-a" :water "a string not a symbol") :type 'invalid-slot-type)) 461 (should-error (class-a :water "a string not a symbol") :type 'invalid-slot-type))
462 462
463(ert-deftest eieio-test-20-class-allocated-slots () 463(ert-deftest eieio-test-20-class-allocated-slots ()
464 ;; Test out class allocated slots 464 ;; Test out class allocated slots
465 (defvar eitest-aa nil) 465 (defvar eitest-aa nil)
466 (setq eitest-aa (class-a "another")) 466 (setq eitest-aa (class-a))
467 467
468 ;; Make sure class slots do not track between objects 468 ;; Make sure class slots do not track between objects
469 (let ((newval 'moose)) 469 (let ((newval 'moose))
@@ -498,7 +498,7 @@ METHOD is the method that was attempting to be called."
498(ert-deftest eieio-test-21-eval-at-construction-time () 498(ert-deftest eieio-test-21-eval-at-construction-time ()
499 ;; initforms that need to be evalled at construction time. 499 ;; initforms that need to be evalled at construction time.
500 (setq eieio-test-permuting-value 2) 500 (setq eieio-test-permuting-value 2)
501 (setq eitest-pvinit (inittest "permuteme")) 501 (setq eitest-pvinit (inittest))
502 502
503 (should (eq (oref eitest-pvinit staticval) 1)) 503 (should (eq (oref eitest-pvinit staticval) 1))
504 (should (eq (oref eitest-pvinit symval) 'eieio-test-permuting-value)) 504 (should (eq (oref eitest-pvinit symval) 'eieio-test-permuting-value))
@@ -514,11 +514,11 @@ METHOD is the method that was attempting to be called."
514 "Test class that will be a calculated value.") 514 "Test class that will be a calculated value.")
515 515
516 (defclass eitest-superior nil 516 (defclass eitest-superior nil
517 ((sub :initform (eitest-subordinate "test") 517 ((sub :initform (eitest-subordinate)
518 :type eitest-subordinate)) 518 :type eitest-subordinate))
519 "A class with an initform that creates a class.") 519 "A class with an initform that creates a class.")
520 520
521 (should (setq eitest-tests (eitest-superior "test"))) 521 (should (setq eitest-tests (eitest-superior)))
522 522
523 (should-error 523 (should-error
524 (eval 524 (eval
@@ -546,8 +546,8 @@ METHOD is the method that was attempting to be called."
546 (should (not (class-a-child-p "foo")))) 546 (should (not (class-a-child-p "foo"))))
547 547
548(ert-deftest eieio-test-24-object-predicates () 548(ert-deftest eieio-test-24-object-predicates ()
549 (let ((listooa (list (class-ab "ab") (class-a "a"))) 549 (let ((listooa (list (class-ab) (class-a)))
550 (listoob (list (class-ab "ab") (class-b "b")))) 550 (listoob (list (class-ab) (class-b))))
551 (should (class-a-list-p listooa)) 551 (should (class-a-list-p listooa))
552 (should (class-b-list-p listoob)) 552 (should (class-b-list-p listoob))
553 (should-not (class-b-list-p listooa)) 553 (should-not (class-b-list-p listooa))
@@ -555,7 +555,7 @@ METHOD is the method that was attempting to be called."
555 555
556(defvar eitest-t1 nil) 556(defvar eitest-t1 nil)
557(ert-deftest eieio-test-25-slot-tests () 557(ert-deftest eieio-test-25-slot-tests ()
558 (setq eitest-t1 (class-c "C1")) 558 (setq eitest-t1 (class-c))
559 ;; Slot initialization 559 ;; Slot initialization
560 (should (eq (oref eitest-t1 slot-1) 'moose)) 560 (should (eq (oref eitest-t1 slot-1) 'moose))
561 (should (eq (oref eitest-t1 :moose) 'moose)) 561 (should (eq (oref eitest-t1 :moose) 'moose))
@@ -564,7 +564,7 @@ METHOD is the method that was attempting to be called."
564 ;; Check private slot accessor 564 ;; Check private slot accessor
565 (should (string= (get-slot-2 eitest-t1) "penguin")) 565 (should (string= (get-slot-2 eitest-t1) "penguin"))
566 ;; Pass string instead of symbol 566 ;; Pass string instead of symbol
567 (should-error (class-c "C2" :moose "not a symbol") :type 'invalid-slot-type) 567 (should-error (class-c :moose "not a symbol") :type 'invalid-slot-type)
568 (should (eq (get-slot-3 eitest-t1) 'emu)) 568 (should (eq (get-slot-3 eitest-t1) 'emu))
569 (should (eq (get-slot-3 class-c) 'emu)) 569 (should (eq (get-slot-3 class-c) 'emu))
570 ;; Check setf 570 ;; Check setf
@@ -576,13 +576,13 @@ METHOD is the method that was attempting to be called."
576(defvar eitest-t2 nil) 576(defvar eitest-t2 nil)
577(ert-deftest eieio-test-26-default-inheritance () 577(ert-deftest eieio-test-26-default-inheritance ()
578 ;; See previous test, nor for subclass 578 ;; See previous test, nor for subclass
579 (setq eitest-t2 (class-subc "subc")) 579 (setq eitest-t2 (class-subc))
580 (should (eq (oref eitest-t2 slot-1) 'moose)) 580 (should (eq (oref eitest-t2 slot-1) 'moose))
581 (should (eq (oref eitest-t2 :moose) 'moose)) 581 (should (eq (oref eitest-t2 :moose) 'moose))
582 (should (string= (get-slot-2 eitest-t2) "linux")) 582 (should (string= (get-slot-2 eitest-t2) "linux"))
583 (should-error (oref eitest-t2 slot-2) :type 'invalid-slot-name) 583 (should-error (oref eitest-t2 slot-2) :type 'invalid-slot-name)
584 (should (string= (get-slot-2 eitest-t2) "linux")) 584 (should (string= (get-slot-2 eitest-t2) "linux"))
585 (should-error (class-subc "C2" :moose "not a symbol") :type 'invalid-slot-type)) 585 (should-error (class-subc :moose "not a symbol") :type 'invalid-slot-type))
586 586
587;;(ert-deftest eieio-test-27-inherited-new-value () 587;;(ert-deftest eieio-test-27-inherited-new-value ()
588 ;;; HACK ALERT: The new value of a class slot is inherited by the 588 ;;; HACK ALERT: The new value of a class slot is inherited by the
@@ -646,8 +646,8 @@ Do not override for `prot-2'."
646(defvar eitest-p1 nil) 646(defvar eitest-p1 nil)
647(defvar eitest-p2 nil) 647(defvar eitest-p2 nil)
648(ert-deftest eieio-test-28-slot-protection () 648(ert-deftest eieio-test-28-slot-protection ()
649 (setq eitest-p1 (prot-1 "")) 649 (setq eitest-p1 (prot-1))
650 (setq eitest-p2 (prot-2 "")) 650 (setq eitest-p2 (prot-2))
651 ;; Access public slots 651 ;; Access public slots
652 (oref eitest-p1 slot-1) 652 (oref eitest-p1 slot-1)
653 (oref eitest-p2 slot-1) 653 (oref eitest-p2 slot-1)
@@ -742,7 +742,7 @@ Subclasses to override slot attributes.")
742 "This class should throw an error."))) 742 "This class should throw an error.")))
743 743
744 ;; Initform should override instance allocation 744 ;; Initform should override instance allocation
745 (let ((obj (slotattr-ok "moose"))) 745 (let ((obj (slotattr-ok)))
746 (should (eq (oref obj initform) 'no-init)))) 746 (should (eq (oref obj initform) 'no-init))))
747 747
748(defclass slotattr-class-base () 748(defclass slotattr-class-base ()
@@ -825,7 +825,7 @@ Subclasses to override slot attributes.")
825 825
826(ert-deftest eieio-test-32-test-clone-boring-objects () 826(ert-deftest eieio-test-32-test-clone-boring-objects ()
827 ;; A simple make instance with EIEIO extension 827 ;; A simple make instance with EIEIO extension
828 (should (setq eitest-CLONETEST1 (make-instance 'class-a "a"))) 828 (should (setq eitest-CLONETEST1 (make-instance 'class-a)))
829 (should (setq eitest-CLONETEST2 (clone eitest-CLONETEST1))) 829 (should (setq eitest-CLONETEST2 (clone eitest-CLONETEST1)))
830 830
831 ;; CLOS form of make-instance 831 ;; CLOS form of make-instance
@@ -839,7 +839,7 @@ Subclasses to override slot attributes.")
839 839
840(ert-deftest eieio-test-33-instance-tracker () 840(ert-deftest eieio-test-33-instance-tracker ()
841 (let (IT-list IT1) 841 (let (IT-list IT1)
842 (should (setq IT1 (IT "trackme"))) 842 (should (setq IT1 (IT)))
843 ;; The instance tracker must find this 843 ;; The instance tracker must find this
844 (should (eieio-instance-tracker-find 'die 'slot1 'IT-list)) 844 (should (eieio-instance-tracker-find 'die 'slot1 'IT-list))
845 ;; Test deletion 845 ;; Test deletion
@@ -851,8 +851,8 @@ Subclasses to override slot attributes.")
851 "A Singleton test object.") 851 "A Singleton test object.")
852 852
853(ert-deftest eieio-test-34-singletons () 853(ert-deftest eieio-test-34-singletons ()
854 (let ((obj1 (SINGLE "Moose")) 854 (let ((obj1 (SINGLE))
855 (obj2 (SINGLE "Cow"))) 855 (obj2 (SINGLE)))
856 (should (eieio-object-p obj1)) 856 (should (eieio-object-p obj1))
857 (should (eieio-object-p obj2)) 857 (should (eieio-object-p obj2))
858 (should (eq obj1 obj2)) 858 (should (eq obj1 obj2))
@@ -865,7 +865,7 @@ Subclasses to override slot attributes.")
865 865
866(ert-deftest eieio-test-35-named-object () 866(ert-deftest eieio-test-35-named-object ()
867 (let (N) 867 (let (N)
868 (should (setq N (NAMED "Foo"))) 868 (should (setq N (NAMED :object-name "Foo")))
869 (should (string= "Foo" (oref N object-name))) 869 (should (string= "Foo" (oref N object-name)))
870 (should-error (oref N missing-slot) :type 'invalid-slot-name) 870 (should-error (oref N missing-slot) :type 'invalid-slot-name)
871 (oset N object-name "NewName") 871 (oset N object-name "NewName")