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-fuzzy ()
104 (should (string= (ivy--regex-fuzzy "tmux")
105 "\\(t\\).*\\(m\\).*\\(u\\).*\\(x\\)"))
106 (should (string= (ivy--regex-fuzzy "^tmux")
107 "^\\(t\\).*\\(m\\).*\\(u\\).*\\(x\\)"))
108 (should (string= (ivy--regex-fuzzy "^tmux$")
109 "^\\(t\\).*\\(m\\).*\\(u\\).*\\(x\\)$"))
110 (should (string= (ivy--regex-fuzzy "")
112 (should (string= (ivy--regex-fuzzy "^")
114 (should (string= (ivy--regex-fuzzy "$")
117 (ert-deftest ivy--regex-ignore-order ()
118 (should (equal (ivy--regex-ignore-order "tmux")
120 (should (equal (ivy--regex-ignore-order "^tmux")
122 (should (equal (ivy--regex-ignore-order "^tmux$")
124 (should (equal (ivy--regex-ignore-order "")
126 (should (equal (ivy--regex-ignore-order "^")
128 (should (equal (ivy--regex-ignore-order "$")
130 (should (equal (ivy--regex-ignore-order "one two")
131 '(("one" . t) ("two" . t))))
132 (should (equal (ivy--regex-ignore-order "one two !three")
133 '(("one" . t) ("two" . t) ("three"))))
134 (should (equal (ivy--regex-ignore-order "one two !three four")
135 '(("one" . t) ("two" . t) ("three") ("four"))))
136 (should (equal (ivy--regex-ignore-order "!three four")
137 '(("" . t) (("three") ("four"))))))
139 (ert-deftest ivy--format ()
140 (should (string= (let ((ivy--index 10)
141 (ivy-format-function (lambda (x) (mapconcat (lambda (y) (car y)) x "\n")))
154 #("\nDESCRIPTION\nFUNCTION LETTERS\nSWITCHES\nDIAGNOSTICS\nEXAMPLE 1\nEXAMPLE 2\nEXAMPLE 3\nSEE ALSO\nAUTHOR"
156 90 96 (face ivy-current-match read-only nil)))))
158 (ert-deftest ivy--filter ()
159 (setq ivy-last (make-ivy-state))
160 (should (equal (ivy--filter "the" '("foo" "the" "The"))
162 (should (equal (ivy--filter "The" '("foo" "the" "The"))
165 (ert-deftest counsel-unquote-regex-parens ()
166 (should (equal (counsel-unquote-regex-parens
167 (ivy--regex "foo bar"))