1 ;;; ivy-test.el --- tests for ivy
3 ;; Copyright (C) 2015 Free Software Foundation, Inc.
7 ;; This file is part of GNU Emacs.
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)
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.
19 ;; For a full copy of the GNU General Public License
20 ;; see <http://www.gnu.org/licenses/>.
27 "Holds a test expression to evaluate with `ivy-eval'.")
29 (defvar ivy-result nil
30 "Holds the eval result of `ivy-expr' by `ivy-eval'.")
33 "Evaluate `ivy-expr'."
35 (setq ivy-result (eval ivy-expr)))
37 (global-set-key (kbd "C-c e") 'ivy-eval)
39 (defun ivy-with (expr keys)
40 "Evaluate EXPR followed by KEYS."
41 (let ((ivy-expr expr))
43 (vconcat (kbd "C-c e")
47 (ert-deftest ivy-read ()
49 (ivy-with '(ivy-read "pattern: " '("blue" "yellow"))
53 (ivy-with '(ivy-read "pattern: " '("blue" "yellow"))
57 (ivy-with '(ivy-read "pattern: " '("blue" "yellow"))
61 (ivy-with '(ivy-read "pattern: " '("blue" "yellow"))
65 (ivy-with '(ivy-read "pattern: " '("blue" "yellow"))
69 (ivy-with '(let ((ivy-re-builders-alist '((t . ivy--regex-fuzzy))))
70 (ivy-read "pattern: " '("package-list-packages" "something-else")))
72 "package-list-packages"))
74 (ivy-with '(ivy-read "test" '("aaab" "aaac"))
78 (ivy-with '(ivy-read "pattern: " '("can do" "can" "can't do"))
82 (ert-deftest swiper--re-builder ()
83 (setq swiper--width 4)
84 (should (string= (swiper--re-builder "^")
86 (should (string= (swiper--re-builder "^a")
88 (should (string= (swiper--re-builder "^a b")
89 "^ \\(a\\).*?\\(b\\)")))
91 (ert-deftest ivy--split ()
92 (should (equal (ivy--split "King of the who?")
93 '("King" "of" "the" "who?")))
94 (should (equal (ivy--split "The Brittons.")
96 (should (equal (ivy--split "Who are the Brittons?")
97 '("Who are" "the Brittons?")))
98 (should (equal (ivy--split "We're all Britons and I am your king.")
103 (ert-deftest ivy--regex ()
104 (should (equal (ivy--regex
105 "\\(?:interactive\\|swiper\\) \\(?:list\\|symbol\\)")
106 "\\(\\(?:interactive\\|swiper\\)\\).*?\\(\\(?:list\\|symbol\\)\\)")))
108 (ert-deftest ivy--regex-fuzzy ()
109 (should (string= (ivy--regex-fuzzy "tmux")
110 "\\(t\\).*\\(m\\).*\\(u\\).*\\(x\\)"))
111 (should (string= (ivy--regex-fuzzy "^tmux")
112 "^\\(t\\).*\\(m\\).*\\(u\\).*\\(x\\)"))
113 (should (string= (ivy--regex-fuzzy "^tmux$")
114 "^\\(t\\).*\\(m\\).*\\(u\\).*\\(x\\)$"))
115 (should (string= (ivy--regex-fuzzy "")
117 (should (string= (ivy--regex-fuzzy "^")
119 (should (string= (ivy--regex-fuzzy "$")
122 (ert-deftest ivy--regex-ignore-order ()
123 (should (equal (ivy--regex-ignore-order "tmux")
125 (should (equal (ivy--regex-ignore-order "^tmux")
127 (should (equal (ivy--regex-ignore-order "^tmux$")
129 (should (equal (ivy--regex-ignore-order "")
131 (should (equal (ivy--regex-ignore-order "^")
133 (should (equal (ivy--regex-ignore-order "$")
135 (should (equal (ivy--regex-ignore-order "one two")
136 '(("one" . t) ("two" . t))))
137 (should (equal (ivy--regex-ignore-order "one two !three")
138 '(("one" . t) ("two" . t) ("three"))))
139 (should (equal (ivy--regex-ignore-order "one two !three four")
140 '(("one" . t) ("two" . t) ("three") ("four"))))
141 (should (equal (ivy--regex-ignore-order "!three four")
142 '(("" . t) (("three") ("four"))))))
144 (ert-deftest ivy--format ()
145 (should (string= (let ((ivy--index 10)
146 (ivy-format-function (lambda (x) (mapconcat #'identity x "\n")))
159 #("\nDESCRIPTION\nFUNCTION LETTERS\nSWITCHES\nDIAGNOSTICS\nEXAMPLE 1\nEXAMPLE 2\nEXAMPLE 3\nSEE ALSO\nAUTHOR"
161 90 96 (face ivy-current-match read-only nil)))))
163 (ert-deftest ivy--filter ()
164 (setq ivy-last (make-ivy-state))
165 (should (equal (ivy--filter "the" '("foo" "the" "The"))
167 (should (equal (ivy--filter "The" '("foo" "the" "The"))
170 (ert-deftest counsel-unquote-regex-parens ()
171 (should (equal (counsel-unquote-regex-parens
172 (ivy--regex "foo bar"))