branch: externals/hyperbole commit a85f06a9e429b96509c6d0a355f4f3c742aaec39 Merge: 1b8fb059c6 2f2d51b816 Author: Bob Weiner <r...@gnu.org> Commit: Bob Weiner <r...@gnu.org>
Merge branch 'rsw' of hyperbole into rsw --- ChangeLog | 13 ++++++ hui-mouse.el | 6 +-- test/hyrolo-tests.el | 115 ++++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 115 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index feedb4d0cc..59127db689 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2024-01-16 Mats Lidell <ma...@gnu.org> + +* test/hyrolo-tests.el + (hyrolo-tests--forward-same-level-all-file-types-level1-depth2) + (hyrolo-tests--forward-same-level-all-file-types-level2): Add test + with more file types and second level headings. + + (hyrolo-tests--outline-content-org, hyrolo-tests--outline-content-otl) + (hyrolo-tests--outline-content-md); Add test content constants. + + (hyrolo-tests--gen-kotl-outline): Add depth arg to kotl to generate + child cells in test data. + 2024-01-15 Bob Weiner <r...@gnu.org> * test/hyrolo-tests.el (hyrolo-tests--forward-same-level-all-file-types-level1): diff --git a/hui-mouse.el b/hui-mouse.el index 8d1af80747..cb6195aad7 100644 --- a/hui-mouse.el +++ b/hui-mouse.el @@ -3,7 +3,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 04-Feb-89 -;; Last-Mod: 15-Jan-24 at 18:18:37 by Bob Weiner +;; Last-Mod: 15-Jan-24 at 22:12:47 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -1447,8 +1447,8 @@ buffer and has moved the cursor to the selected buffer." (interactive) (if (hyrolo-hdr-in-p) (hact 'hyp-source (save-excursion - (hyrolo-hdr-to-first-line-p) - (when (search-forward hbut:source-prefix nil t) + (when (and (hyrolo-hdr-to-first-line-p) + (search-forward hbut:source-prefix nil t)) (hbut:source t)))) (hyrolo-edit-entry))) diff --git a/test/hyrolo-tests.el b/test/hyrolo-tests.el index 89e2974540..392312014d 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: 15-Jan-24 at 21:40:51 by Bob Weiner +;; Last-Mod: 15-Jan-24 at 22:15:11 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -229,7 +229,7 @@ and {b} the previous same level cell." (hyrolo-add "a") (hyrolo-add "b/d") - ; Verify insertion order and following date on separate line + ;; Verify insertion order and following date on separate line (goto-char (point-min)) (should (looking-at "===")) (dolist (insertion-order '("a" "b" "d" "c")) @@ -238,7 +238,7 @@ and {b} the previous same level cell." (hyrolo-sort) - ; Verify sorted order and following date on separate line + ;; Verify sorted order and following date on separate line (goto-char (point-min)) (should (looking-at "===")) (dolist (sorted-order '("a" "b" "d" "c")) @@ -565,7 +565,7 @@ Example: (ert-deftest hyrolo-tests--outline-next-visible-heading-md () "Verify movement to next visible heading." (let* ((md-file (make-temp-file "hypb" nil ".md" - (hyrolo-tests--gen-outline ?# "heading" 2 "body" 2))) + (hyrolo-tests--gen-outline ?# "heading" 2 "body" 2))) (hyrolo-file-list (list md-file))) (unwind-protect (progn @@ -603,7 +603,7 @@ Example: (ert-deftest hyrolo-tests--outline-next-visible-heading-all () "Verify movement to next visible heading." (let* ((md-file (make-temp-file "hypb" nil ".md" - (hyrolo-tests--gen-outline ?# "heading" 2 "body" 2))) + (hyrolo-tests--gen-outline ?# "heading" 2 "body" 2))) (hyrolo-file-list (list md-file))) (unwind-protect (progn @@ -665,7 +665,7 @@ Example: (let* ((org-file1 (make-temp-file "hypb" nil ".org" (hyrolo-tests--gen-outline ?* "heading-a" 1 "body-a" 2))) (md-file1 (make-temp-file "hypb" nil ".md" - (hyrolo-tests--gen-outline ?# "heading-b" 1 "body-b" 2))) + (hyrolo-tests--gen-outline ?# "heading-b" 1 "body-b" 2))) (hyrolo-file-list (list org-file1 md-file1))) (unwind-protect (progn @@ -702,15 +702,22 @@ Example: (kill-buffer hyrolo-display-buffer) (hy-delete-files-and-buffers hyrolo-file-list)))) -(defun hyrolo-tests--gen-kotl-outline (heading body) +(defun hyrolo-tests--gen-kotl-outline (heading body &optional depth) "Generate a temp file with kotl outline structure for hyrolo outline test. -Make cell start with HEADING and follow by next line BODY." +Make cell start with HEADING and follow by next line BODY. With +optional DEPTH the number of sub cells are created to that depth." (let ((kotl-file (make-temp-file "hypb" nil ".kotl"))) (find-file kotl-file) (insert heading) (kotl-mode:newline 1) (insert body) (kotl-mode:newline 1) + (when (and depth (< 0 depth)) + (dotimes (d depth) + (kotl-mode:add-child) + (insert (format "%s %d" heading (1+ d))) + (kotl-mode:newline 1) + (insert (format "%s %d" body (1+ d))))) (save-buffer) kotl-file)) @@ -933,10 +940,39 @@ All files types are present." (kill-buffer hyrolo-display-buffer) (hy-delete-files-and-buffers hyrolo-file-list)))) -(ert-deftest hyrolo-tests--forward-same-level-org-level2 () - "Verify forward and backward to second level headers with org files." - (let* ((content - "\ +(ert-deftest hyrolo-tests--forward-same-level-all-file-types-level1-depth2 () + "Verify forward and backward to first level headers and section lines. +All files types are present with a max depth of 2 of the outline +structure." + (let* ((org-file1 (make-temp-file "hypb" nil ".org" + (hyrolo-tests--gen-outline ?* "heading-org" 1 "body-org" 2))) + (md-file1 (make-temp-file "hypb" nil ".md" + (hyrolo-tests--gen-outline ?# "heading-md" 1 "body-md" 2))) + (otl-file1 (make-temp-file "hypb" nil ".otl" + (hyrolo-tests--gen-outline ?* "heading-otl" 1 "body-otl" 2))) + (kotl-file1 (hyrolo-tests--gen-kotl-outline "heading-kotl" "body-kotl" 2)) + (hyrolo-file-list (list org-file1 md-file1 otl-file1 kotl-file1))) + (unwind-protect + (progn + (hyrolo-grep "body") + (should (string= hyrolo-display-buffer (buffer-name))) + + ;; Move forward + (dolist (v '("===" "^\\* heading-org 1$" "===" "^# heading-md 1$" + "===" "^\\* heading-otl 1$" "===")) + (should (and (looking-at-p v) (hact 'kbd-key "f")))) + (should (looking-at-p "^ +1\\. heading-kotl$")) ; When on last match do not move further + + ;; Move backward + (dolist (v '("===" "^\\* heading-otl 1$" "===" "^# heading-md 1$" + "===" "^\\* heading-org 1$" "===")) + (should (and (hact 'kbd-key "b") (looking-at-p v)))) + (should (= 1 (line-number-at-pos)))) + (kill-buffer hyrolo-display-buffer) + (hy-delete-files-and-buffers hyrolo-file-list)))) + +(defconst hyrolo-tests--outline-content-org + "\ * h-org 1 body ** h-org 1.1 @@ -949,9 +985,22 @@ body body ** h-org-2.1 body -") - (org-file1 (make-temp-file "hypb" nil ".org" content)) - (org-file2 (make-temp-file "hypb" nil ".org" content)) +" + "Outline content for org files.") + +(defconst hyrolo-tests--outline-content-otl + (string-replace "org" "otl" hyrolo-tests--outline-content-org) + "Outline content for otl files.") + +(defconst hyrolo-tests--outline-content-md + (string-replace "*" "#" + (string-replace "org" "md" hyrolo-tests--outline-content-org)) + "Outline content for markdown files.") + +(ert-deftest hyrolo-tests--forward-same-level-org-level2 () + "Verify forward and backward to second level headers with org files." + (let* ((org-file1 (make-temp-file "hypb" nil ".org" hyrolo-tests--outline-content-org)) + (org-file2 (make-temp-file "hypb" nil ".org" hyrolo-tests--outline-content-org)) (hyrolo-file-list (list org-file1 org-file2))) (unwind-protect (progn @@ -967,7 +1016,41 @@ body (should (and (hact 'kbd-key "f") (looking-at-p "^\\*\\* h-org 1\\.2"))) ;; Multiple times does not move point when there are no more headers at the same level - (should-error (and (hact 'kbd-key "f") (looking-at-p "^\\*\\* h-org 1\\.2"))) + (should-error (hact 'kbd-key "f")) + (should (looking-at-p "^\\*\\* h-org 1\\.2")) + + ;; Move back on same level + (should (and (hact 'kbd-key "b") (looking-at-p "\\*\\* h-org 1\\.1"))) + + ;; Moving up from first header on a level errors, also when repeated. + (should-error (and (hact 'kbd-key "b") (looking-at-p "^\\*\\* h-org 1\\.1"))) + (should-error (and (hact 'kbd-key "b") (looking-at-p "^\\*\\* h-org 1\\.1")))) + (kill-buffer hyrolo-display-buffer) + (hy-delete-files-and-buffers hyrolo-file-list)))) + +(ert-deftest hyrolo-tests--forward-same-level-all-file-types-level2 () + "Verify forward and backward to second level headers with org files." + (let* ((org-file1 (make-temp-file "hypb" nil ".org" hyrolo-tests--outline-content-org)) + (otl-file1 (make-temp-file "hypb" nil ".otl" hyrolo-tests--outline-content-otl)) + (md-file1 (make-temp-file "hypb" nil ".md" hyrolo-tests--outline-content-md)) + (kotl-file1 (hyrolo-tests--gen-kotl-outline "heading-kotl" "body-kotl" 2)) + (hyrolo-file-list (list org-file1 otl-file1 md-file1 kotl-file1))) + (unwind-protect + (progn + (hyrolo-grep "body") + (should (string= hyrolo-display-buffer (buffer-name))) + + ;; Move to first second level header + (search-forward "** h-org 1.1") + (beginning-of-line) + (should (looking-at-p "^\\*\\* h-org 1\\.1")) + + ;; Move forward same level + (should (and (hact 'kbd-key "f") (looking-at-p "^\\*\\* h-org 1\\.2"))) + + ;; Multiple times does not move point when there are no more headers at the same level + (should-error (hact 'kbd-key "f")) + (should (looking-at-p "^\\*\\* h-org 1\\.2")) ;; Move back on same level (should (and (hact 'kbd-key "b") (looking-at-p "\\*\\* h-org 1\\.1")))