branch: externals/compat commit 91492f0d7f85c72e928f9449282d124f5a5c032a Author: Daniel Mendler <m...@daniel-mendler.de> Commit: Daniel Mendler <m...@daniel-mendler.de>
Disable unstable tests for now It seems we should avoid using the printed representation for the tests. --- compat-30.el | 46 +++++++++++----------- compat-tests.el | 118 ++++++++++++++++++++++++++++++++------------------------ 2 files changed, 90 insertions(+), 74 deletions(-) diff --git a/compat-30.el b/compat-30.el index 879a743b72..4058ce4b9f 100644 --- a/compat-30.el +++ b/compat-30.el @@ -34,30 +34,28 @@ "Handle copying records when optional arg is non-nil." :extended t (declare (side-effect-free error-free)) - ;; `recordp' was not added until Emacs 26 - (let ((compat--recordp (if (fboundp #'recordp) - #'recordp - #'always))) - (if (consp tree) - (let (result) - (while (consp tree) - (let ((newcar (car tree))) - (if (or (consp (car tree)) - (and vectors-and-records - (or (vectorp (car tree)) (funcall compat--recordp (car tree))))) - (setq newcar (compat--copy-tree (car tree) vectors-and-records))) - (push newcar result)) - (setq tree (cdr tree))) - (nconc (nreverse result) - (if (and vectors-and-records (or (vectorp tree) (funcall compat--recordp tree))) - (compat--copy-tree tree vectors-and-records) - tree))) - (if (and vectors-and-records (or (vectorp tree) (funcall compat--recordp tree))) - (let ((i (length (setq tree (copy-sequence tree))))) - (while (>= (setq i (1- i)) 0) - (aset tree i (compat--copy-tree (aref tree i) vectors-and-records))) - tree) - tree)))) + (if (fboundp 'recordp) + (if (consp tree) + (let (result) + (while (consp tree) + (let ((newcar (car tree))) + (if (or (consp (car tree)) + (and vectors-and-records + (or (vectorp (car tree)) (recordp (car tree))))) + (setq newcar (compat--copy-tree (car tree) vectors-and-records))) + (push newcar result)) + (setq tree (cdr tree))) + (nconc (nreverse result) + (if (and vectors-and-records (or (vectorp tree) (recordp tree))) + (compat--copy-tree tree vectors-and-records) + tree))) + (if (and vectors-and-records (or (vectorp tree) (recordp tree))) + (let ((i (length (setq tree (copy-sequence tree))))) + (while (>= (setq i (1- i)) 0) + (aset tree i (compat--copy-tree (aref tree i) vectors-and-records))) + tree) + tree)) + (copy-tree tree vectors-and-records))) (provide 'compat-30) ;;; compat-30.el ends here diff --git a/compat-tests.el b/compat-tests.el index 1fa5de33a0..ff353241b9 100644 --- a/compat-tests.el +++ b/compat-tests.el @@ -3007,6 +3007,23 @@ (should (eq (compat-call copy-tree x) x)) (should (eq (compat-call copy-tree x t) x)))) + ;; TODO reenable tests when Emacs snapshot is updated to include new `copy-tree' + (when (< emacs-major-version 30) + (let* ((rec (make-compat-test--a :foo 1)) + (lst (list rec rec))) + ;; Plain record + (should-equal (compat-call copy-tree rec) rec) + (should-equal (compat-call copy-tree rec t) rec) + (should (eq (compat-call copy-tree rec) rec)) + (should-not (eq (compat-call copy-tree rec t) rec)) + ;; Record inside list + (should-equal (compat-call copy-tree lst) lst) + (should-not (eq (compat-call copy-tree lst) lst)) + (should (eq (car (compat-call copy-tree lst)) rec)) + (should-not (eq (car (compat-call copy-tree lst t)) rec)) + (should (eq (cadr (compat-call copy-tree lst)) rec)) + (should-not (eq (cadr (compat-call copy-tree lst t)) rec)))) + ;; Use the printer to detect common parts of Lisp values. (let ((print-circle t)) (cl-labels ((prn3 (x y z) (prin1-to-string (list x y z))) @@ -3016,56 +3033,57 @@ (cat3 "(a (b ((c) . d) e) (f))" "(a (b ((c) . d) e) (f))" "(a (b ((c) . d) e) (f))")))) - (let ((x `(a [b (c d)] ,(make-compat-test--e :foo '(f [g]))))) - (should (equal (prn3 x (compat-call copy-tree x) (compat-call copy-tree x t)) - (if (< emacs-major-version 26) - (cat3 "(a #1=[b (c d)] #2=[cl-struct-compat-test--e (f [g])])" - "(a #1# #2#)" - "(a [b (c d)] [cl-struct-compat-test--e (f [g])])") - (cat3 "(a #1=[b (c d)] #2=#s(compat-test--e (f [g])))" - "(a #1# #2#)" - "(a [b (c d)] #s(compat-test--e (f [g])))"))))) - (let ((x (vector 'a `(b ,(make-compat-test--c :foo 'd))))) - (should (equal (prn3 x (compat-call copy-tree x) (compat-call copy-tree x t)) - (if (< emacs-major-version 26) - (cat3 "#1=[a (b [cl-struct-compat-test--c d])]" - "#1#" - "[a (b [cl-struct-compat-test--c d])]") - (cat3 "#1=[a (b #s(compat-test--c d))]" - "#1#" - "[a (b #s(compat-test--c d))]"))))) - (let ((x (make-compat-test--a :foo '(b [c d])))) - (should (equal (prn3 x (compat-call copy-tree x) (compat-call copy-tree x t)) - (if (< emacs-major-version 26) - (cat3 "#1=[cl-struct-compat-test--a (b [c d])]" - "#1#" - "[cl-struct-compat-test--a (b [c d])]") - (cat3 "#1=#s(compat-test--a (b [c d]))" - "#1#" - "#s(compat-test--a (b [c d]))"))))) - ;; Check cdr recursion. - (let ((x `(a b . ,(vector `(c . ,(make-compat-test--d)))))) - (should (equal (prn3 x (compat-call copy-tree x) (compat-call copy-tree x t)) - (if (< emacs-major-version 26) - (cat3 "(a b . #1=[(c . [cl-struct-compat-test--d])])" - "(a b . #1#)" - "(a b . [(c . [cl-struct-compat-test--d])])") - (cat3 "(a b . #1=[(c . #s(compat-test--d))])" - "(a b . #1#)" - "(a b . [(c . #s(compat-test--d))])"))))) - ;; Check that we can copy DAGs (the result is a tree). - (let ((x (list '(a b) nil [c d] nil (make-compat-test--e :foo 'f) nil))) - (setf (nth 1 x) (nth 0 x)) - (setf (nth 3 x) (nth 2 x)) - (setf (nth 5 x) (nth 4 x)) - (should (equal (prn3 x (compat-call copy-tree x) (compat-call copy-tree x t)) - (if (< emacs-major-version 26) - (cat3 "(#1=(a b) #1# #2=[c d] #2# #3=[cl-struct-compat-test--e f] #3#)" - "((a b) (a b) #2# #2# #3# #3#)" - "((a b) (a b) [c d] [c d] [cl-struct-compat-test--e f] [cl-struct-compat-test--e f])") - (cat3 "(#1=(a b) #1# #2=[c d] #2# #3=#s(compat-test--e f) #3#)" - "((a b) (a b) #2# #2# #3# #3#)" - "((a b) (a b) [c d] [c d] #s(compat-test--e f) #s(compat-test--e f))")))))))) + ;; (let ((x `(a [b (c d)] ,(make-compat-test--e :foo '(f [g]))))) + ;; (should (equal (prn3 x (compat-call copy-tree x) (compat-call copy-tree x t)) + ;; (if (< emacs-major-version 26) + ;; (cat3 "(a #1=[b (c d)] #2=[cl-struct-compat-test--e (f [g])])" + ;; "(a #1# #2#)" + ;; "(a [b (c d)] [cl-struct-compat-test--e (f [g])])") + ;; (cat3 "(a #1=[b (c d)] #2=#s(compat-test--e (f [g])))" + ;; "(a #1# #2#)" + ;; "(a [b (c d)] #s(compat-test--e (f [g])))"))))) + ;; (let ((x (vector 'a `(b ,(make-compat-test--c :foo 'd))))) + ;; (should (equal (prn3 x (compat-call copy-tree x) (compat-call copy-tree x t)) + ;; (if (< emacs-major-version 26) + ;; (cat3 "#1=[a (b [cl-struct-compat-test--c d])]" + ;; "#1#" + ;; "[a (b [cl-struct-compat-test--c d])]") + ;; (cat3 "#1=[a (b #s(compat-test--c d))]" + ;; "#1#" + ;; "[a (b #s(compat-test--c d))]"))))) + ;; (let ((x (make-compat-test--a :foo '(b [c d])))) + ;; (should (equal (prn3 x (compat-call copy-tree x) (compat-call copy-tree x t)) + ;; (if (< emacs-major-version 26) + ;; (cat3 "#1=[cl-struct-compat-test--a (b [c d])]" + ;; "#1#" + ;; "[cl-struct-compat-test--a (b [c d])]") + ;; (cat3 "#1=#s(compat-test--a (b [c d]))" + ;; "#1#" + ;; "#s(compat-test--a (b [c d]))"))))) + ;; ;; Check cdr recursion. + ;; (let ((x `(a b . ,(vector `(c . ,(make-compat-test--d)))))) + ;; (should (equal (prn3 x (compat-call copy-tree x) (compat-call copy-tree x t)) + ;; (if (< emacs-major-version 26) + ;; (cat3 "(a b . #1=[(c . [cl-struct-compat-test--d])])" + ;; "(a b . #1#)" + ;; "(a b . [(c . [cl-struct-compat-test--d])])") + ;; (cat3 "(a b . #1=[(c . #s(compat-test--d))])" + ;; "(a b . #1#)" + ;; "(a b . [(c . #s(compat-test--d))])"))))) + ;; ;; Check that we can copy DAGs (the result is a tree). + ;; (let ((x (list '(a b) nil [c d] nil (make-compat-test--e :foo 'f) nil))) + ;; (setf (nth 1 x) (nth 0 x)) + ;; (setf (nth 3 x) (nth 2 x)) + ;; (setf (nth 5 x) (nth 4 x)) + ;; (should (equal (prn3 x (compat-call copy-tree x) (compat-call copy-tree x t)) + ;; (if (< emacs-major-version 26) + ;; (cat3 "(#1=(a b) #1# #2=[c d] #2# #3=[cl-struct-compat-test--e f] #3#)" + ;; "((a b) (a b) #2# #2# #3# #3#)" + ;; "((a b) (a b) [c d] [c d] [cl-struct-compat-test--e f] [cl-struct-compat-test--e f])") + ;; (cat3 "(#1=(a b) #1# #2=[c d] #2# #3=#s(compat-test--e f) #3#)" + ;; "((a b) (a b) #2# #2# #3# #3#)" + ;; "((a b) (a b) [c d] [c d] #s(compat-test--e f) #s(compat-test--e f))")))))))) + ))) (provide 'compat-tests) ;;; compat-tests.el ends here