branch: externals/hyperbole commit 5d27b22695139ad9a573fb8d23a7172567b971a0 Author: Mats Lidell <mats.lid...@lidells.se> Commit: Mats Lidell <mats.lid...@lidells.se>
Add overview and top-level outline tests --- ChangeLog | 12 +++++++ test/hyrolo-tests.el | 90 +++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 97 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3a7c5ce484..80072b9773 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2024-02-12 Mats Lidell <ma...@gnu.org> + +* test/hyrolo-tests.el (hyrolo-tests--modify-test-data): Helper for + modifying org test data for outline and markdown files. + (hyrolo-tests--outline-content-otl) + (hyrolo-tests--outline-content-md): Use hyrolo-tests--modify-test-data. + (hyrolo-tests---org-expected-outline-for-top-level) + (hyrolo-tests---org-expected-outline-for-overview): Add expected + outline for org test data. + (hyrolo-tests--top-level-outline-for-all-file-types): Test top level outline. + (hyrolo-tests--overview-outline-for-all-file-types): Test overview outline. + 2024-02-08 Mats Lidell <ma...@gnu.org> * test/hyrolo-tests.el: Make hide tests more forgiving about hiding diff --git a/test/hyrolo-tests.el b/test/hyrolo-tests.el index 82edf07c59..5a8c19749c 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: 8-Feb-24 at 13:57:13 by Mats Lidell +;; Last-Mod: 12-Feb-24 at 22:53:26 by Mats Lidell ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -991,14 +991,19 @@ body " "Outline content for org files.") +(defun hyrolo-tests--modify-test-data (star type str) + "Replace * with STAR and org with TYPE in STR. +Useful for creating outline and markdown test data from org examples." + (replace-regexp-in-string + "org" type + (replace-regexp-in-string (regexp-quote "*") star str))) + (defconst hyrolo-tests--outline-content-otl - (replace-regexp-in-string "org" "otl" hyrolo-tests--outline-content-org) + (hyrolo-tests--modify-test-data "*" "otl" hyrolo-tests--outline-content-org) "Outline content for otl files.") (defconst hyrolo-tests--outline-content-md - (replace-regexp-in-string - (regexp-quote "*") "#" - (replace-regexp-in-string "org" "md" hyrolo-tests--outline-content-org)) + (hyrolo-tests--modify-test-data "#" "md" hyrolo-tests--outline-content-org) "Outline content for markdown files.") (ert-deftest hyrolo-tests--forward-same-level-org-level2 () @@ -1366,5 +1371,80 @@ body (kill-buffer hyrolo-display-buffer) (hy-delete-files-and-buffers hyrolo-file-list)))) +(defconst hyrolo-tests---org-expected-outline-for-top-level + "\ +* h-org 1... +* h-org 2... +" + "Expected outline for org test data.") + +(ert-deftest hyrolo-tests--top-level-outline-for-all-file-types () + "Verify `hyrolo-top-level' shows first level for all supported file types." + (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 "h-kotl" "body" 2)) + (hyrolo-file-list (list org-file1 otl-file1 md-file1 kotl-file1))) + (unwind-protect + (progn + (hyrolo-grep "body") + (hyrolo-top-level) + + (should (string= + (concat (hyrolo-tests--hyrolo-section-header org-file1) + hyrolo-tests---org-expected-outline-for-top-level + (hyrolo-tests--hyrolo-section-header otl-file1) + (hyrolo-tests--modify-test-data "*" "otl" hyrolo-tests---org-expected-outline-for-top-level) + (hyrolo-tests--hyrolo-section-header md-file1) + (hyrolo-tests--modify-test-data "#" "md" hyrolo-tests---org-expected-outline-for-top-level) + (hyrolo-tests--hyrolo-section-header kotl-file1) + "\ + 1. h-kotl... + 1a. h-kotl 1... +") + (hyrolo-tests--outline-as-string)))) + (kill-buffer hyrolo-display-buffer) + (hy-delete-files-and-buffers hyrolo-file-list)))) + +(defconst hyrolo-tests---org-expected-outline-for-overview + "\ +* h-org 1... +** h-org 1.1... +** h-org 1.2... +*** h-org 1.2.1... +* h-org 2... +** h-org-2.1... +" + "Expected outline for org test data.") + +(ert-deftest hyrolo-tests--overview-outline-for-all-file-types () + "Verify `hyrolo-overview' shows all level headings for all supported file types." + (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 "h-kotl" "body" 2)) + (hyrolo-file-list (list org-file1 otl-file1 md-file1 kotl-file1))) + (unwind-protect + (progn + (hyrolo-grep "body") + (hyrolo-overview nil) + + (should (string= + (concat (hyrolo-tests--hyrolo-section-header org-file1) + hyrolo-tests---org-expected-outline-for-overview + (hyrolo-tests--hyrolo-section-header otl-file1) + (hyrolo-tests--modify-test-data "*" "otl" hyrolo-tests---org-expected-outline-for-overview) + (hyrolo-tests--hyrolo-section-header md-file1) + (hyrolo-tests--modify-test-data "#" "md" hyrolo-tests---org-expected-outline-for-overview) + (hyrolo-tests--hyrolo-section-header kotl-file1) + "\ + 1. h-kotl... + 1a. h-kotl 1... + 1a1. h-kotl 2... +") + (hyrolo-tests--outline-as-string)))) + (kill-buffer hyrolo-display-buffer) + (hy-delete-files-and-buffers hyrolo-file-list)))) + (provide 'hyrolo-tests) ;;; hyrolo-tests.el ends here