]> code.delx.au - gnu-emacs-elpa/blob - ivy-test.el
Update Copyright
[gnu-emacs-elpa] / 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
24 (defvar ivy-expr nil
25 "Holds a test expression to evaluate with `ivy-eval'.")
26
27 (defvar ivy-result nil
28 "Holds the eval result of `ivy-expr' by `ivy-eval'.")
29
30 (defun ivy-eval ()
31 "Evaluate `ivy-expr'."
32 (interactive)
33 (setq ivy-result (eval ivy-expr)))
34
35 (global-set-key (kbd "C-c e") 'ivy-eval)
36
37 (defun ivy-with (expr keys)
38 "Evaluate EXPR followed by KEYS."
39 (let ((ivy-expr expr))
40 (execute-kbd-macro
41 (vconcat (kbd "C-c e")
42 (kbd keys)))
43 ivy-result))
44
45 (ert-deftest ivy-read ()
46 (should (equal
47 (ivy-read "pattern: " nil)
48 nil))
49 (should (equal
50 (ivy-read "pattern: " '("42"))
51 "42"))
52 (should (equal
53 (ivy-with '(ivy-read "pattern: " '("blue" "yellow"))
54 "C-m")
55 "blue"))
56 (should (equal
57 (ivy-with '(ivy-read "pattern: " '("blue" "yellow"))
58 "y C-m")
59 "yellow"))
60 (should (equal
61 (ivy-with '(ivy-read "pattern: " '("blue" "yellow"))
62 "y DEL b C-m")
63 "blue"))
64 (should (equal
65 (ivy-with '(ivy-read "pattern: " '("blue" "yellow"))
66 "z C-m")
67 nil)))