branch: master
commit 0a1d361b926291874124f8c63a653d83ead64a36
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
Minor changes to counsel-url-expand
* counsel.el: Rename `counsel-url-expansions' to
`counsel-url-expansions-alist'.
* ivy-test.el (counsel-url-expand): Flip `ivy--string-buffer' and `equal'.
Easier to eval just the `ivy--string-buffer'
expression and get a string.
Re #1164
---
counsel.el | 6 +-
ivy-test.el | 302 ++++++++++++++++++++++++++++++------------------------------
2 files changed, 154 insertions(+), 154 deletions(-)
diff --git a/counsel.el b/counsel.el
index e7a6984..7dd9e5b 100644
--- a/counsel.el
+++ b/counsel.el
@@ -1700,7 +1700,7 @@ When INITIAL-INPUT is non-nil, use it in the minibuffer
during completion."
(format "http://debbugs.gnu.org/cgi/bugreport.cgi?bug=%s"
(substring url 1)))))))
-(defvar counsel-url-expansions nil
+(defvar counsel-url-expansions-alist nil
"Map of regular expressions to expansions.
This variable should take the form of a list of (REGEXP . FORMAT)
@@ -1727,7 +1727,7 @@ transformations are possible. As an example,
trims the \"issue\" prefix from the word at point before creating the URL.")
(defun counsel-url-expand ()
- "Expand word at point using `counsel-url-expansions'.
+ "Expand word at point using `counsel-url-expansions-alist'.
The first pair in the list whose regexp matches the word at point
will be expanded according to its format. This function is
intended to be used in `ivy-ffap-url-functions' to browse the
@@ -1741,7 +1741,7 @@ result as a URL."
(if (functionp formatter)
(funcall formatter word-at-point)
(format formatter word-at-point)))))
- counsel-url-expansions)))
+ counsel-url-expansions-alist)))
;;** `counsel-recentf'
(defvar recentf-list)
diff --git a/ivy-test.el b/ivy-test.el
index 7ac9326..3c41732 100644
--- a/ivy-test.el
+++ b/ivy-test.el
@@ -1,4 +1,4 @@
-;;; ivy-test.el --- tests for ivy
+;;; ivy-test.el --- tests for ivy -*- lexical-binding: t -*-
;; Copyright (C) 2015-2017 Free Software Foundation, Inc.
@@ -138,7 +138,7 @@ will bring the behavior in line with the newer Emacsen."
(ert-deftest ivy-read-remap ()
(should (equal
(ivy-with '(ivy-read "pattern: " '("blue" "yellow" "red"))
- "<S-right> C-m")
+ "<S-right> C-m")
"red")))
(ert-deftest swiper--re-builder ()
@@ -252,31 +252,31 @@ will bring the behavior in line with the newer Emacsen."
(defmacro ivy--string-buffer (text &rest body)
"Test helper that wraps TEXT in a temp buffer while running BODY."
`(with-temp-buffer
- (insert ,text)
- ,@body))
+ (insert ,text)
+ ,@body))
(ert-deftest counsel-url-expand ()
- "Test ffap expansion using counsel-url-expansions."
+ "Test ffap expansion using `counsel-url-expansions-alist'."
;; no expansions defined
- (let (counsel-url-expansions)
+ (let (counsel-url-expansions-alist)
(should (eq (counsel-url-expand) nil)))
- (let ((counsel-url-expansions
- `(("^foo$" . "https://foo.com/%s")
- ("^issue\\([0-9]+\\)" . ,(lambda (word)
- (concat "https://foo.com/issues/"
- (match-string 1 word)))))))
+ (let ((counsel-url-expansions-alist
+ '(("^foo$" . "https://foo.com/%s")
+ ("^issue\\([0-9]+\\)" . (lambda (word)
+ (concat "https://foo.com/issues/"
+ (match-string 1 word)))))))
;; no match
- (ivy--string-buffer
- "foobar"
- (should (equal (counsel-url-expand) nil)))
+ (should (equal (ivy--string-buffer
+ "foobar"
+ (counsel-url-expand)) nil))
;; string expansion
- (ivy--string-buffer
- "foo"
- (should (equal (counsel-url-expand) "https://foo.com/foo")))
+ (should (equal (ivy--string-buffer
+ "foo"
+ (counsel-url-expand)) "https://foo.com/foo"))
;; function expansion
- (ivy--string-buffer
- "issue123"
- (should (equal (counsel-url-expand) "https://foo.com/issues/123")))))
+ (should (equal (ivy--string-buffer
+ "issue123"
+ (counsel-url-expand)) "https://foo.com/issues/123"))))
(ert-deftest colir-color-parse ()
(should (equal (colir-color-parse "#ab1234")
@@ -458,19 +458,19 @@ will bring the behavior in line with the newer Emacsen."
(should (equal
(ivy-with
'(let (res)
- (ivy-read "pattern: " '("blue" "yellow")
- :action (lambda (x)
- (setq res ivy-current-prefix-arg)))
- res)
+ (ivy-read "pattern: " '("blue" "yellow")
+ :action (lambda (x)
+ (setq res ivy-current-prefix-arg)))
+ res)
"M-1 M-2 M-3 C-m")
123))
(should (equal
(ivy-with
'(let (res)
- (ivy-read "pattern: " '("blue" "yellow")
- :action (lambda (x)
- (setq res ivy-current-prefix-arg)))
- res)
+ (ivy-read "pattern: " '("blue" "yellow")
+ :action (lambda (x)
+ (setq res ivy-current-prefix-arg)))
+ res)
"C-u 123 C-m")
123)))
@@ -498,83 +498,83 @@ will bring the behavior in line with the newer Emacsen."
"default")))
(ert-deftest ivy-read-prompt ()
- (let ((prompt "pattern: ")
- (collection '("blue" "yellow")))
- (should (equal
- (ivy-with
- '(let ((ivy-use-selectable-prompt nil))
- (ivy-read prompt collection))
- "bl C-m")
- "blue"))
- (should (equal
- (ivy-with
- '(let ((ivy-use-selectable-prompt nil))
- (ivy-read prompt collection))
- "bl C-p C-m")
- "blue"))
- (should (equal
- (ivy-with
- '(let ((ivy-use-selectable-prompt nil))
- (ivy-read prompt collection))
- "bl C-j")
- "blue"))
- (should (equal
- (ivy-with
- '(let ((ivy-use-selectable-prompt nil))
- (ivy-read prompt collection))
- "bl C-p C-j")
- "blue"))
- (should (equal
- (ivy-with
- '(let ((ivy-use-selectable-prompt nil))
- (ivy-read prompt collection))
- "bl C-M-j")
- "bl"))
- (should (equal
- (ivy-with
- '(let ((ivy-use-selectable-prompt nil))
- (ivy-read prompt collection))
- "bl C-p C-M-j")
- "bl"))
- (should (equal
- (ivy-with
- '(let ((ivy-use-selectable-prompt t))
- (ivy-read prompt collection))
- "bl C-m")
- "blue"))
- (should (equal
- (ivy-with
- '(let ((ivy-use-selectable-prompt t))
- (ivy-read prompt collection))
- "bl C-p C-m")
- "bl"))
- (should (equal
- (ivy-with
- '(let ((ivy-use-selectable-prompt t))
- (ivy-read prompt collection))
- "bl C-j")
- "blue"))
- (should (equal
- (ivy-with
- '(let ((ivy-use-selectable-prompt t))
- (ivy-read prompt collection))
- "bl C-p C-j")
- "bl"))
- (should (equal
- (ivy-with
- '(let ((ivy-use-selectable-prompt t))
- (ivy-read prompt collection))
- "bl C-M-j")
- "bl"))
- (should (equal
- (ivy-with
- '(let ((ivy-use-selectable-prompt t))
- (ivy-read prompt collection))
- "bl C-p C-M-j")
- "bl"))))
+ (setq prompt "pattern: ")
+ (setq collection '("blue" "yellow"))
+ (should (equal
+ (ivy-with
+ '(let ((ivy-use-selectable-prompt nil))
+ (ivy-read prompt collection))
+ "bl C-m")
+ "blue"))
+ (should (equal
+ (ivy-with
+ '(let ((ivy-use-selectable-prompt nil))
+ (ivy-read prompt collection))
+ "bl C-p C-m")
+ "blue"))
+ (should (equal
+ (ivy-with
+ '(let ((ivy-use-selectable-prompt nil))
+ (ivy-read prompt collection))
+ "bl C-j")
+ "blue"))
+ (should (equal
+ (ivy-with
+ '(let ((ivy-use-selectable-prompt nil))
+ (ivy-read prompt collection))
+ "bl C-p C-j")
+ "blue"))
+ (should (equal
+ (ivy-with
+ '(let ((ivy-use-selectable-prompt nil))
+ (ivy-read prompt collection))
+ "bl C-M-j")
+ "bl"))
+ (should (equal
+ (ivy-with
+ '(let ((ivy-use-selectable-prompt nil))
+ (ivy-read prompt collection))
+ "bl C-p C-M-j")
+ "bl"))
+ (should (equal
+ (ivy-with
+ '(let ((ivy-use-selectable-prompt t))
+ (ivy-read prompt collection))
+ "bl C-m")
+ "blue"))
+ (should (equal
+ (ivy-with
+ '(let ((ivy-use-selectable-prompt t))
+ (ivy-read prompt collection))
+ "bl C-p C-m")
+ "bl"))
+ (should (equal
+ (ivy-with
+ '(let ((ivy-use-selectable-prompt t))
+ (ivy-read prompt collection))
+ "bl C-j")
+ "blue"))
+ (should (equal
+ (ivy-with
+ '(let ((ivy-use-selectable-prompt t))
+ (ivy-read prompt collection))
+ "bl C-p C-j")
+ "bl"))
+ (should (equal
+ (ivy-with
+ '(let ((ivy-use-selectable-prompt t))
+ (ivy-read prompt collection))
+ "bl C-M-j")
+ "bl"))
+ (should (equal
+ (ivy-with
+ '(let ((ivy-use-selectable-prompt t))
+ (ivy-read prompt collection))
+ "bl C-p C-M-j")
+ "bl")))
(ert-deftest ivy-completing-read-def-handling ()
- ;; DEF in COLLECTION
+ ;; DEF in COLLECTION
(should
(equal "b"
(ivy-with '(ivy-completing-read "Pick: " '("a" "b" "c") nil t nil
nil "b")
@@ -621,7 +621,7 @@ will bring the behavior in line with the newer Emacsen."
(equal "c"
(ivy-with '(ivy-completing-read-with-empty-string-def
"Pick: " '("a" "b" "c") nil t nil nil nil)
- "c RET"))))
+ "c RET"))))
(ert-deftest ivy-completing-read-handlers ()
(cl-letf* ((ivy-mode-reset-arg (if ivy-mode 1 0))
@@ -642,53 +642,53 @@ will bring the behavior in line with the newer Emacsen."
((symbol-function 'test-command-recursive-handler)
(symbol-function 'test-command-no-handler)))
(unwind-protect
- (progn
- ;; Activate ivy-mode
- (ivy-mode 1)
- ;; No handler
- (should
- (equal "a"
- (ivy-with
- '(command-execute-setting-this-command
- 'test-command-no-handler)
- "RET")))
- (should
- (equal "c"
- (ivy-with
- '(command-execute-setting-this-command
- 'test-command-no-handler)
- "c RET")))
- ;; Handler = `completing-read-default'; make sure ivy-read
- ;; is never called
- (cl-letf (((symbol-function 'ivy-read)
- (lambda (&rest args) (error "`ivy-read' should not be
called"))))
-
- (should
- (equal ""
- (ivy-with
- '(command-execute-setting-this-command
- 'test-command-default-handler)
- "RET")))
- (should
- (equal "c"
- (ivy-with
- '(command-execute-setting-this-command
- 'test-command-default-handler)
- "c RET"))))
- ;; Handler = `ivy-completing-read-with-empty-string-def';
- ;; make sure infinite recursion does not occur
- (should
- (equal ""
- (ivy-with
- '(command-execute-setting-this-command
- 'test-command-recursive-handler)
- "RET")))
- (should
- (equal "c"
- (ivy-with
- '(command-execute-setting-this-command
- 'test-command-recursive-handler)
- "c RET"))))
+ (progn
+ ;; Activate ivy-mode
+ (ivy-mode 1)
+ ;; No handler
+ (should
+ (equal "a"
+ (ivy-with
+ '(command-execute-setting-this-command
+ 'test-command-no-handler)
+ "RET")))
+ (should
+ (equal "c"
+ (ivy-with
+ '(command-execute-setting-this-command
+ 'test-command-no-handler)
+ "c RET")))
+ ;; Handler = `completing-read-default'; make sure ivy-read
+ ;; is never called
+ (cl-letf (((symbol-function 'ivy-read)
+ (lambda (&rest args) (error "`ivy-read' should not be
called"))))
+
+ (should
+ (equal ""
+ (ivy-with
+ '(command-execute-setting-this-command
+ 'test-command-default-handler)
+ "RET")))
+ (should
+ (equal "c"
+ (ivy-with
+ '(command-execute-setting-this-command
+ 'test-command-default-handler)
+ "c RET"))))
+ ;; Handler = `ivy-completing-read-with-empty-string-def';
+ ;; make sure infinite recursion does not occur
+ (should
+ (equal ""
+ (ivy-with
+ '(command-execute-setting-this-command
+ 'test-command-recursive-handler)
+ "RET")))
+ (should
+ (equal "c"
+ (ivy-with
+ '(command-execute-setting-this-command
+ 'test-command-recursive-handler)
+ "c RET"))))
(ivy-mode ivy-mode-reset-arg))))
(provide 'ivy-test)