branch: externals/hyperbole
commit 8adaf7582246eab83c2c8cf8309e67d9523303da
Author: Mats Lidell <mats.lid...@lidells.se>
Commit: GitHub <nore...@github.com>

    Verify hyrolo match count (#500)
---
 ChangeLog            |  4 ++++
 test/hyrolo-tests.el | 28 +++++++++++++++++++++++++++-
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 879645bc84..dbf92d0187 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2024-03-31  Mats Lidell  <ma...@gnu.org>
+
+* test/hyrolo-tests.el (hyrolo-test--grep-count): Verify hyrolo match count.
+
 2024-03-31  Bob Weiner  <r...@gnu.org>
 
 * hyrolo.el (hyrolo-grep-file): Remove this line that was skipping past the
diff --git a/test/hyrolo-tests.el b/test/hyrolo-tests.el
index 177e494372..0bd65a4b8a 100644
--- a/test/hyrolo-tests.el
+++ b/test/hyrolo-tests.el
@@ -3,7 +3,7 @@
 ;; Author:       Mats Lidell <ma...@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
 ;;
@@ -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

Reply via email to