Skip to content

Commit 7e473f6

Browse files
committed
PR#1164: use temp buffer in counsel-url-expand test
Avoid clobbering `current-word'
1 parent 52b063b commit 7e473f6

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

ivy-test.el

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,13 @@ will bring the behavior in line with the newer Emacsen."
241241
(ivy--regex "(foo bar"))
242242
"(\\(foo).*?(bar)")))
243243

244+
(defmacro ivy--string-buffer (text body)
245+
"Test helper that wraps TEXT in a temp buffer while running BODY."
246+
`(with-temp-buffer
247+
(insert ,text)
248+
(goto-char (point-min))
249+
,body))
250+
244251
(ert-deftest counsel-url-expand ()
245252
"Test ffap expansion using counsel-url-expansions."
246253
;; no expansions defined
@@ -252,14 +259,17 @@ will bring the behavior in line with the newer Emacsen."
252259
(concat "https://foo.com/issues/"
253260
(match-string 1 word)))))))
254261
;; no match
255-
(defun current-word () "foobar")
256-
(should (equal (counsel-url-expand) nil))
262+
(ivy--string-buffer
263+
"foobar"
264+
(should (equal (counsel-url-expand) nil)))
257265
;; string expansion
258-
(defun current-word () "foo")
259-
(should (equal (counsel-url-expand) "https://foo.com/foo"))
266+
(ivy--string-buffer
267+
"foo"
268+
(should (equal (counsel-url-expand) "https://foo.com/foo")))
260269
;; function expansion
261-
(defun current-word () "issue123")
262-
(should (equal (counsel-url-expand) "https://foo.com/issues/123"))))
270+
(ivy--string-buffer
271+
"issue123"
272+
(should (equal (counsel-url-expand) "https://foo.com/issues/123")))))
263273

264274
(ert-deftest colir-color-parse ()
265275
(should (equal (colir-color-parse "#ab1234")

0 commit comments

Comments
 (0)