Skip to content

Commit

Permalink
[ADD] Test for normal behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
KeyWeeUsr committed Aug 17, 2024
1 parent 6425778 commit 8ec016b
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions typewriter-roll-mode-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,61 @@
(require 'ert)
(require 'typewriter-roll-mode)

(defun typewriter-roll--cursor-line ()
(line-number-at-pos))
(defun typewriter-roll--top-line ()
(line-number-at-pos (window-start)))

(ert-deftest trm-backspace ()
(should (not
(let ((this-command "hello"))
(typewriter-roll--is-backspace))))
(should (let ((this-command 'delete-backward-char))
(typewriter-roll--is-backspace))))

(ert-deftest normal-behavior ()
"Write something until it overflows `fill-column', then scroll it away."
(let ((scroll-margin 0)
(typewriter-roll-keep-in-focus 0))
(with-temp-buffer
(switch-to-buffer (current-buffer))
(let* ((old-win-start (window-start))
(old-win-end (window-end))
(old-text "text text")
(expected-text (format "%s\ntext" old-text)))
;; initial text
(insert old-text)
;; default state
(should (string= (buffer-string) old-text))
(should (eq (typewriter-roll--cursor-line) 1))
(should (eq (typewriter-roll--top-line) 1))

(let ((fill-column 10))
(typewriter-roll-mode)

(typewriter-roll--scroll-main (current-column))
;; default state, not enough chars to fill `fill-column'
(should (string= (buffer-string) old-text))
(should (eq (typewriter-roll--cursor-line) 1))
(should (eq (typewriter-roll--top-line) 1))

(insert " text")
(should (string= (buffer-string) (format "%s text" old-text)))
(should (eq (typewriter-roll--cursor-line) 1))
(should (eq (typewriter-roll--top-line) 1))

;; only after
(typewriter-roll--scroll-main (current-column))
(should (string= (buffer-string) expected-text))
(should (eq (typewriter-roll--cursor-line) 2))
(should (eq (typewriter-roll--top-line) 2))

(insert " ") ; will be removed by filling
(typewriter-roll--scroll-main (current-column))
(should (string= (buffer-string) expected-text))
(should (eq (typewriter-roll--cursor-line) 2))
(should (eq (typewriter-roll--top-line) 2)))))))

(provide 'typewriter-roll-mode-tests)

;;; typewriter-roll-mode-tests.el ends here

0 comments on commit 8ec016b

Please sign in to comment.