aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorStefan Monnier2018-12-17 14:51:01 -0500
committerStefan Monnier2018-12-17 14:51:01 -0500
commit55838e4e6a176317367c6759e0520395e80c856f (patch)
tree49f0293f48e1084e076a936e8b3476f35efe7cf5 /test
parent2c3f7f9c45985c36fd9e86c334b49b10e8c8c270 (diff)
downloademacs-55838e4e6a176317367c6759e0520395e80c856f.tar.gz
emacs-55838e4e6a176317367c6759e0520395e80c856f.zip
* lisp/emacs-lisp/map.el: Avoid special casing lists.
(map-not-inplace, map-inplace): New errors. (map-insert): New generic function. (map-put!): Signal map-not-inplace rather than a generic 'error'. (map-elt): Use map-not-inplace and map-insert to avoid hardcoding a special case for lists. * test/lisp/emacs-lisp/map-tests.el (test-map-put!): Rename from test-map-put. Also test the errors signaled.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/emacs-lisp/map-tests.el20
1 files changed, 16 insertions, 4 deletions
diff --git a/test/lisp/emacs-lisp/map-tests.el b/test/lisp/emacs-lisp/map-tests.el
index 885b09be985..4dd67d48d40 100644
--- a/test/lisp/emacs-lisp/map-tests.el
+++ b/test/lisp/emacs-lisp/map-tests.el
@@ -76,13 +76,25 @@ Evaluate BODY for each created map.
76 'b 76 'b
77 '2)))) 77 '2))))
78 78
79(ert-deftest test-map-put () 79(ert-deftest test-map-put! ()
80 (with-maps-do map 80 (with-maps-do map
81 (setf (map-elt map 2) 'hello) 81 (setf (map-elt map 2) 'hello)
82 (should (eq (map-elt map 2) 'hello))) 82 (should (eq (map-elt map 2) 'hello)))
83 (with-maps-do map 83 (with-maps-do map
84 (map-put map 2 'hello) 84 (map-put map 2 'hello)
85 (should (eq (map-elt map 2) 'hello))) 85 (should (eq (map-elt map 2) 'hello)))
86 (with-maps-do map
87 (map-put! map 2 'hello)
88 (should (eq (map-elt map 2) 'hello))
89 (if (not (hash-table-p map))
90 (should-error (map-put! map 5 'value)
91 ;; For vectors, it could arguably signal
92 ;; map-not-inplace as well, but it currently doesn't.
93 :type (if (listp map)
94 'map-not-inplace
95 'error))
96 (map-put! map 5 'value)
97 (should (eq (map-elt map 5) 'value))))
86 (let ((ht (make-hash-table))) 98 (let ((ht (make-hash-table)))
87 (setf (map-elt ht 2) 'a) 99 (setf (map-elt ht 2) 'a)
88 (should (eq (map-elt ht 2) 100 (should (eq (map-elt ht 2)
@@ -92,7 +104,7 @@ Evaluate BODY for each created map.
92 (should (eq (map-elt alist 2) 104 (should (eq (map-elt alist 2)
93 'a))) 105 'a)))
94 (let ((vec [3 4 5])) 106 (let ((vec [3 4 5]))
95 (should-error (setf (map-elt vec 3) 6)))) 107 (should-error (setf (map-elt vec 3) 6))))
96 108
97(ert-deftest test-map-put-alist-new-key () 109(ert-deftest test-map-put-alist-new-key ()
98 "Regression test for Bug#23105." 110 "Regression test for Bug#23105."
@@ -105,9 +117,9 @@ Evaluate BODY for each created map.
105 (let ((alist (list (cons "a" 1) (cons "b" 2))) 117 (let ((alist (list (cons "a" 1) (cons "b" 2)))
106 ;; Make sure to use a non-eq "a", even when compiled. 118 ;; Make sure to use a non-eq "a", even when compiled.
107 (noneq-key (string ?a))) 119 (noneq-key (string ?a)))
108 (map-put alist noneq-key 3 'equal) 120 (map-put alist noneq-key 3 #'equal)
109 (should-not (cddr alist)) 121 (should-not (cddr alist))
110 (map-put alist noneq-key 9) 122 (map-put alist noneq-key 9 #'eql)
111 (should (cddr alist)))) 123 (should (cddr alist))))
112 124
113(ert-deftest test-map-put-return-value () 125(ert-deftest test-map-put-return-value ()