Skip to content

Commit 3ed61f1

Browse files
authored
Add test for hyrolo-display-matches (#904)
* hyrolo.el (hyrolo-display-matches): Remove support for Emacs 18. * test/hyrolo-tests.el (hyrolo-tests--display-matches): Add test.
1 parent 287b794 commit 3ed61f1

2 files changed

Lines changed: 30 additions & 10 deletions

File tree

hyrolo.el

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
;; Author: Bob Weiner
44
;;
55
;; Orig-Date: 7-Jun-89 at 22:08:29
6-
;; Last-Mod: 11-Mar-26 at 19:00:19 by Bob Weiner
6+
;; Last-Mod: 14-Mar-26 at 19:38:41 by Mats Lidell
77
;;
88
;; SPDX-License-Identifier: GPL-3.0-or-later
99
;;
10-
;; Copyright (C) 1991-2025 Free Software Foundation, Inc.
10+
;; Copyright (C) 1991-2026 Free Software Foundation, Inc.
1111
;; See the "HY-COPY" file for license information.
1212
;;
1313
;; This file is part of GNU Hyperbole.
@@ -582,12 +582,8 @@ after the display."
582582
(error "(hyrolo-display-matches): Search the rolo first"))
583583
;; Save current window configuration if rolo match buffer is not
584584
;; displayed in one of the windows already.
585-
(or
586-
;; Handle both Emacs V18 and V19 versions of get-buffer-window.
587-
(condition-case ()
588-
(get-buffer-window display-buf (selected-frame))
589-
(error (get-buffer-window display-buf)))
590-
(setq hyrolo--wconfig (current-window-configuration)))
585+
(unless (get-buffer-window display-buf (selected-frame))
586+
(setq hyrolo--wconfig (current-window-configuration)))
591587
(hyrolo-to-buffer display-buf)
592588
(when (fboundp 'hproperty:but-create)
593589
(hproperty:but-create))

test/hyrolo-tests.el

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
;; Author: Mats Lidell <matsl@gnu.org>
44
;;
55
;; Orig-Date: 19-Jun-21 at 22:42:00
6-
;; Last-Mod: 16-Aug-25 at 15:30:03 by Bob Weiner
6+
;; Last-Mod: 14-Mar-26 at 19:44:08 by Mats Lidell
77
;;
88
;; SPDX-License-Identifier: GPL-3.0-or-later
99
;;
10-
;; Copyright (C) 2021-2025 Free Software Foundation, Inc.
10+
;; Copyright (C) 2021-2026 Free Software Foundation, Inc.
1111
;; See the "HY-COPY" file for license information.
1212
;;
1313
;; This file is part of GNU Hyperbole.
@@ -1696,6 +1696,30 @@ match
16961696
(let ((buffer-file-name "file"))
16971697
(should (hyrolo-at-tags-p t))))))
16981698

1699+
(ert-deftest hyrolo-tests--display-matches ()
1700+
"Verify hyrolo-display-matches displays the buffer with the matches."
1701+
(ert-info ("No previous search nor buffer is provided")
1702+
(with-mock
1703+
(mock (get-buffer hyrolo-display-buffer) => nil)
1704+
(should-error (hyrolo-display-matches nil))))
1705+
(with-temp-buffer
1706+
(let ((buf1 (current-buffer)))
1707+
(with-temp-buffer
1708+
(let ((buf2 (current-buffer))
1709+
hyrolo--wconfig
1710+
(display-buffer-alist '((".*" display-buffer-same-window))))
1711+
(ert-info ("Provided buffer is selected with window config")
1712+
(hyrolo-display-matches buf1)
1713+
(should hyrolo--wconfig)
1714+
(should (equal buf1 (current-buffer))))
1715+
(ert-info ("Provided buffer already visible, don't save window config")
1716+
(setq hyrolo--wconfig nil)
1717+
(hyrolo-display-matches buf1)
1718+
(should-not hyrolo--wconfig))
1719+
(ert-info ("return-to-buffer is selected")
1720+
(hyrolo-display-matches buf1 buf2)
1721+
(should (equal buf2 (current-buffer)))))))))
1722+
16991723
(provide 'hyrolo-tests)
17001724

17011725
;; This file can't be byte-compiled without the `el-mock' package

0 commit comments

Comments
 (0)