Skip to content
Open
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
33 changes: 33 additions & 0 deletions test/hy-test-helpers.el
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
;;; Code:

(require 'ert)
(require 'ert-x)
(require 'hmouse-drv) ;; For `action-key'
(require 'hywiki) ;; For `hywiki-word-face-at-p' and (require 'hypb)
(eval-when-compile (require 'cl-lib))
Expand Down Expand Up @@ -184,5 +185,37 @@ and the default WORD-LENGTH is 4."
(insert-file-contents file)
(buffer-string)))

(defun hy-test-get-resource-as-sexp (resource)
"Read RESOURCE and return as sexp."
(with-temp-buffer
(insert-file-contents resource)
(read (current-buffer))))

(defun hy-test-outline-as-string (&optional begin end)
"Return buffer content as a string with hidden text replaced by ellipses.
The string contains what the outline actually looks like. This
enables `string-match' tests for verifying text is hidden. With
optional BEGIN and END only return that part of the buffer."
(if (not begin) (setq begin (point-min)))
(if (not end) (setq end (point-max)))
(save-excursion
(let ((result "")
in-invisible-section)
(goto-char begin)
(while (< (point) end)
(setq result
(concat result
(if (get-char-property (point) 'invisible)
(cond ((not in-invisible-section)
(setq in-invisible-section t)
"...")
(t nil))
(progn
(if in-invisible-section
(setq in-invisible-section nil))
(char-to-string (char-after))))))
(goto-char (1+ (point))))
result)))

(provide 'hy-test-helpers)
;;; hy-test-helpers.el ends here
78 changes: 26 additions & 52 deletions 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: 4-Nov-26 at 17:26:40 by Mats Lidell
;; Last-Mod: 14-Nov-26 at 00:59:09 by Mats Lidell
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -1309,32 +1309,6 @@ Useful for creating outline and markdown test data from org examples."
(kill-buffer hyrolo-display-buffer)
(hy-delete-files-and-buffers hyrolo-file-list))))

(defun hyrolo-tests--outline-as-string (&optional begin end)
"Return buffer content as a string with hidden text replaced by ellipses.
The string contains what the outline actually looks like. This
enables `string-match' tests for verifying text is hidden. With
optional BEGIN and END only return that part of the buffer."
(if (not begin) (setq begin (point-min)))
(if (not end) (setq end (point-max)))
(save-excursion
(let ((result "")
in-invisible-section)
(goto-char begin)
(while (< (point) end)
(setq result
(concat result
(if (get-char-property (point) 'invisible)
(cond ((not in-invisible-section)
(setq in-invisible-section t)
"...")
(t nil))
(progn
(if in-invisible-section
(setq in-invisible-section nil))
(char-to-string (char-after))))))
(goto-char (1+ (point))))
result)))

(ert-deftest hyrolo-tests--outline-hide-other ()
"Verify `hyrolo-outline-hide-other' hides except current body, parent and top-level headings."
(let* ((org-file1 (make-temp-file "hypb" nil ".org" hyrolo-tests--outline-content-org))
Expand All @@ -1353,7 +1327,7 @@ optional BEGIN and END only return that part of the buffer."
* h-org 2...
"
) "$")
(hyrolo-tests--outline-as-string)))
(hy-test-outline-as-string)))

;; On first header
(goto-char (point-min))
Expand All @@ -1366,7 +1340,7 @@ optional BEGIN and END only return that part of the buffer."
body...
* h-org 2...
"
(hyrolo-tests--outline-as-string (point))))
(hy-test-outline-as-string (point))))

;; On second header
(goto-char (point-min))
Expand All @@ -1379,7 +1353,7 @@ body...
body...
* h-org 2...
"
(hyrolo-tests--outline-as-string (point)))))
(hy-test-outline-as-string (point)))))
(kill-buffer hyrolo-display-buffer)
(hy-delete-files-and-buffers hyrolo-file-list))))

Expand All @@ -1403,7 +1377,7 @@ body...
* h-org 2...
"
) "$")
(hyrolo-tests--outline-as-string)))
(hy-test-outline-as-string)))

;; On first header
(goto-char (point-min))
Expand All @@ -1415,7 +1389,7 @@ body...
* h-org 1...
* h-org 2...
"
(hyrolo-tests--outline-as-string (point))))
(hy-test-outline-as-string (point))))

;; On second header
(goto-char (point-min))
Expand All @@ -1427,7 +1401,7 @@ body...
1...
* h-org 2...
"
(hyrolo-tests--outline-as-string (point))))
(hy-test-outline-as-string (point))))

;; First line - 2 levels
(goto-char (point-min))
Expand All @@ -1444,7 +1418,7 @@ body...
** h-org 2.1...
"
) "$")
(hyrolo-tests--outline-as-string)))
(hy-test-outline-as-string)))

;; On first header - 2 levels
(goto-char (point-min))
Expand All @@ -1459,7 +1433,7 @@ body...
* h-org 2...
** h-org 2.1...
"
(hyrolo-tests--outline-as-string (point))))
(hy-test-outline-as-string (point))))

;; On second header - 2 levels
(goto-char (point-min))
Expand All @@ -1473,7 +1447,7 @@ body...
* h-org 2...
** h-org 2.1...
"
(hyrolo-tests--outline-as-string (point)))))
(hy-test-outline-as-string (point)))))
(kill-buffer hyrolo-display-buffer)
(hy-delete-files-and-buffers hyrolo-file-list))))

Expand All @@ -1487,21 +1461,21 @@ body...

;; First line - show all
(should (= (point) 1))
(let ((original-look (hyrolo-tests--outline-as-string)))
(let ((original-look (hy-test-outline-as-string)))
(hyrolo-outline-hide-subtree)
(should (string-match-p
(concat "^===+" (regexp-quote "...") "\n$")
(hyrolo-tests--outline-as-string)))
(hy-test-outline-as-string)))
(hyrolo-outline-show-subtree)
(should (string= original-look (hyrolo-tests--outline-as-string))))
(should (string= original-look (hy-test-outline-as-string))))

;; On first header
(goto-char (point-min))
(hyrolo-outline-show-all)
(hyrolo-outline-hide-sublevels 1)
(search-forward "* h-org 1")
(beginning-of-line)
(let ((original-look (hyrolo-tests--outline-as-string)))
(let ((original-look (hy-test-outline-as-string)))
(hyrolo-outline-show-subtree)
(should (string= "\
* h-org 1
Expand All @@ -1514,18 +1488,18 @@ body
body
* h-org 2...
"
(hyrolo-tests--outline-as-string (point))))
(hy-test-outline-as-string (point))))
;; Hide it again
(hyrolo-outline-hide-subtree)
(should (string= original-look (hyrolo-tests--outline-as-string))))
(should (string= original-look (hy-test-outline-as-string))))

;; On second level header
(goto-char (point-min))
(hyrolo-outline-show-all)
(hyrolo-outline-hide-sublevels 2)
(search-forward "** h-org 1.2")
(beginning-of-line)
(let ((original-look (hyrolo-tests--outline-as-string)))
(let ((original-look (hy-test-outline-as-string)))
(hyrolo-outline-show-subtree)
(should (string= "\
** h-org 1.2
Expand All @@ -1535,10 +1509,10 @@ body
* h-org 2...
** h-org 2.1...
"
(hyrolo-tests--outline-as-string (point))))
(hy-test-outline-as-string (point))))
;; Hide it again
(hyrolo-outline-hide-subtree)
(should (string= original-look (hyrolo-tests--outline-as-string)))))
(should (string= original-look (hy-test-outline-as-string)))))
(kill-buffer hyrolo-display-buffer)
(hy-delete-files-and-buffers hyrolo-file-list))))

Expand All @@ -1562,19 +1536,19 @@ body
(should (string=
(concat (hyrolo-tests--hyrolo-section-header org-file1)
"* h-org 1...\n* h-org 2...\n")
(hyrolo-tests--outline-as-string)))
(hy-test-outline-as-string)))

(execute-kbd-macro (kbd "TAB"))
(should (string=
(concat (hyrolo-tests--hyrolo-section-header org-file1)
"* h-org 1\nbody\n** h-org 1.1\nbody\n** h-org 1.2\nbody\n*** h-org 1.2.1\nbody\n* h-org 2...\n")
(hyrolo-tests--outline-as-string)))
(hy-test-outline-as-string)))

(execute-kbd-macro (kbd "f TAB"))
(should (string=
(concat (hyrolo-tests--hyrolo-section-header org-file1)
"* h-org 1\nbody\n** h-org 1.1\nbody\n** h-org 1.2\nbody\n*** h-org 1.2.1\nbody\n* h-org 2\nbody\n** h-org 2.1\nbody\n")
(hyrolo-tests--outline-as-string))))
(hy-test-outline-as-string))))
(kill-buffer hyrolo-display-buffer)
(hy-delete-files-and-buffers hyrolo-file-list))))

Expand All @@ -1592,7 +1566,7 @@ body
"\
1. h-kotl...
")
(hyrolo-tests--outline-as-string)))
(hy-test-outline-as-string)))
(hyrolo-next-match)
(should (string= (concat
(hyrolo-tests--hyrolo-section-header kotl-file1)
Expand All @@ -1602,7 +1576,7 @@ body
1a. h-kotl 1
body 1
")
(hyrolo-tests--outline-as-string))))
(hy-test-outline-as-string))))
(kill-buffer hyrolo-display-buffer)
(hy-delete-files-and-buffers hyrolo-file-list))))

Expand Down Expand Up @@ -1636,7 +1610,7 @@ body
"\
1. h-kotl...
")
(hyrolo-tests--outline-as-string))))
(hy-test-outline-as-string))))
(kill-buffer hyrolo-display-buffer)
(hy-delete-files-and-buffers hyrolo-file-list))))

Expand Down Expand Up @@ -1676,7 +1650,7 @@ body
1a. h-kotl 1...
1a1. h-kotl 2...
")
(hyrolo-tests--outline-as-string))))
(hy-test-outline-as-string))))
(kill-buffer hyrolo-display-buffer)
(hy-delete-files-and-buffers hyrolo-file-list))))

Expand Down
45 changes: 45 additions & 0 deletions test/kotl-mode-resources/kotl-file.kotl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
;; -*- Mode: kotl -*-
"Kotl-4.0" ;; file-format

1. A
a

1a. B
b

1a1. C
c

2. D
d

2a. E
e

2a1. F
f


"ben" ;; kvspec:current
11 ;; id-counter
alpha ;; label-type
4 ;; label-min-width
". " ;; label-separator
3 ;; level-indent

;; depth-first kcell attributes
[[0
(creator "mats.lidell@lidells.se" create-time "20261113:09:29:37" id-counter 11)]
[1
(creator "mats.lidell@lidells.se" create-time "20261113:09:29:37")]
[3
(creator "mats.lidell@lidells.se" create-time "20261113:09:29:46")]
[6
(creator "mats.lidell@lidells.se" create-time "20261113:09:29:58")]
[7
(creator "mats.lidell@lidells.se" create-time "20261113:22:27:06")]
[9
(creator "mats.lidell@lidells.se" create-time "20261113:22:27:10")]
[11
(creator "mats.lidell@lidells.se" create-time "20261113:22:27:14")]
nil nil nil nil nil]
Loading
Loading