branch: master
commit 63688c68872fff0b54e927b765d6a305998a6f91
Author: Oleh Krehel <ohwoeo...@gmail.com>
Commit: Oleh Krehel <ohwoeo...@gmail.com>

    Add a couple tests for ivy-read with alists
    
    * ivy-test.el (ivy-read): Add tests.
    
    To summarize how it works:
    
    1. Only the keys of the alist are offered for completion, not the values
    - this is the standard Emacs behavior.
    
    2. `ivy-read' will return the selected key, not the value or the cons
    cell.
    
    3. When :action is specified, it will be called with the value
    corresponding to the selected key. Not the key, and not the cons.
    
    This allows keys to work as aliases for the actual data, and :action
    arguments to be simple functions that deal with data (i.e. not having to
    deal with the `cdr' of the passed argument).
---
 ivy-test.el |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/ivy-test.el b/ivy-test.el
index 5e388d3..40dae48 100644
--- a/ivy-test.el
+++ b/ivy-test.el
@@ -79,6 +79,24 @@
                      "a C-n <tab> C-m")
            "aaac"))
   (should (equal
+           (ivy-with '(ivy-read "test" '(("foo" . "bar")))
+                     "asdf C-m")
+           "asdf"))
+  (should (equal
+           (ivy-with
+            '(with-output-to-string
+              (ivy-read "test" '(("foo" . "bar"))
+               :action (lambda (x) (prin1 x))))
+            "f C-m")
+           "\"bar\""))
+  (should (equal
+           (ivy-with
+            '(with-output-to-string
+              (ivy-read "test" '(("foo" . "bar"))
+               :action (lambda (x) (prin1 x))))
+            "asdf C-m")
+           "\"asdf\""))
+  (should (equal
            (ivy-with '(ivy-read "pattern: " '("can do" "can" "can't do"))
                      "can C-m")
            "can")))

Reply via email to