]> code.delx.au - gnu-emacs-elpa/blob - packages/swiper/ivy-test.el
Merge commit 'efa18eca10e5a0e05043f872cf9945842bb3a034' from swiper
[gnu-emacs-elpa] / packages / swiper / ivy-test.el
1 ;;; ivy-test.el --- tests for ivy
2
3 ;; Copyright (C) 2015 Free Software Foundation, Inc.
4
5 ;; Author: Oleh Krehel
6
7 ;; This file is part of GNU Emacs.
8
9 ;; This file is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 3, or (at your option)
12 ;; any later version.
13
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
18
19 ;; For a full copy of the GNU General Public License
20 ;; see <http://www.gnu.org/licenses/>.
21
22 (require 'ert)
23 (require 'ivy)
24
25 (defvar ivy-expr nil
26 "Holds a test expression to evaluate with `ivy-eval'.")
27
28 (defvar ivy-result nil
29 "Holds the eval result of `ivy-expr' by `ivy-eval'.")
30
31 (defun ivy-eval ()
32 "Evaluate `ivy-expr'."
33 (interactive)
34 (setq ivy-result (eval ivy-expr)))
35
36 (global-set-key (kbd "C-c e") 'ivy-eval)
37
38 (defun ivy-with (expr keys)
39 "Evaluate EXPR followed by KEYS."
40 (let ((ivy-expr expr))
41 (execute-kbd-macro
42 (vconcat (kbd "C-c e")
43 (kbd keys)))
44 ivy-result))
45
46 (ert-deftest ivy-read ()
47 (should (equal
48 (ivy-read "pattern: " nil)
49 nil))
50 (should (equal
51 (ivy-read "pattern: " '("42"))
52 "42"))
53 (should (equal
54 (ivy-with '(ivy-read "pattern: " '("blue" "yellow"))
55 "C-m")
56 "blue"))
57 (should (equal
58 (ivy-with '(ivy-read "pattern: " '("blue" "yellow"))
59 "y C-m")
60 "yellow"))
61 (should (equal
62 (ivy-with '(ivy-read "pattern: " '("blue" "yellow"))
63 "y DEL b C-m")
64 "blue"))
65 (should (equal
66 (ivy-with '(ivy-read "pattern: " '("blue" "yellow"))
67 "z C-m")
68 nil)))