aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorArtur Malabarba2014-12-19 18:25:06 -0200
committerArtur Malabarba2014-12-19 18:30:26 -0200
commitf447d33fdb082ce8e5d336be6034df24339b4c45 (patch)
tree7ad100c335eb0e84024c0aab266f674e2078ff47 /test
parent948fa912de164a1374c87e9206cddca741b7fa33 (diff)
downloademacs-f447d33fdb082ce8e5d336be6034df24339b4c45.tar.gz
emacs-f447d33fdb082ce8e5d336be6034df24339b4c45.zip
* let-alist.el (let-alist): Enable access to deeper alists
Acces them by using extra dots inside the dotted symbols.
Diffstat (limited to 'test')
-rw-r--r--test/ChangeLog1
-rw-r--r--test/automated/let-alist.el26
2 files changed, 26 insertions, 1 deletions
diff --git a/test/ChangeLog b/test/ChangeLog
index 80d2a40bc4c..7d23b3efe1c 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,6 +1,7 @@
12014-12-19 Artur Malabarba <bruce.connor.am@gmail.com> 12014-12-19 Artur Malabarba <bruce.connor.am@gmail.com>
2 2
3 * automated/let-alist.el: require `cl-lib' 3 * automated/let-alist.el: require `cl-lib'
4 New tests for accessing alists inside alists.
4 5
52014-12-18 Artur Malabarba <bruce.connor.am@gmail.com> 62014-12-18 Artur Malabarba <bruce.connor.am@gmail.com>
6 7
diff --git a/test/automated/let-alist.el b/test/automated/let-alist.el
index a700a4773ff..391ccb44a8d 100644
--- a/test/automated/let-alist.el
+++ b/test/automated/let-alist.el
@@ -33,7 +33,19 @@
33 (cl-letf (((symbol-function #'gensym) (lambda (x) 'symbol))) 33 (cl-letf (((symbol-function #'gensym) (lambda (x) 'symbol)))
34 (macroexpand 34 (macroexpand
35 '(let-alist data (list .test-one .test-two 35 '(let-alist data (list .test-one .test-two
36 .test-two .test-two))))))) 36 .test-two .test-two))))))
37 (should
38 (equal
39 (let ((.external "ext")
40 (.external.too "et"))
41 (let-alist '((test-two . 0)
42 (test-three . 1)
43 (sublist . ((foo . 2)
44 (bar . 3))))
45 (list .test-one .test-two .test-three
46 .sublist.foo .sublist.bar
47 ..external ..external.too)))
48 (list nil 0 1 2 3 "ext" "et"))))
37 49
38(defvar let-alist--test-counter 0 50(defvar let-alist--test-counter 0
39 "Used to count number of times a function is called.") 51 "Used to count number of times a function is called.")
@@ -49,5 +61,17 @@
49 (list .test-one .test-two .test-two .test-three .cl-incf)) 61 (list .test-one .test-two .test-two .test-three .cl-incf))
50 '(nil 1 1 2 nil))))) 62 '(nil 1 1 2 nil)))))
51 63
64(ert-deftest let-alist-remove-dot ()
65 "Remove firt dot from symbol."
66 (should (equal (let-alist--remove-dot 'hi) 'hi))
67 (should (equal (let-alist--remove-dot '.hi) 'hi))
68 (should (equal (let-alist--remove-dot '..hi) '.hi)))
69
70(ert-deftest let-alist-list-to-sexp ()
71 "Check that multiple dots are handled correctly."
72 (should (= 1 (eval (let-alist--list-to-sexp '(a b c d) ''((d (c (b (a . 1)))))))))
73 (should (equal (let-alist--access-sexp '.foo.bar.baz 'var)
74 '(cdr (assq 'baz (cdr (assq 'bar (cdr (assq 'foo var))))))))
75 (should (equal (let-alist--access-sexp '..foo.bar.baz 'var) '.foo.bar.baz)))
52 76
53;;; let-alist.el ends here 77;;; let-alist.el ends here