From 4e8b50ec57bc0d70bdb1279756eec679eb4eab0d Mon Sep 17 00:00:00 2001 From: Alan Mackenzie Date: Tue, 7 Mar 2023 17:38:20 +0000 Subject: [PATCH] * test/lisp/subr-tests.el (subr--safe-copy-tree): New tests for safe-copy-tree --- test/lisp/subr-tests.el | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el index 050ee22ac18..37fe09c1716 100644 --- a/test/lisp/subr-tests.el +++ b/test/lisp/subr-tests.el @@ -1205,5 +1205,31 @@ final or penultimate step during initialization.")) (should (equal a-dedup '("a" "b" "a" "b" "c"))) (should (eq a a-dedup)))) +(ert-deftest subr--safe-copy-tree () + (should (null (safe-copy-tree nil))) + (let* ((foo '(1 2 (3 4))) (bar (safe-copy-tree foo))) + (should (equal bar foo)) + (should-not (eq bar foo)) + (should-not (eq (caddr bar) (caddr foo)))) + (let* ((foo '#1=(a #1#)) (bar (safe-copy-tree foo))) + (should (eq (car bar) (car foo))) +; (should-not (proper-list-p bar)) + (should (eq (caadr bar) (caadr foo))) + (should (eq (caadr bar) 'a))) + (let* ((foo [1 2 3 4]) (bar (safe-copy-tree foo))) + (should (eq bar foo))) + (let* ((foo [1 (2 3) 4]) (bar (safe-copy-tree foo t))) + (should-not (eq bar foo)) + (should (equal bar foo)) + (should-not (eq (aref bar 1) (aref foo 1)))) + (let* ((foo [1 [2 3] 4]) (bar (safe-copy-tree foo t))) + (should (equal bar foo)) + (should-not (eq bar foo)) + (should-not (eq (aref bar 1) (aref foo 1)))) + (let* ((foo (record 'foo 1 "two" 3)) (bar (safe-copy-tree foo t))) + (should (equal bar foo)) + (should-not (eq bar foo)) + (should (eq (aref bar 2) (aref foo 2))))) + (provide 'subr-tests) ;;; subr-tests.el ends here -- 2.39.2