alist-get: Add optional arg TESTFN

If TESTFN is non-nil, then it is the predicate to lookup
the alist.  Otherwise, use 'eq' (Bug#27584).
* lisp/subr.el (alist-get): Add optional arg FULL.
* lisp/emacs-lisp/map.el (map-elt, map-put): Add optional arg TESTFN.
* lisp/emacs-lisp/gv.el (alist-get): Update expander.
* doc/lispref/lists.texi (Association Lists): Update manual.
* etc/NEWS: Announce the changes.
* test/lisp/emacs-lisp/map-tests.el (test-map-put-testfn-alist)
(test-map-elt-testfn): New tests.
This commit is contained in:
Tino Calancha 2017-07-17 21:30:50 +09:00
parent 4968aa685b
commit 76e1f7d00f
6 changed files with 51 additions and 22 deletions

View file

@ -63,6 +63,11 @@ Evaluate BODY for each created map.
(with-maps-do map
(should (= 5 (map-elt map 7 5)))))
(ert-deftest test-map-elt-testfn ()
(let ((map (list (cons "a" 1) (cons "b" 2))))
(should-not (map-elt map "a"))
(should (map-elt map "a" nil 'equal))))
(ert-deftest test-map-elt-with-nil-value ()
(should (null (map-elt '((a . 1)
(b))
@ -94,6 +99,13 @@ Evaluate BODY for each created map.
(should (eq (map-elt alist 2)
'b))))
(ert-deftest test-map-put-testfn-alist ()
(let ((alist (list (cons "a" 1) (cons "b" 2))))
(map-put alist "a" 3 'equal)
(should-not (cddr alist))
(map-put alist "a" 9)
(should (cddr alist))))
(ert-deftest test-map-put-return-value ()
(let ((ht (make-hash-table)))
(should (eq (map-put ht 'a 'hello) 'hello))))