Skip to content

Commit

Permalink
Merge branch 'rsw' of hyperbole into rsw
Browse files Browse the repository at this point in the history
  • Loading branch information
rswgnu committed Jan 16, 2024
2 parents 1b8fb05 + 2f2d51b commit a85f06a
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 19 deletions.
13 changes: 13 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
2024-01-16 Mats Lidell <[email protected]>

* 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 <[email protected]>

* test/hyrolo-tests.el (hyrolo-tests--forward-same-level-all-file-types-level1):
Expand Down
6 changes: 3 additions & 3 deletions hui-mouse.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
;;
Expand Down Expand Up @@ -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)))

Expand Down
115 changes: 99 additions & 16 deletions test/hyrolo-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Mats Lidell <[email protected]>
;;
;; 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
;;
Expand Down Expand Up @@ -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"))
Expand All @@ -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"))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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")))
Expand Down

0 comments on commit a85f06a

Please sign in to comment.