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/>.
26 "Holds a test expression to evaluate with `ivy-eval'.")
28 (defvar ivy-result nil
29 "Holds the eval result of `ivy-expr' by `ivy-eval'.")
32 "Evaluate `ivy-expr'."
34 (setq ivy-result (eval ivy-expr)))
36 (global-set-key (kbd "C-c e") 'ivy-eval)
38 (defun ivy-with (expr keys)
39 "Evaluate EXPR followed by KEYS."
40 (let ((ivy-expr expr))
42 (vconcat (kbd "C-c e")
46 (ert-deftest ivy-read ()
48 (ivy-with '(ivy-read "pattern: " '("blue" "yellow"))
52 (ivy-with '(ivy-read "pattern: " '("blue" "yellow"))
56 (ivy-with '(ivy-read "pattern: " '("blue" "yellow"))
60 (ivy-with '(ivy-read "pattern: " '("blue" "yellow"))
64 (ert-deftest swiper--re-builder ()
65 (setq swiper--width 4)
66 (should (string= (swiper--re-builder "^")
68 (should (string= (swiper--re-builder "^a")
69 "^[0-9][0-9 ]\\{4\\}\\(a\\)"))
70 (should (string= (swiper--re-builder "^a b")
71 "^[0-9][0-9 ]\\{4\\}\\(a\\).*?\\(b\\)")))
73 (ert-deftest ivy--split ()
74 (should (equal (ivy--split "King of the who?")
75 '("King" "of" "the" "who?")))
76 (should (equal (ivy--split "The Brittons.")
78 (should (equal (ivy--split "Who are the Brittons?")
79 '("Who are" "the Brittons?")))
80 (should (equal (ivy--split "We're all Britons and I am your king.")
85 (ert-deftest ivy--regex-fuzzy ()
86 (should (string= (ivy--regex-fuzzy "tmux")
88 (should (string= (ivy--regex-fuzzy "^tmux")
90 (should (string= (ivy--regex-fuzzy "^tmux$")
92 (should (string= (ivy--regex-fuzzy "")
94 (should (string= (ivy--regex-fuzzy "^")
96 (should (string= (ivy--regex-fuzzy "$")
99 (ert-deftest ivy--format ()
100 (should (string= (let ((ivy--index 10)
101 (ivy-format-function (lambda (x) (mapconcat #'identity x "\n")))
114 #("\nDESCRIPTION\nFUNCTION LETTERS\nSWITCHES\nDIAGNOSTICS\nEXAMPLE 1\nEXAMPLE 2\nEXAMPLE 3\nSEE ALSO\nAUTHOR"
116 90 96 (face ivy-current-match read-only nil)))))
118 (ert-deftest ivy--filter ()
119 (setq ivy-last (make-ivy-state))
120 (should (equal (ivy--filter "the" '("foo" "the" "The"))
122 (should (equal (ivy--filter "The" '("foo" "the" "The"))