aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorStefan Monnier2023-11-12 11:37:38 -0500
committerStefan Monnier2023-11-12 11:37:38 -0500
commitb86dcea37c86a3b9cb9fc6c4656b481b2ad1c1e5 (patch)
treef970fa6143d822ad5031f1e4319325c76c31c23b /test
parentfbb897b7af53cdb43e18322c5cdfbfef7cdda1ee (diff)
downloademacs-b86dcea37c86a3b9cb9fc6c4656b481b2ad1c1e5.tar.gz
emacs-b86dcea37c86a3b9cb9fc6c4656b481b2ad1c1e5.zip
(derived-mode-all-parents): Fix handling of cycles
* lisp/subr.el (derived-mode-all-parents): Fix the handling of cycles so that it doesn't fill the cache with incorrect results. (merge-ordered-lists): Improve docstring. (provided-mode-derived-p): Swap the loops since `modes` is usually shorter than `ps`. * test/lisp/subr-tests.el (subr-tests--parent-mode): Simplify. (subr-tests--mode-A, subr-tests--mode-B, subr-tests--mode-C): New funs. (subt-tests--derived-mode-add-parents): New test.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/subr-tests.el26
1 files changed, 24 insertions, 2 deletions
diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el
index db327056533..03eb0d5bf8c 100644
--- a/test/lisp/subr-tests.el
+++ b/test/lisp/subr-tests.el
@@ -345,8 +345,7 @@
345 345
346;;;; Mode hooks. 346;;;; Mode hooks.
347 347
348(defalias 'subr-tests--parent-mode 348(defalias 'subr-tests--parent-mode #'prog-mode)
349 (if (fboundp 'prog-mode) 'prog-mode 'fundamental-mode))
350 349
351(define-derived-mode subr-tests--derived-mode-1 prog-mode "test") 350(define-derived-mode subr-tests--derived-mode-1 prog-mode "test")
352(define-derived-mode subr-tests--derived-mode-2 subr-tests--parent-mode "test") 351(define-derived-mode subr-tests--derived-mode-2 subr-tests--parent-mode "test")
@@ -360,6 +359,29 @@
360 'subr-tests--parent-mode)) 359 'subr-tests--parent-mode))
361 (should (provided-mode-derived-p 'subr-tests--derived-mode-2 'prog-mode))) 360 (should (provided-mode-derived-p 'subr-tests--derived-mode-2 'prog-mode)))
362 361
362
363(define-derived-mode subr-tests--mode-A subr-tests--derived-mode-1 "t")
364(define-derived-mode subr-tests--mode-B subr-tests--mode-A "t")
365(defalias 'subr-tests--mode-C #'subr-tests--mode-B)
366(derived-mode-add-parents 'subr-tests--mode-A '(subr-tests--mode-C))
367
368(ert-deftest subt-tests--derived-mode-add-parents ()
369 ;; The Right Answer is somewhat unclear in the presence of cycles,
370 ;; but let's make sure we get tolerable answers.
371 ;; FIXME: Currently `prog-mode' doesn't always end up at the end :-(
372 (let ((set-equal (lambda (a b)
373 (not (or (cl-set-difference a b)
374 (cl-set-difference b a))))))
375 (dolist (mode '(subr-tests--mode-A subr-tests--mode-B subr-tests--mode-C))
376 (should (eq (derived-mode-all-parents mode)
377 (derived-mode-all-parents mode)))
378 (should (eq mode (car (derived-mode-all-parents mode))))
379 (should (funcall set-equal
380 (derived-mode-all-parents mode)
381 '(subr-tests--mode-A subr-tests--mode-B prog-mode
382 subr-tests--mode-C subr-tests--derived-mode-1))))))
383
384
363(ert-deftest number-sequence-test () 385(ert-deftest number-sequence-test ()
364 (should (= (length 386 (should (= (length
365 (number-sequence (1- most-positive-fixnum) most-positive-fixnum)) 387 (number-sequence (1- most-positive-fixnum) most-positive-fixnum))