diff --git a/test/hy-test-helpers.el b/test/hy-test-helpers.el index 515a7b8b..88f6c82d 100644 --- a/test/hy-test-helpers.el +++ b/test/hy-test-helpers.el @@ -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)) @@ -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 diff --git a/test/hyrolo-tests.el b/test/hyrolo-tests.el index 4e72e4fd..0d5bba27 100644 --- a/test/hyrolo-tests.el +++ b/test/hyrolo-tests.el @@ -3,7 +3,7 @@ ;; Author: Mats Lidell ;; ;; 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 ;; @@ -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)) @@ -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)) @@ -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)) @@ -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)))) @@ -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)) @@ -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)) @@ -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)) @@ -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)) @@ -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)) @@ -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)))) @@ -1487,13 +1461,13 @@ 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)) @@ -1501,7 +1475,7 @@ body... (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 @@ -1514,10 +1488,10 @@ 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)) @@ -1525,7 +1499,7 @@ body (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 @@ -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)))) @@ -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)))) @@ -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) @@ -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)))) @@ -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)))) @@ -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)))) diff --git a/test/kotl-mode-resources/kotl-file.kotl b/test/kotl-mode-resources/kotl-file.kotl new file mode 100644 index 00000000..5453dd84 --- /dev/null +++ b/test/kotl-mode-resources/kotl-file.kotl @@ -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] diff --git a/test/kotl-mode-resources/kotl-mode-org-cycling.eld b/test/kotl-mode-resources/kotl-mode-org-cycling.eld new file mode 100644 index 00000000..96a0aa7f --- /dev/null +++ b/test/kotl-mode-resources/kotl-mode-org-cycling.eld @@ -0,0 +1,138 @@ +;; Resource used in +;; "../kotl-mode-tests.el#kotl-mode--org-cycling" +;; Initial buffer contents: "kotl-file.kotl" +;; Below list of (Test name, key, expected visible buffer contents) + +( + ("FOLDED" + "" + "\ + 1. A... + + 2. D + d + + 2a. E + e + + 2a1. F + f + +") + + ("CHILDREN" + "" + "\ + 1. A... + + 1a. B... + + 2. D + d + + 2a. E + e + + 2a1. F + f + +") + + ("SUBTREE" + "" + "\ + 1. A + a + + 1a. B + b + + 1a1. C + c + + 2. D + d + + 2a. E + e + + 2a1. F + f + +") + + ("Back to FOLDED" + "" + "\ + 1. A... + + 2. D + d + + 2a. E + e + + 2a1. F + f + +") + + ("OVERVIEW" + "S-" + "\ + 1. A... + + 2. D... + +") + + ("CONTENTS" + "S-" + "\ + 1. A... + + 1a. B... + + 1a1. C... + + 2. D... + + 2a. E... + + 2a1. F... + +") + + ("SHOW ALL" + "S-" + "\ + 1. A + a + + 1a. B + b + + 1a1. C + c + + 2. D + d + + 2a. E + e + + 2a1. F + f + +") + + ("Back to OVERVIEW" + "S-" + "\ + 1. A... + + 2. D... + +") + +) diff --git a/test/kotl-mode-tests.el b/test/kotl-mode-tests.el index 3700524d..f7dd4f3f 100644 --- a/test/kotl-mode-tests.el +++ b/test/kotl-mode-tests.el @@ -3,7 +3,7 @@ ;; Author: Mats Lidell ;; ;; Orig-Date: 18-May-21 at 22:14:10 -;; Last-Mod: 7-Nov-26 at 00:19:59 by Mats Lidell +;; Last-Mod: 14-Nov-26 at 00:36:03 by Mats Lidell ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -1552,6 +1552,29 @@ marked with :ignore t") (should (= p (point))) (should (looking-at-p "2")))))))) +(ert-deftest kotl-mode--org-cycling () + "Verify org style cycling works. +Go through a sequence of cycle states. Verify the visible outline for +each state. Sequence and expected states are defined in +kotl-mode-org-cycling.eld resource file." + (let ((kotl-file (ert-resource-file "kotl-file.kotl")) + (resource (hy-test-get-resource-as-sexp + (ert-resource-file "kotl-mode-org-cycling.eld")))) + (with-temp-buffer + (insert-file kotl-file) + (kotl-mode) + (let ((kotl-mode:tab-flag 'cycle) + (kotl-mode:emulate-tab nil) + (kotl-mode:indent-tabs-mode t)) + (save-window-excursion + (with-selected-window (display-buffer (current-buffer)) + (dolist (v resource) + (pcase-let ((`(,name ,key ,expected) v)) + (when key + (execute-kbd-macro (kbd key))) + (ert-info (name) + (should (string= (hy-test-outline-as-string) expected))))))))))) + (provide 'kotl-mode-tests) ;; This file can't be byte-compiled without the `el-mock' package diff --git a/test/test-helpers-resources/test-helpers.eld b/test/test-helpers-resources/test-helpers.eld new file mode 100644 index 00000000..85a84e79 --- /dev/null +++ b/test/test-helpers-resources/test-helpers.eld @@ -0,0 +1,3 @@ +;; Test resource + +(a b) diff --git a/test/test-helpers-tests.el b/test/test-helpers-tests.el index 9a3080a6..75dd687e 100644 --- a/test/test-helpers-tests.el +++ b/test/test-helpers-tests.el @@ -3,7 +3,7 @@ ;; Author: Mats Lidell ;; ;; Orig-Date: 20-Jan-25 at 20:22:05 -;; Last-Mod: 21-Jan-25 at 17:02:12 by Mats Lidell +;; Last-Mod: 14-Nov-26 at 00:36:03 by Mats Lidell ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -40,5 +40,9 @@ then gives correct answers only for ASCII characters." (should (char-uppercase-p (string-to-char (substring ww 0 1)))) (should-not (char-uppercase-p (string-to-char (substring ww 1 2)))))))) +(ert-deftest test-helpers-test--read-resource-file () + "Verify `hy-test-get-resource-as-sexp' can read the resource." + (should (equal '(a b) (hy-test-get-resource-as-sexp (ert-resource-file "test-helpers.eld"))))) + (provide 'test-helpers-tests) ;;; test-helpers-tests.el ends here