aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Petton2015-04-18 16:35:43 +0200
committerNicolas Petton2015-04-18 16:35:43 +0200
commit35c27cd5818bede77279dc7e5cf1beec93766baa (patch)
tree60311e38c60f099ddd963547336ac49f202c4db8
parentc3acb3258df5fc0987fdd233062632ed030923d9 (diff)
downloademacs-35c27cd5818bede77279dc7e5cf1beec93766baa.tar.gz
emacs-35c27cd5818bede77279dc7e5cf1beec93766baa.zip
Throw an error when converting a map into an unknown map type
* lisp/emacs-lisp/map.el (map-into): Throw an error if type is not valid. * test/automated/map-test.el: Add a regression test.
-rw-r--r--lisp/emacs-lisp/map.el3
-rw-r--r--test/automated/map-test.el3
2 files changed, 4 insertions, 2 deletions
diff --git a/lisp/emacs-lisp/map.el b/lisp/emacs-lisp/map.el
index fec06343f7c..7d839f822d2 100644
--- a/lisp/emacs-lisp/map.el
+++ b/lisp/emacs-lisp/map.el
@@ -193,7 +193,8 @@ MAP can be a list, hash-table or array."
193TYPE can be one of the following symbols: list or hash-table." 193TYPE can be one of the following symbols: list or hash-table."
194 (pcase type 194 (pcase type
195 (`list (map-pairs map)) 195 (`list (map-pairs map))
196 (`hash-table (map--into-hash-table map)))) 196 (`hash-table (map--into-hash-table map))
197 (t (error "Not a map type name: %s" type))))
197 198
198(defmacro map--dispatch (spec &rest args) 199(defmacro map--dispatch (spec &rest args)
199 "Evaluate one of the provided forms depending on the type of MAP. 200 "Evaluate one of the provided forms depending on the type of MAP.
diff --git a/test/automated/map-test.el b/test/automated/map-test.el
index 8a12be84aa1..ea7b0af3f46 100644
--- a/test/automated/map-test.el
+++ b/test/automated/map-test.el
@@ -318,7 +318,8 @@
318 (assert (equal (map-values (map-into (map-into ht 'list) 'hash-table)) 318 (assert (equal (map-values (map-into (map-into ht 'list) 'hash-table))
319 (map-values ht))) 319 (map-values ht)))
320 (assert (null (map-into nil 'list))) 320 (assert (null (map-into nil 'list)))
321 (assert (map-empty-p (map-into nil 'hash-table))))) 321 (assert (map-empty-p (map-into nil 'hash-table)))
322 (should-error (map-into [1 2 3] 'string))))
322 323
323(provide 'map-tests) 324(provide 'map-tests)
324;;; map-tests.el ends here 325;;; map-tests.el ends here