Skip to content

Commit cc887f9

Browse files
authored
Add koutline tests (#359)
1 parent c5a3632 commit cc887f9

File tree

2 files changed

+63
-16
lines changed

2 files changed

+63
-16
lines changed

ChangeLog

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2023-10-09 Mats Lidell <[email protected]>
2+
3+
* test/kotl-mode-tests.el (kotl-mode-kill-contents)
4+
(kotl-mode-kill-contents-all): Add kotl-tests for cell contents
5+
removal.
6+
17
2023-10-07 Mats Lidell <[email protected]>
28

39
* hsys-org-roam.el: Byte compile. Warning is handled by declaration.

test/kotl-mode-tests.el

+57-16
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
;; Author: Mats Lidell <[email protected]>
44
;;
55
;; Orig-Date: 18-May-21 at 22:14:10
6-
;; Last-Mod: 5-Oct-23 at 21:15:10 by Mats Lidell
6+
;; Last-Mod: 9-Oct-23 at 00:51:28 by Mats Lidell
77
;;
88
;; SPDX-License-Identifier: GPL-3.0-or-later
99
;;
@@ -347,6 +347,31 @@
347347
(should (string= (kcell-view:label (point)) "1a")))
348348
(hy-delete-file-and-buffer kotl-file))))
349349

350+
(ert-deftest kotl-mode-kill-contents ()
351+
"Kotl-mode kill contents shall remove rest of a cell."
352+
(with-temp-buffer
353+
(kotl-mode)
354+
(insert "first line")
355+
(kotl-mode:backward-word)
356+
(should (looking-at-p "line"))
357+
(kotl-mode:kill-contents nil)
358+
(kotl-mode:beginning-of-cell)
359+
(should (looking-at-p "first $"))))
360+
361+
(ert-deftest kotl-mode-kill-contents-all ()
362+
"Kotl-mode kill contents with prefix argument shall remove the cell."
363+
(with-temp-buffer
364+
(kotl-mode)
365+
(insert "first line")
366+
(kotl-mode:backward-word)
367+
(should (looking-at-p "line"))
368+
(let ((transient-mark-mode nil))
369+
;; kotl-mode:kill-contents uses kotl-mode:kill-region which
370+
;; depends on transient-mark-mode
371+
(kotl-mode:kill-contents t))
372+
(kotl-mode:beginning-of-cell)
373+
(should (looking-at-p "$"))))
374+
350375
(ert-deftest kotl-mode-kill-cell ()
351376
"Kotl-mode kill a cell test."
352377
(let ((kotl-file (make-temp-file "hypb" nil ".kotl")))
@@ -762,7 +787,7 @@
762787

763788
(ert-deftest kotl-mode-move-up-from-first-line-shall-message-and-beep ()
764789
"Trying to move up from first line shall beep and output a message.
765-
In non-interactive mode there shall be no beep nor message."
790+
In non interactive mode there shall be no beep (nor message)"
766791
(skip-unless (not noninteractive))
767792
(let ((kotl-file (make-temp-file "hypb" nil ".kotl")))
768793
(unwind-protect
@@ -773,27 +798,36 @@ In non-interactive mode there shall be no beep nor message."
773798
(mock (message "(kotl-mode:previous-line): Beginning of buffer") => t)
774799
(mock (beep) => t)
775800
(funcall-interactively 'kotl-mode:previous-line 1))
776-
;; Non-interactive neither calls message nor beeps, so the mock fails.
777-
(should-error
801+
(should-error ;; Verifies no beep
778802
(with-mock
779803
(mock (beep) => t)
804+
(kotl-mode:previous-line 1)))
805+
(should-error ;; Verifies no message
806+
(with-mock
807+
(mock (message "(kotl-mode:previous-line): Beginning of buffer") => t)
780808
(kotl-mode:previous-line 1))))
781809
(hy-delete-file-and-buffer kotl-file))))
782810

783811
(ert-deftest kotl-mode-move-up-to-first-line ()
784-
"Trying to move up from first line shall beep and output a message.
785-
In non-interactive mode there shall be no beep nor message."
812+
"Move up to first line shall succeed with no beep nor message."
786813
(skip-unless (not noninteractive))
787814
(let ((kotl-file (make-temp-file "hypb" nil ".kotl")))
788815
(unwind-protect
789816
(progn
790817
(find-file kotl-file)
791-
(insert "1\n2")
792-
(funcall-interactively 'kotl-mode:previous-line 1)
818+
(insert "1")
819+
(kotl-mode:newline 1)
820+
(insert "2")
821+
(should-error ;; Verifies no beep
822+
(with-mock
823+
(mock (beep) => t)
824+
(funcall-interactively 'kotl-mode:previous-line 1)))
793825
(should (= (line-number-at-pos) 1))
794-
;; Non-interactive test
795-
(kotl-mode:next-line 1)
796-
(kotl-mode:previous-line 1)
826+
(kotl-mode:next-line 1)
827+
(should-error ;; Verifies no message
828+
(with-mock
829+
(mock (message "(kotl-mode:previous-line): Beginning of buffer") => t)
830+
(funcall-interactively 'kotl-mode:previous-line 1)))
797831
(should (= (line-number-at-pos) 1)))
798832
(hy-delete-file-and-buffer kotl-file))))
799833

@@ -810,10 +844,13 @@ In non-interactive mode there shall be no beep nor message."
810844
(mock (message "(kotl-mode:next-line): End of buffer") => t)
811845
(mock (beep) => t)
812846
(funcall-interactively 'kotl-mode:next-line 1))
813-
;; Non-interactive neither calls message nor beeps, so the mock fails.
814-
(should-error
847+
(should-error ;; Verifies no beep
815848
(with-mock
816849
(mock (beep) => t)
850+
(kotl-mode:next-line 1)))
851+
(should-error ;; Verifies no message
852+
(with-mock
853+
(mock (message "(kotl-mode:next-line): End of buffer") => t)
817854
(kotl-mode:next-line 1))))
818855
(hy-delete-file-and-buffer kotl-file))))
819856

@@ -828,12 +865,16 @@ In non-interactive mode there shall be no beep nor message."
828865
(kotl-mode:newline 1)
829866
(insert "2")
830867
(kotl-mode:beginning-of-buffer)
831-
;; Non interactive does not call neither message nor beep so
832-
;; the mock will fails.
833-
(should-error
868+
(should-error ;; Verifies no beep
834869
(with-mock
835870
(mock (beep) => t)
836871
(funcall-interactively 'kotl-mode:next-line 1)))
872+
(should (kotl-mode:last-line-p))
873+
(kotl-mode:beginning-of-buffer)
874+
(should-error ;; Verifies no message
875+
(with-mock
876+
(mock (message "(kotl-mode:next-line): End of buffer") => t)
877+
(funcall-interactively 'kotl-mode:next-line 1)))
837878
(should (kotl-mode:last-line-p)))
838879
(hy-delete-file-and-buffer kotl-file))))
839880

0 commit comments

Comments
 (0)