]> code.delx.au - gnu-emacs-elpa/commitdiff
Add a couple tests for ivy-read with alists
authorOleh Krehel <ohwoeowho@gmail.com>
Fri, 22 Apr 2016 08:39:08 +0000 (10:39 +0200)
committerOleh Krehel <ohwoeowho@gmail.com>
Fri, 22 Apr 2016 08:39:28 +0000 (10:39 +0200)
* 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

index 5e388d3dbf8fcf79e22300de749be2ffeaa8a450..40dae48286bb4254a290fc04585f31222ea8bd0e 100644 (file)
            (ivy-with '(ivy-read "test" '("aaab" "aaac"))
                      "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")