branch: externals/hyperbole
commit 6c7b8e5afb3536ee046d1a60b46369aa854dd668
Author: Mats Lidell <[email protected]>
Commit: Mats Lidell <[email protected]>
Add helper for generating org files + two tests using the matches
---
ChangeLog | 10 ++++
test/hyrolo-tests.el | 142 +++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 148 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 4969506ca4..d3fd9e3122 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2023-01-02 Mats Lidell <[email protected]>
+* test/hyrolo-tests.el (hyrolo-tests--level-number)
+ (hyrolo-tests--generate-header-contents-for-tests)
+ (hyrolo-tests--gen-outline): Add helper for constructing org files for
+ tests.
+ (hyrolo-tests--outline-next-visible-header)
+ (hyrolo-tests--tab-through-matches): Add test for working with hyrolo
+ matches.
+
+2023-12-31 Mats Lidell <[email protected]>
+
* test/hyrolo-tests.el (hyrolo-tests--get-file-list-change)
(hyrolo-tests--get-file-list-wrong-suffice): Add hyrolo tests.
diff --git a/test/hyrolo-tests.el b/test/hyrolo-tests.el
index 06b18d9e55..db17adbd95 100644
--- a/test/hyrolo-tests.el
+++ b/test/hyrolo-tests.el
@@ -3,7 +3,7 @@
;; Author: Mats Lidell <[email protected]>
;;
;; Orig-Date: 19-Jun-21 at 22:42:00
-;; Last-Mod: 31-Dec-23 at 16:10:00 by Mats Lidell
+;; Last-Mod: 1-Jan-24 at 16:24:40 by Mats Lidell
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
@@ -462,9 +462,143 @@ Match a string in the second cell."
(ert-deftest hyrolo-tests--get-file-list-wrong-suffice ()
"Verify files need to have the proper suffix in hyrolo-file-list."
- (should-error
- (let ((hyrolo-file-list (list "file-no-proper-suffix")))
- ())))
+ (let ((tmp-file (make-temp-file "hypb" nil)))
+ (unwind-protect
+ (should-error
+ (setq hyrolo-file-list (list tmp-file)))
+ (hy-delete-file-and-buffer tmp-file))))
+
+;; Outline movement tests
+(defun hyrolo-tests--level-number (section depth)
+ "Generate the number for the SECTION at DEPTH.
+
+The format is the section followed by the depth given by the
+sequence up to depth starting from 2.
+ Depth 1: section
+ Depth <depth>: section.2.3.4..<depth>"
+ (let (result)
+ (dotimes (d depth)
+ (setq result
+ (if (= 0 d)
+ (number-to-string section)
+ (concat result
+ "."
+ (number-to-string (+ 1 d))))))
+ result))
+
+(defun hyrolo-tests--generate-header-contents-for-tests (header section body
depth)
+ "Generate the HEADER and BODY contents for the SECTION with DEPTH."
+ (let (result)
+ (dotimes (d depth)
+ (setq result
+ (concat result
+ (make-string (1+ d) ?*) " " header " "
(hyrolo-tests--level-number section (1+ d)) "\n"
+ body " " (hyrolo-tests--level-number section (1+ d))
"\n")))
+ result))
+
+(defun hyrolo-tests--gen-outline (header sections body depth)
+ "Generate an outline structure suitable for hyrolo outline test.
+
+The contents is constructed with an outline HEADER and BODY text.
+Each is repeated in SECTIONS with one set of hierarchical headers
+to the specified DEPTH.
+
+Example:
+ * header 1
+ body 1
+ ** header 2
+ body 1.2
+ [...]
+ * header <sections>
+ body <sections>
+ ** header <sections>.2
+ body <section>.2
+ [...]"
+ (let (result)
+ (dotimes (section sections)
+ (setq result
+ (concat result
+ (hyrolo-tests--generate-header-contents-for-tests header
(1+ section) body depth))))
+ result))
+
+(ert-deftest hyrolo-tests--outline-next-visible-header ()
+ "Verify movement to next visible header."
+ (let* ((org-file (make-temp-file "hypb" nil ".org"
+ (hyrolo-tests--gen-outline "header" 2
"body" 2)))
+ (hyrolo-file-list (list org-file)))
+ (unwind-protect
+ (progn
+ (hyrolo-grep "body")
+ (should (string= "*HyRolo*" (buffer-name)))
+
+ ;; Move down
+ (should (looking-at-p "==="))
+ (should (hact 'kbd-key "n"))
+ (should (looking-at-p "^* header 1"))
+ (should (hact 'kbd-key "n"))
+ (should (looking-at-p "^** header 1.2"))
+ (should (hact 'kbd-key "n"))
+ (should (looking-at-p "^* header 2"))
+ (should (hact 'kbd-key "n"))
+ (should (looking-at-p "^** header 2.2"))
+ (should (hact 'kbd-key "n"))
+ (should (eobp))
+
+ ;; Move back up
+ (should (hact 'kbd-key "p"))
+ (should (looking-at-p "^** header 2.2"))
+ (should (hact 'kbd-key "p"))
+ (should (looking-at-p "^* header 2"))
+ (should (hact 'kbd-key "p"))
+ (should (looking-at-p "^** header 1.2"))
+ (should (hact 'kbd-key "p"))
+ (should (looking-at-p "^* header 1"))
+ (should (hact 'kbd-key "p"))
+
+ ;; BUG: This fails in Emacs 29 and 30
+ ;; This is the expected behavior that works in Emacs 27 and 28.
+ ;; (should (looking-at-p "==="))
+ ;; (should (bobp))
+ ;; This is what we get
+ (should (looking-at-p "@loc>"))
+ (should (= 2 (line-number-at-pos))))
+ (kill-buffer "*HyRolo*")
+ (hy-delete-file-and-buffer org-file))))
+
+
+(ert-deftest hyrolo-tests--tab-through-matches ()
+ "Verify movement to next visible header."
+ (let* ((org-file (make-temp-file "hypb" nil ".org"
+ (hyrolo-tests--gen-outline "header" 2
"body" 2)))
+ (hyrolo-file-list (list org-file)))
+ (unwind-protect
+ (progn
+ (hyrolo-grep "body")
+ (should (string= "*HyRolo*" (buffer-name)))
+
+ ;; Search Down
+ (should (looking-at-p "==="))
+ (should (hact 'kbd-key "TAB"))
+ (should (looking-at-p "^body 1$"))
+ (should (hact 'kbd-key "TAB"))
+ (should (looking-at-p "^body 1.2"))
+ (should (hact 'kbd-key "TAB"))
+ (should (looking-at-p "^body 2$"))
+ (should (hact 'kbd-key "TAB"))
+ (should (looking-at-p "^body 2.2"))
+ (should-error (hact 'kbd-key "TAB"))
+ (should (looking-at-p "^body 2.2"))
+
+ ;; Search Up
+ (should (hact 'kbd-key "<backtab>"))
+ (should (looking-at-p "^body 2$"))
+ (should (hact 'kbd-key "<backtab>"))
+ (should (looking-at-p "^body 1.2"))
+ (should (hact 'kbd-key "<backtab>"))
+ (should (looking-at-p "^body 1$"))
+ (should-error (hact 'kbd-key "<backtab>")))
+ (kill-buffer "*HyRolo*")
+ (hy-delete-file-and-buffer org-file))))
(provide 'hyrolo-tests)
;;; hyrolo-tests.el ends here