diff options
author | Nic Ferrier <nic@ferrier.me.uk> | 2013-01-01 16:06:44 -0800 |
---|---|---|
committer | Nic Ferrier <nic@ferrier.me.uk> | 2013-01-01 16:06:44 -0800 |
commit | 608de1e608ba6f1a77d3ffff93dc0fea0fad3fea (patch) | |
tree | edafb3f5a1a7a3b1d22f4a3d909b0c083ff494a5 | |
parent | 67606a0f2df369ec935733895c845190e94b32fd (diff) | |
parent | ea74f5bfb6817b2b4e76a8ebb137ba57d27bdcad (diff) |
Merge pull request #2 from spacebat/master
Removed recursion and a few tweaks
-rw-r--r-- | kv-tests.el | 25 | ||||
-rw-r--r-- | kv.el | 10 |
2 files changed, 29 insertions, 6 deletions
diff --git a/kv-tests.el b/kv-tests.el index c910d2a..4a4823f 100644 --- a/kv-tests.el +++ b/kv-tests.el @@ -141,12 +141,35 @@ (dotassq 'a.b.c '((a . ((b . ((c . 10))))))) 10))) +(ert-deftest keyword->symbol () + "Convert keyword into a symbol without the leading `:'" + (should + (eq + 'key + (keyword->symbol :key))) + (should + (eq + 'key + (keyword->symbol 'key))) + (let ((sym (gensym))) + (should + (eq + sym + (keyword->symbol sym))))) + (ert-deftest kvalist->plist () "Make alists into plists." (should (equal '(:a1 value1 :a2 value2) - (kvalist->plist '((a1 . value1)(a2 . value2)))))) + (kvalist->plist '((a1 . value1) (a2 . value2)))))) + +(ert-deftest kvplist->alist () + "Make plists into alists." + (should + (equal + '((a1 . value1) (a2 . value2)) + (kvplist->alist '(:a1 value1 :a2 value2))))) (ert-deftest kvplist->filter-keys () (should @@ -168,18 +168,18 @@ expression is true." "A keyword is a symbol leading with a :. Converting to a symbol means dropping the :." - (intern (substring (symbol-name keyword) 1))) + (if (keywordp keyword) + (intern (substring (symbol-name keyword) 1)) + keyword)) (defun kvplist->alist (plist) "Convert PLIST to an alist. The keys are expected to be :prefixed and the colons are removed. The keys in the resulting alist are symbols." - ;; RECURSION KLAXON (when plist - (destructuring-bind (key value &rest plist) plist - (cons `(,(keyword->symbol key) . ,value) - (kvplist->alist plist))))) + (loop for (key value . rest) on plist by 'cddr + collect (cons (keyword->symbol key) value)))) (defun kvalist2->plist (alist2) "Convert a list of alists too a list of plists." |