branch: externals/hyperbole
commit def24815ee4503b7350d4995056e58752cb5b014
Author: Mats Lidell <mats.lid...@lidells.se>
Commit: GitHub <nore...@github.com>

    add kotl mode add cell tests (#767)
---
 ChangeLog               |   6 ++
 test/kotl-mode-tests.el | 168 +++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 172 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c8c42aae3e..c35b286e8b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2025-07-31  Mats Lidell  <ma...@gnu.org>
+
+* test/kotl-mode-tests.el (kotl-mode--add-cell)
+    (kotl-mode--add-after-parent, kotl-mode--add-before-parent)
+    (kotl-mode--add-below-parent, kotl-mode--add-child): Add tests.
+
 2025-07-27  Bob Weiner  <r...@gnu.org>
 
 *  hpath.el (hpath:external-file-suffixes): Remove old Sun Raster image format
diff --git a/test/kotl-mode-tests.el b/test/kotl-mode-tests.el
index a60589875f..22622fccf3 100644
--- a/test/kotl-mode-tests.el
+++ b/test/kotl-mode-tests.el
@@ -3,7 +3,7 @@
 ;; Author:       Mats Lidell <ma...@gnu.org>
 ;;
 ;; Orig-Date:    18-May-21 at 22:14:10
-;; Last-Mod:     20-May-25 at 00:38:20 by Mats Lidell
+;; Last-Mod:     31-Jul-25 at 13:57:56 by Mats Lidell
 ;;
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 ;;
@@ -1121,7 +1121,171 @@ marked with :ignore t")
           (should (call-interactively #'kotl-mode:add-prior-cell)))
         (mocklet (((kotl-mode:up-level 1) => nil)
                   ((kotl-mode:add-below-parent 1 nil nil nil) => t))
-          (should (call-interactively #'kotl-mode:add-prior-cell)))))))
+                 (should (call-interactively #'kotl-mode:add-prior-cell)))))))
+
+(ert-deftest kotl-mode--add-cell ()
+  "Verify `kotl-mode:add-cell'."
+  (cl-flet ((init ()
+              (progn (erase-buffer)
+                     (kotl-mode)
+                     (insert "first")
+                     (kotl-mode:add-cell '(4) "child"))))
+    (with-temp-buffer
+      (ert-info ("After init. Point at beginning of child cell")
+        (init)
+        (should (looking-at-p "child"))
+        (should (= (kcell-view:level) 2)))
+      (ert-info ("Error: Called with non numeric level")
+        (init)
+        (should-error (kotl-mode:add-cell "not numeric")))
+      (ert-info ("when = 0, add as the parent’s first child cell")
+        (init)
+        (kotl-mode:add-cell 0 "first child cell")
+        (should (kotl-mode:first-cell-p)))
+      (ert-info ("when < 0, add that number of cells as preceding siblings" 
:prefix "1: ")
+        (init)
+        (kotl-mode:add-cell -1 "preceding sibling")
+        (should (= (kcell-view:level) 2))
+        (should (string= (kcell-view:label (point)) "1a")))
+      (ert-info ("when < 0, add that number of cells as preceding siblings" 
:prefix "2: ")
+        (init)
+        (kotl-mode:add-cell -2 "preceding siblings")
+        (should (= (kcell-view:level) 2))
+        (should (string= (kcell-view:label (point)) "1b")))
+      (ert-info ("when '(4) (universal arg, C-u), add as the first child of 
the current cell")
+        (init)
+        (kotl-mode:add-cell '(4) "first child")
+        (should (= (kcell-view:level) 3))
+        (should (string= (kcell-view:label (point)) "1a1")))
+      (ert-info ("when > 0 or nil (meaning 1), add that number of cells as 
following siblings" :prefix "1: ")
+        (init)
+        (kotl-mode:add-cell 1 "following sibling")
+        (should (equal (kcell-view:level) 2))
+        (should (string= (kcell-view:label (point)) "1b")))
+      (ert-info ("when > 0 or nil (meaning 1), add that number of cells as 
following siblings" :prefix "2: ")
+        (init)
+        (kotl-mode:add-cell 2 "following siblings")
+        (should (equal (kcell-view:level) 2))
+        (should (string= (kcell-view:label (point)) "1c"))))))
+
+(ert-deftest kotl-mode--add-after-parent ()
+  "Verify `kotl-mode:add-after-parent'."
+  (cl-flet ((init ()
+              (progn (erase-buffer)
+                     (kotl-mode)
+                     (insert "first")
+                     (kotl-mode:add-cell '(4) "child"))))
+    (with-temp-buffer
+      (ert-info ("After init. Point at beginning of child cell")
+        (init)
+        (should (looking-at-p "child"))
+        (should (= (kcell-view:level) 2)))
+      (ert-info ("Error: Called with non positive argument")
+        (init)
+        (should-error (kotl-mode:add-after-parent 0)))
+      (ert-info ("If on the first level of the outline, insert cells at the 
start of the outline.")
+        (init)
+        (kotl-mode:beginning-of-buffer)
+        (kotl-mode:add-after-parent 1 "first child cell")
+        (should (string= "first child cell" (kcell-view:contents)))
+        (should (kotl-mode:first-cell-p)))
+      (ert-info ("Add succeeding sibling cells to the current cell’s parent" 
:prefix "1: ")
+        (init)
+        (kotl-mode:add-after-parent 1 "succeeding sibling")
+        (should (= (kcell-view:level) 1))
+        (should (string= (kcell-view:label (point)) "2")))
+      (ert-info ("Add succeeding sibling cells to the current cell’s parent" 
:prefix "2: ")
+        (init)
+        (kotl-mode:add-after-parent 2 "succeeding sibling")
+        (should (= (kcell-view:level) 1))
+        (should (string= (kcell-view:label (point)) "3"))))))
+
+(ert-deftest kotl-mode--add-below-parent ()
+  "Verify `kotl-mode:add-below-parent'."
+  (cl-flet ((init ()
+              (progn (erase-buffer)
+                     (kotl-mode)
+                     (insert "first")
+                     (kotl-mode:add-cell '(4) "child"))))
+    (with-temp-buffer
+      (ert-info ("After init. Point at beginning of child cell")
+        (init)
+        (should (looking-at-p "child"))
+        (should (= (kcell-view:level) 2)))
+      (ert-info ("Error: Called with non positive argument")
+        (init)
+        (should-error (kotl-mode:add-below-parent 0)))
+      (ert-info ("If on the first level of the outline, insert cells at the 
start of the outline.")
+        (init)
+        (kotl-mode:beginning-of-buffer)
+        (kotl-mode:add-below-parent 1 "first child cell")
+        (should (string= "first child cell" (kcell-view:contents)))
+        (should (kotl-mode:first-cell-p)))
+      (ert-info ("Add new cells as initial children of the current cell’s 
parent." :prefix "1: ")
+        (init)
+        (kotl-mode:add-below-parent 1 "initial child")
+        (should (= (kcell-view:level) 2))
+        (should (string= (kcell-view:label (point)) "1a")))
+      (ert-info ("Add new cells as initial children of the current cell’s 
parent." :prefix "2: ")
+        (init)
+        (kotl-mode:add-below-parent 2 "initial children")
+        (should (= (kcell-view:level) 2))
+        (should (string= (kcell-view:label (point)) "1b"))))))
+
+(ert-deftest kotl-mode--add-before-parent ()
+  "Verify `kotl-mode:add-before-parent'."
+  (cl-flet ((init ()
+              (progn (erase-buffer)
+                     (kotl-mode)
+                     (insert "first")
+                     (kotl-mode:add-cell '(4) "child")
+                     (kotl-mode:add-cell '(4) "child of child"))))
+    (with-temp-buffer
+      (ert-info ("After init. Point at beginning of child of child cell")
+        (init)
+        (should (looking-at-p "child of child"))
+        (should (= (kcell-view:level) 3)))
+      (ert-info ("Error: Called with non positive argument")
+        (init)
+        (should-error (kotl-mode:add-before-parent 0)))
+      (ert-info ("If on the first level of the outline, insert cells at the 
start of the outline.")
+        (init)
+        (kotl-mode:beginning-of-buffer)
+        (should (= (kcell-view:level) 1))
+        (kotl-mode:add-before-parent 1 "start of outline")
+        ;; (should (kotl-mode:first-cell-p))) ;; <= EXPECTED
+        (should (string= (kcell-view:label (point)) "2"))) ;; FAIL: Actual.
+      (ert-info ("Add prior sibling cells to the current cell’s parent")
+        (init)
+        (kotl-mode:add-before-parent 1 "add prior sibling to current cells 
parent")
+        (should (= (kcell-view:level) 2))
+        (should (string= (kcell-view:label (point)) "1a"))))))
+
+(ert-deftest kotl-mode--add-child ()
+  "Verify `kotl-mode:add-child'."
+  (cl-flet ((init ()
+              (progn (erase-buffer)
+                     (kotl-mode)
+                     (insert "first")
+                     (kotl-mode:add-cell '(4) "child"))))
+    (with-temp-buffer
+      (ert-info ("After init. Point at beginning of child of child cell")
+        (init)
+        (should (looking-at-p "child"))
+        (should (= (kcell-view:level) 2)))
+      (ert-info ("Error: Called with non positive argument")
+        (init)
+        (should-error (kotl-mode:add-child 0)))
+      (ert-info ("Add new cells as children of the current cell" :prefix "1: ")
+        (init)
+        (kotl-mode:add-child 1 "new child")
+        (should (= (kcell-view:level) 3))
+        (should (string= (kcell-view:label (point)) "1a1")))
+      (ert-info ("Add new cells as children of the current cell" :prefix "2: ")
+        (init)
+        (kotl-mode:add-child 2 "new children")
+        (should (= (kcell-view:level) 3))
+        (should (string= (kcell-view:label (point)) "1a2"))))))
 
 (provide 'kotl-mode-tests)
 

Reply via email to