diff options
| author | Stefan Monnier | 2015-03-18 23:02:26 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2015-03-18 23:02:26 -0400 |
| commit | 50c117fe86d94719807cbe08353c032779b3b910 (patch) | |
| tree | 9db572083112db33d17d759a245278fa0af7b897 /test | |
| parent | f469024eea692a163beb98a824b5cc0a4e8bcda8 (diff) | |
| download | emacs-50c117fe86d94719807cbe08353c032779b3b910.tar.gz emacs-50c117fe86d94719807cbe08353c032779b3b910.zip | |
EIEIO: Change class's representation to unify instance & class slots
* lisp/emacs-lisp/eieio-core.el (eieio--class): Change field names and order
to match those of cl--class; use cl--slot for both instance slots and
class slots.
(eieio--object-num-slots): Use cl-struct-slot-info.
(eieio--object-class): Rename from eieio--object-class-object.
(eieio--object-class-name): Remove.
(eieio-defclass-internal): Adjust to new slot representation.
Store doc in class rather than in `variable-documentation'.
(eieio--perform-slot-validation-for-default): Change API to take
a slot object.
(eieio--slot-override): New function.
(eieio--add-new-slot): Rewrite.
(eieio-copy-parents-into-subclass): Rewrite.
(eieio--validate-slot-value, eieio--validate-class-slot-value)
(eieio-oref-default, eieio-oset-default)
(eieio--class-slot-name-index, eieio-set-defaults): Adjust to new
slot representation.
(eieio--c3-merge-lists): Simplify.
(eieio--class/struct-parents): New function.
(eieio--class-precedence-bfs): Use it.
* lisp/emacs-lisp/eieio.el (with-slots): Use macroexp-let2.
(object-class-fast): Change recommend replacement.
(eieio-object-class): Rewrite.
(slot-exists-p): Adjust to new slot representation.
(initialize-instance): Adjust to new slot representation.
(object-write): Adjust to new slot representation.
* lisp/emacs-lisp/eieio-base.el (eieio-persistent-convert-list-to-object):
Manually map initargs to slot names.
(eieio-persistent-validate/fix-slot-value): Adjust to new
slot representation.
* lisp/emacs-lisp/eieio-compat.el (eieio--generic-static-symbol-specializers):
Extract from eieio--generic-static-symbol-generalizer.
(eieio--generic-static-symbol-generalizer): Use it.
* lisp/emacs-lisp/eieio-custom.el (eieio-object-value-create)
(eieio-object-value-get): Adjust to new slot representation.
* lisp/emacs-lisp/eieio-datadebug.el (data-debug/eieio-insert-slots):
Declare to silence warnings.
(data-debug-insert-object-button): Avoid `object-slots'.
(data-debug/eieio-insert-slots): Adjust to new slot representation.
* lisp/emacs-lisp/eieio-opt.el (eieio--help-print-slot): New function
extracted from eieio-help-class-slots.
(eieio-help-class-slots): Use it. Adjust to new slot representation.
* test/automated/eieio-test-methodinvoke.el (make-instance): Use new-style
`subclass' specializer for a change.
* test/automated/eieio-test-persist.el (persist-test-save-and-compare):
Adjust to new slot representation.
* test/automated/eieio-tests.el (eieio-test-17-virtual-slot): Don't use
initarg in `oset'.
(eieio-test-32-slot-attribute-override-2): Adjust to new
slot representation.
* lisp/emacs-lisp/cl-preloaded.el (cl--class): Fix type of `parents'.
Diffstat (limited to 'test')
| -rw-r--r-- | test/ChangeLog | 13 | ||||
| -rw-r--r-- | test/automated/eieio-test-methodinvoke.el | 2 | ||||
| -rw-r--r-- | test/automated/eieio-test-persist.el | 17 | ||||
| -rw-r--r-- | test/automated/eieio-tests.el | 57 |
4 files changed, 47 insertions, 42 deletions
diff --git a/test/ChangeLog b/test/ChangeLog index e150aba2874..15408a3c970 100644 --- a/test/ChangeLog +++ b/test/ChangeLog | |||
| @@ -1,3 +1,16 @@ | |||
| 1 | 2015-03-19 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * automated/eieio-tests.el (eieio-test-17-virtual-slot): Don't use | ||
| 4 | initarg in `oset'. | ||
| 5 | (eieio-test-32-slot-attribute-override-2): Adjust to new | ||
| 6 | slot representation. | ||
| 7 | |||
| 8 | * automated/eieio-test-persist.el (persist-test-save-and-compare): | ||
| 9 | Adjust to new slot representation. | ||
| 10 | |||
| 11 | * automated/eieio-test-methodinvoke.el (make-instance): Use new-style | ||
| 12 | `subclass' specializer for a change. | ||
| 13 | |||
| 1 | 2015-03-17 Stefan Monnier <monnier@iro.umontreal.ca> | 14 | 2015-03-17 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 15 | ||
| 3 | * automated/cl-lib-tests.el: Use lexical-binding. | 16 | * automated/cl-lib-tests.el: Use lexical-binding. |
diff --git a/test/automated/eieio-test-methodinvoke.el b/test/automated/eieio-test-methodinvoke.el index 62f5603d3b6..5263013434e 100644 --- a/test/automated/eieio-test-methodinvoke.el +++ b/test/automated/eieio-test-methodinvoke.el | |||
| @@ -184,7 +184,7 @@ | |||
| 184 | (if (next-method-p) (call-next-method)) | 184 | (if (next-method-p) (call-next-method)) |
| 185 | ) | 185 | ) |
| 186 | 186 | ||
| 187 | (defmethod make-instance :STATIC ((p C) &rest args) | 187 | (cl-defmethod make-instance ((p (subclass C)) &rest args) |
| 188 | (eieio-test-method-store :STATIC 'C) | 188 | (eieio-test-method-store :STATIC 'C) |
| 189 | (call-next-method) | 189 | (call-next-method) |
| 190 | ) | 190 | ) |
diff --git a/test/automated/eieio-test-persist.el b/test/automated/eieio-test-persist.el index 7bb2f1ca779..6710ead2e77 100644 --- a/test/automated/eieio-test-persist.el +++ b/test/automated/eieio-test-persist.el | |||
| @@ -45,20 +45,20 @@ This is usually a symbol that starts with `:'." | |||
| 45 | 45 | ||
| 46 | (eieio-persistent-save original) | 46 | (eieio-persistent-save original) |
| 47 | 47 | ||
| 48 | (let* ((file (oref original :file)) | 48 | (let* ((file (oref original file)) |
| 49 | (class (eieio-object-class original)) | 49 | (class (eieio-object-class original)) |
| 50 | (fromdisk (eieio-persistent-read file class)) | 50 | (fromdisk (eieio-persistent-read file class)) |
| 51 | (cv (eieio--class-v class)) | 51 | (cv (eieio--class-v class)) |
| 52 | (slot-names (eieio--class-public-a cv)) | 52 | (slots (eieio--class-slots cv)) |
| 53 | (slot-deflt (eieio--class-public-d cv)) | ||
| 54 | ) | 53 | ) |
| 55 | (unless (object-of-class-p fromdisk class) | 54 | (unless (object-of-class-p fromdisk class) |
| 56 | (error "Persistent class %S != original class %S" | 55 | (error "Persistent class %S != original class %S" |
| 57 | (eieio-object-class fromdisk) | 56 | (eieio-object-class fromdisk) |
| 58 | class)) | 57 | class)) |
| 59 | 58 | ||
| 60 | (while slot-names | 59 | (dotimes (i (length slots)) |
| 61 | (let* ((oneslot (car slot-names)) | 60 | (let* ((slot (aref slots i)) |
| 61 | (oneslot (cl--slot-descriptor-name slot)) | ||
| 62 | (origvalue (eieio-oref original oneslot)) | 62 | (origvalue (eieio-oref original oneslot)) |
| 63 | (fromdiskvalue (eieio-oref fromdisk oneslot)) | 63 | (fromdiskvalue (eieio-oref fromdisk oneslot)) |
| 64 | (initarg-p (eieio--attribute-to-initarg | 64 | (initarg-p (eieio--attribute-to-initarg |
| @@ -70,12 +70,9 @@ This is usually a symbol that starts with `:'." | |||
| 70 | (error "Slot %S Original Val %S != Persistent Val %S" | 70 | (error "Slot %S Original Val %S != Persistent Val %S" |
| 71 | oneslot origvalue fromdiskvalue)) | 71 | oneslot origvalue fromdiskvalue)) |
| 72 | ;; Else !initarg-p | 72 | ;; Else !initarg-p |
| 73 | (unless (equal (car slot-deflt) fromdiskvalue) | 73 | (unless (equal (cl--slot-descriptor-initform slot) fromdiskvalue) |
| 74 | (error "Slot %S Persistent Val %S != Default Value %S" | 74 | (error "Slot %S Persistent Val %S != Default Value %S" |
| 75 | oneslot fromdiskvalue (car slot-deflt)))) | 75 | oneslot fromdiskvalue (cl--slot-descriptor-initform slot)))) |
| 76 | |||
| 77 | (setq slot-names (cdr slot-names) | ||
| 78 | slot-deflt (cdr slot-deflt)) | ||
| 79 | )))) | 76 | )))) |
| 80 | 77 | ||
| 81 | ;;; Simple Case | 78 | ;;; Simple Case |
diff --git a/test/automated/eieio-tests.el b/test/automated/eieio-tests.el index 7532609c4c3..01131d886dd 100644 --- a/test/automated/eieio-tests.el +++ b/test/automated/eieio-tests.el | |||
| @@ -406,21 +406,21 @@ METHOD is the method that was attempting to be called." | |||
| 406 | (ert-deftest eieio-test-17-virtual-slot () | 406 | (ert-deftest eieio-test-17-virtual-slot () |
| 407 | (setq eitest-vsca (virtual-slot-class :base-value 1)) | 407 | (setq eitest-vsca (virtual-slot-class :base-value 1)) |
| 408 | ;; Check slot values | 408 | ;; Check slot values |
| 409 | (should (= (oref eitest-vsca :base-value) 1)) | 409 | (should (= (oref eitest-vsca base-value) 1)) |
| 410 | (should (= (oref eitest-vsca :derived-value) 2)) | 410 | (should (= (oref eitest-vsca :derived-value) 2)) |
| 411 | 411 | ||
| 412 | (oset eitest-vsca :derived-value 3) | 412 | (oset eitest-vsca derived-value 3) |
| 413 | (should (= (oref eitest-vsca :base-value) 2)) | 413 | (should (= (oref eitest-vsca base-value) 2)) |
| 414 | (should (= (oref eitest-vsca :derived-value) 3)) | 414 | (should (= (oref eitest-vsca :derived-value) 3)) |
| 415 | 415 | ||
| 416 | (oset eitest-vsca :base-value 3) | 416 | (oset eitest-vsca base-value 3) |
| 417 | (should (= (oref eitest-vsca :base-value) 3)) | 417 | (should (= (oref eitest-vsca base-value) 3)) |
| 418 | (should (= (oref eitest-vsca :derived-value) 4)) | 418 | (should (= (oref eitest-vsca :derived-value) 4)) |
| 419 | 419 | ||
| 420 | ;; should also be possible to initialize instance using virtual slot | 420 | ;; should also be possible to initialize instance using virtual slot |
| 421 | 421 | ||
| 422 | (setq eitest-vscb (virtual-slot-class :derived-value 5)) | 422 | (setq eitest-vscb (virtual-slot-class :derived-value 5)) |
| 423 | (should (= (oref eitest-vscb :base-value) 4)) | 423 | (should (= (oref eitest-vscb base-value) 4)) |
| 424 | (should (= (oref eitest-vscb :derived-value) 5))) | 424 | (should (= (oref eitest-vscb :derived-value) 5))) |
| 425 | 425 | ||
| 426 | (ert-deftest eieio-test-18-slot-unbound () | 426 | (ert-deftest eieio-test-18-slot-unbound () |
| @@ -560,7 +560,8 @@ METHOD is the method that was attempting to be called." | |||
| 560 | (setq eitest-t1 (class-c)) | 560 | (setq eitest-t1 (class-c)) |
| 561 | ;; Slot initialization | 561 | ;; Slot initialization |
| 562 | (should (eq (oref eitest-t1 slot-1) 'moose)) | 562 | (should (eq (oref eitest-t1 slot-1) 'moose)) |
| 563 | (should (eq (oref eitest-t1 :moose) 'moose)) | 563 | ;; Accessing via the initarg name is deprecated! |
| 564 | ;; (should (eq (oref eitest-t1 :moose) 'moose)) | ||
| 564 | ;; Don't pass reference of private slot | 565 | ;; Don't pass reference of private slot |
| 565 | ;;PRIVATE (should-error (oref eitest-t1 slot-2) :type 'invalid-slot-name) | 566 | ;;PRIVATE (should-error (oref eitest-t1 slot-2) :type 'invalid-slot-name) |
| 566 | ;; Check private slot accessor | 567 | ;; Check private slot accessor |
| @@ -580,7 +581,8 @@ METHOD is the method that was attempting to be called." | |||
| 580 | ;; See previous test, nor for subclass | 581 | ;; See previous test, nor for subclass |
| 581 | (setq eitest-t2 (class-subc)) | 582 | (setq eitest-t2 (class-subc)) |
| 582 | (should (eq (oref eitest-t2 slot-1) 'moose)) | 583 | (should (eq (oref eitest-t2 slot-1) 'moose)) |
| 583 | (should (eq (oref eitest-t2 :moose) 'moose)) | 584 | ;; Accessing via the initarg name is deprecated! |
| 585 | ;;(should (eq (oref eitest-t2 :moose) 'moose)) | ||
| 584 | (should (string= (get-slot-2 eitest-t2) "linux")) | 586 | (should (string= (get-slot-2 eitest-t2) "linux")) |
| 585 | ;;PRIVATE (should-error (oref eitest-t2 slot-2) :type 'invalid-slot-name) | 587 | ;;PRIVATE (should-error (oref eitest-t2 slot-2) :type 'invalid-slot-name) |
| 586 | (should (string= (get-slot-2 eitest-t2) "linux")) | 588 | (should (string= (get-slot-2 eitest-t2) "linux")) |
| @@ -802,30 +804,24 @@ Subclasses to override slot attributes.") | |||
| 802 | 804 | ||
| 803 | (ert-deftest eieio-test-32-slot-attribute-override-2 () | 805 | (ert-deftest eieio-test-32-slot-attribute-override-2 () |
| 804 | (let* ((cv (eieio--class-v 'slotattr-ok)) | 806 | (let* ((cv (eieio--class-v 'slotattr-ok)) |
| 805 | (docs (eieio--class-public-doc cv)) | 807 | (slots (eieio--class-slots cv)) |
| 806 | (names (eieio--class-public-a cv)) | 808 | (args (eieio--class-initarg-tuples cv))) |
| 807 | (cust (eieio--class-public-custom cv)) | ||
| 808 | (label (eieio--class-public-custom-label cv)) | ||
| 809 | (group (eieio--class-public-custom-group cv)) | ||
| 810 | (types (eieio--class-public-type cv)) | ||
| 811 | (args (eieio--class-initarg-tuples cv)) | ||
| 812 | (i 0)) | ||
| 813 | ;; :initarg should override for subclass | 809 | ;; :initarg should override for subclass |
| 814 | (should (assoc :initblarg args)) | 810 | (should (assoc :initblarg args)) |
| 815 | 811 | ||
| 816 | (while (< i (length names)) | 812 | (dotimes (i (length slots)) |
| 817 | (cond | 813 | (let* ((slot (aref slots i)) |
| 818 | ((eq (nth i names) 'custom) | 814 | (props (cl--slot-descriptor-props slot))) |
| 819 | ;; Custom slot attributes must override | 815 | (cond |
| 820 | (should (eq (nth i cust) 'string)) | 816 | ((eq (cl--slot-descriptor-name slot) 'custom) |
| 821 | ;; Custom label slot attribute must override | 817 | ;; Custom slot attributes must override |
| 822 | (should (string= (nth i label) "One String")) | 818 | (should (eq (alist-get :custom props) 'string)) |
| 823 | (let ((grp (nth i group))) | 819 | ;; Custom label slot attribute must override |
| 824 | ;; Custom group slot attribute must combine | 820 | (should (string= (alist-get :label props) "One String")) |
| 825 | (should (and (memq 'moose grp) (memq 'cow grp))))) | 821 | (let ((grp (alist-get :group props))) |
| 826 | (t nil)) | 822 | ;; Custom group slot attribute must combine |
| 827 | 823 | (should (and (memq 'moose grp) (memq 'cow grp))))) | |
| 828 | (setq i (1+ i))))) | 824 | (t nil)))))) |
| 829 | 825 | ||
| 830 | (defvar eitest-CLONETEST1 nil) | 826 | (defvar eitest-CLONETEST1 nil) |
| 831 | (defvar eitest-CLONETEST2 nil) | 827 | (defvar eitest-CLONETEST2 nil) |
| @@ -891,8 +887,7 @@ Subclasses to override slot attributes.") | |||
| 891 | (should (= (length (eieio-build-class-alist 'opt-test1 nil)) 2)) | 887 | (should (= (length (eieio-build-class-alist 'opt-test1 nil)) 2)) |
| 892 | (should (= (length (eieio-build-class-alist 'opt-test1 t)) 1))) | 888 | (should (= (length (eieio-build-class-alist 'opt-test1 t)) 1))) |
| 893 | 889 | ||
| 894 | (defclass eieio--testing () | 890 | (defclass eieio--testing () ()) |
| 895 | ()) | ||
| 896 | 891 | ||
| 897 | (defmethod constructor :static ((_x eieio--testing) newname &rest _args) | 892 | (defmethod constructor :static ((_x eieio--testing) newname &rest _args) |
| 898 | (list newname 2)) | 893 | (list newname 2)) |