Skip to content
Merged
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
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2025-07-31 Mats Lidell <matsl@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 <rsw@gnu.org>

* hpath.el (hpath:external-file-suffixes): Remove old Sun Raster image format
Expand Down
168 changes: 166 additions & 2 deletions test/kotl-mode-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: 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
;;
Expand Down Expand Up @@ -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.
Comment on lines +1256 to +1257
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cell should be added at the start of the outline. i.e. label=1 but is added after i.e. label=2.

(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)

Expand Down