From 63688c68872fff0b54e927b765d6a305998a6f91 Mon Sep 17 00:00:00 2001 From: Oleh Krehel Date: Fri, 22 Apr 2016 10:39:08 +0200 Subject: [PATCH] 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 5e388d3db..40dae4828 100644 --- a/ivy-test.el +++ b/ivy-test.el @@ -78,6 +78,24 @@ (ivy-with '(ivy-read "test" '("aaab" "aaac")) "a C-n 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") -- 2.39.2