summaryrefslogtreecommitdiff
path: root/test/lisp/subr-tests.el
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2020-12-31 05:28:47 +0100
committerLars Ingebrigtsen <larsi@gnus.org>2020-12-31 05:28:47 +0100
commitb1ac23ebef62d5a185727a4973462828dc6f65f0 (patch)
tree453a984bdfccfd3217743630e2b7260b144d38d7 /test/lisp/subr-tests.el
parent3d9f20cfcf647063e62ba12187cf3b4bcd4d9685 (diff)
downloademacs-b1ac23ebef62d5a185727a4973462828dc6f65f0.tar.gz
emacs-b1ac23ebef62d5a185727a4973462828dc6f65f0.tar.bz2
emacs-b1ac23ebef62d5a185727a4973462828dc6f65f0.zip
Allow add-to-ordered-list to use a test predicate
* doc/lispref/lists.texi (List Variables): Update manual. * lisp/subr.el (add-to-ordered-list): Allow using a test predicate, and make slightly more efficient (bug#45539).
Diffstat (limited to 'test/lisp/subr-tests.el')
-rw-r--r--test/lisp/subr-tests.el28
1 files changed, 26 insertions, 2 deletions
diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el
index 3154135ce17..5be3b8915a2 100644
--- a/test/lisp/subr-tests.el
+++ b/test/lisp/subr-tests.el
@@ -600,7 +600,7 @@ See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=19350."
(defvar subr--ordered nil)
-(ert-deftest subr--add-to-ordered-list ()
+(ert-deftest subr--add-to-ordered-list-eq ()
(setq subr--ordered nil)
(add-to-ordered-list 'subr--ordered 'b 2)
(should (equal subr--ordered '(b)))
@@ -611,7 +611,31 @@ See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=19350."
(add-to-ordered-list 'subr--ordered 'e)
(should (equal subr--ordered '(a b c e)))
(add-to-ordered-list 'subr--ordered 'd 4)
- (should (equal subr--ordered '(a b c d e))))
+ (should (equal subr--ordered '(a b c d e)))
+ (add-to-ordered-list 'subr--ordered 'e)
+ (should (equal subr--ordered '(a b c d e)))
+ (add-to-ordered-list 'subr--ordered 'b 5)
+ (should (equal subr--ordered '(a c d b e))))
+
+(defvar subr--ordered-s nil)
+
+(ert-deftest subr--add-to-ordered-list-equal ()
+ (setq subr--ordered-s nil)
+ (add-to-ordered-list 'subr--ordered-s "b" 2 #'equal)
+ (should (equal subr--ordered-s '("b")))
+ (add-to-ordered-list 'subr--ordered-s "c" 3)
+ (should (equal subr--ordered-s '("b" "c")))
+ (add-to-ordered-list 'subr--ordered-s "a" 1)
+ (should (equal subr--ordered-s '("a" "b" "c")))
+ (add-to-ordered-list 'subr--ordered-s "e")
+ (should (equal subr--ordered-s '("a" "b" "c" "e")))
+ (add-to-ordered-list 'subr--ordered-s "d" 4)
+ (should (equal subr--ordered-s '("a" "b" "c" "d" "e")))
+ (add-to-ordered-list 'subr--ordered-s "e")
+ (should (equal subr--ordered-s '("a" "b" "c" "d" "e")))
+ (add-to-ordered-list 'subr--ordered-s "b" 5)
+ (should (equal subr--ordered-s '("a" "c" "d" "b" "e")))
+ (should-error (add-to-ordered-list 'subr--ordered-s "b" 5 #'eql)))
;;; Apropos.