From 4fd221077f922492e82ee44502ca29185ce12fd4 Mon Sep 17 00:00:00 2001 From: Mats Lidell Date: Tue, 29 Jul 2025 15:45:56 +0200 Subject: [PATCH 1/7] Add test for kotl-mode:add-cell --- ChangeLog | 4 ++++ test/kotl-mode-tests.el | 51 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index c8c42aae..4e5dd7c0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2025-07-29 Mats Lidell + +* test/kotl-mode-tests.el (kotl-mode--add-cell): Add test. + 2025-07-27 Bob Weiner * 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 a6058987..c583f917 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: 20-May-25 at 00:38:20 by Mats Lidell +;; Last-Mod: 29-Jul-25 at 15:45:03 by Mats Lidell ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -1121,7 +1121,54 @@ 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 ("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)) ;; FAIL!? Goes to beginning of kotl, not first cell of parent! + ;; Expected: + ;; (should (= (kcell-view:level) 2)) + ;; (should (looking-at-p "first child cell")) + ;; (should (string= (kcell-view:label (point)) "1a"))) + ) + (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")))))) (provide 'kotl-mode-tests) From d5f675e7d8381973fa0a016d1fc360ce040b05f2 Mon Sep 17 00:00:00 2001 From: Mats Lidell Date: Tue, 29 Jul 2025 16:06:10 +0200 Subject: [PATCH 2/7] Add error cases --- test/kotl-mode-tests.el | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/kotl-mode-tests.el b/test/kotl-mode-tests.el index c583f917..23b4fc34 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: 29-Jul-25 at 15:45:03 by Mats Lidell +;; Last-Mod: 29-Jul-25 at 16:05:57 by Mats Lidell ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -1135,6 +1135,9 @@ marked with :ignore t") (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") @@ -1144,6 +1147,11 @@ marked with :ignore t") ;; (should (looking-at-p "first child cell")) ;; (should (string= (kcell-view:label (point)) "1a"))) ) + ;; FAIL for same reason as above. Adds as first cell even if at level 1. + ;; (ert-info ("when = 0, add as the parent’s first child cell" :prefix "Error case. No parent: ") + ;; (init) + ;; (kotl-mode:beginning-of-buffer) + ;; (should-error (kotl-mode:add-cell 0 "first child cell"))) (ert-info ("when < 0, add that number of cells as preceding siblings" :prefix "1: ") (init) (kotl-mode:add-cell -1 "preceding sibling") From 4a1c7a9da751522124c57eeeb542d3d5b973af5a Mon Sep 17 00:00:00 2001 From: Mats Lidell Date: Wed, 30 Jul 2025 23:55:48 +0200 Subject: [PATCH 3/7] Add test for kotl-mode:add-after-parent --- test/kotl-mode-tests.el | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/test/kotl-mode-tests.el b/test/kotl-mode-tests.el index 23b4fc34..19fe9ff4 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: 29-Jul-25 at 16:05:57 by Mats Lidell +;; Last-Mod: 30-Jul-25 at 23:55:27 by Mats Lidell ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -1178,6 +1178,38 @@ marked with :ignore t") (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")))))) + (provide 'kotl-mode-tests) ;; This file can't be byte-compiled without the `el-mock' package From b27df7b1d15e7c3e4c31a25c0377e5262d9496c0 Mon Sep 17 00:00:00 2001 From: Mats Lidell Date: Thu, 31 Jul 2025 12:53:27 +0200 Subject: [PATCH 4/7] Remove comment about strange behavior and not possible error case Test the current behavior and leave discussion of changed behavior outside of the PR. --- test/kotl-mode-tests.el | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/test/kotl-mode-tests.el b/test/kotl-mode-tests.el index 19fe9ff4..a842960d 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: 30-Jul-25 at 23:55:27 by Mats Lidell +;; Last-Mod: 31-Jul-25 at 12:53:10 by Mats Lidell ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -1141,17 +1141,7 @@ marked with :ignore t") (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)) ;; FAIL!? Goes to beginning of kotl, not first cell of parent! - ;; Expected: - ;; (should (= (kcell-view:level) 2)) - ;; (should (looking-at-p "first child cell")) - ;; (should (string= (kcell-view:label (point)) "1a"))) - ) - ;; FAIL for same reason as above. Adds as first cell even if at level 1. - ;; (ert-info ("when = 0, add as the parent’s first child cell" :prefix "Error case. No parent: ") - ;; (init) - ;; (kotl-mode:beginning-of-buffer) - ;; (should-error (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") From 9b79f268984a583ad633f06e7f4478743c91c38c Mon Sep 17 00:00:00 2001 From: Mats Lidell Date: Thu, 31 Jul 2025 13:21:03 +0200 Subject: [PATCH 5/7] Add kotl-mode--add-before-parent test --- test/kotl-mode-tests.el | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/test/kotl-mode-tests.el b/test/kotl-mode-tests.el index a842960d..0c89525d 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: 31-Jul-25 at 12:53:10 by Mats Lidell +;; Last-Mod: 31-Jul-25 at 13:20:37 by Mats Lidell ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -1131,7 +1131,7 @@ marked with :ignore t") (insert "first") (kotl-mode:add-cell '(4) "child")))) (with-temp-buffer - (ert-info ("After init point at beginning of child cell") + (ert-info ("After init. Point at beginning of child cell") (init) (should (looking-at-p "child")) (should (= (kcell-view:level) 2))) @@ -1176,7 +1176,7 @@ marked with :ignore t") (insert "first") (kotl-mode:add-cell '(4) "child")))) (with-temp-buffer - (ert-info ("After init point at beginning of child cell") + (ert-info ("After init. Point at beginning of child cell") (init) (should (looking-at-p "child")) (should (= (kcell-view:level) 2))) @@ -1200,6 +1200,35 @@ marked with :ignore t") (should (= (kcell-view:level) 1)) (should (string= (kcell-view:label (point)) "3")))))) +(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")))))) + (provide 'kotl-mode-tests) ;; This file can't be byte-compiled without the `el-mock' package From fffaa8528d6ba551f2b247780f086321d1584ff7 Mon Sep 17 00:00:00 2001 From: Mats Lidell Date: Thu, 31 Jul 2025 13:59:06 +0200 Subject: [PATCH 6/7] Tests kotl-mode--add-before-parent, kotl-mode--kotl-mode--add-child --- test/kotl-mode-tests.el | 62 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/test/kotl-mode-tests.el b/test/kotl-mode-tests.el index 0c89525d..22622fcc 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: 31-Jul-25 at 13:20:37 by Mats Lidell +;; Last-Mod: 31-Jul-25 at 13:57:56 by Mats Lidell ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -1200,6 +1200,38 @@ marked with :ignore t") (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 () @@ -1228,7 +1260,33 @@ marked with :ignore t") (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) ;; This file can't be byte-compiled without the `el-mock' package From d0fb119c20397b1358267797fedbcae25a59cecc Mon Sep 17 00:00:00 2001 From: Mats Lidell Date: Thu, 31 Jul 2025 14:00:08 +0200 Subject: [PATCH 7/7] Update ChangeLog --- ChangeLog | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4e5dd7c0..c35b286e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,8 @@ -2025-07-29 Mats Lidell +2025-07-31 Mats Lidell -* test/kotl-mode-tests.el (kotl-mode--add-cell): Add test. +* 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