Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify hyrolo match count #500

Merged
merged 2 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2024-03-31 Mats Lidell <matsl@gnu.org>

* test/hyrolo-tests.el (hyrolo-test--grep-count): Verify hyrolo match count.

2024-03-31 Bob Weiner <rsw@gnu.org>

* hyrolo.el (hyrolo-grep-file): Remove this line that was skipping past the
Expand Down
28 changes: 27 additions & 1 deletion test/hyrolo-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Mats Lidell <matsl@gnu.org>
;;
;; Orig-Date: 19-Jun-21 at 22:42:00
;; Last-Mod: 22-Mar-24 at 08:37:53 by Bob Weiner
;; Last-Mod: 31-Mar-24 at 11:36:33 by Mats Lidell
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -1634,6 +1634,32 @@ body
(kill-buffer hyrolo-display-buffer)
(hy-delete-files-and-buffers hyrolo-file-list))))

(ert-deftest hyrolo-test--grep-count ()
"Verify number of matched entries are correct."
:expected-result :failed
(unwind-protect
(with-temp-buffer
(org-mode)
(insert "\
* match
match
* match
other
* other
match
")
;; Count number of entries that have a match
(should (= (hyrolo-grep "match" nil (current-buffer) t nil) 3))
;; Count number of entries that only match on the first line
(should (= (hyrolo-grep "match" nil (current-buffer) t t) 2))
;; Count number of entries that match but not on the first line
(should (= (hyrolo-grep "match" t (current-buffer) t nil) 2))
;; Nothing if there is no match
(should (= (hyrolo-grep "nothing" nil (current-buffer) t nil) 0)))
(and (get-buffer hyrolo-display-buffer)
(kill-buffer hyrolo-display-buffer)
(ert-fail "Buffer %s should not have been created" hyrolo-display-buffer))))

(provide 'hyrolo-tests)

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