Skip to content

Commit

Permalink
[ADD] Test for typewriter-roll-prefer-scroll-margin
Browse files Browse the repository at this point in the history
typewriter-roll-prefer-scroll-margin | t
typewriter-roll-keep-in-focus        | 0 (and ignored)
scroll-margin                        | 0
last cursor line                     | 2
last top line                        | 2
  • Loading branch information
KeyWeeUsr committed Aug 17, 2024
1 parent 21978dc commit 1c829f6
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions typewriter-roll-mode-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,59 @@ but keep one more line visible above."
(should (eq (typewriter-roll--cursor-line) 2))
(should (eq (typewriter-roll--top-line) 1)))))))

(ert-deftest bug-1-prefer-scroll-margin-zero ()
"https://github.com/KeyWeeUsr/typewriter-roll-mode/issues/1
`typewriter-roll-keep-in-focus' is zero, `scroll-margin' is
preferred and zero. The cursor should move to the next line and
that line should be the only one visible on top."
(let ((scroll-margin 0)
(typewriter-roll-keep-in-focus 0)
(typewriter-roll-prefer-scroll-margin t))
(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, cursor on line 1, top is line 1
(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'
;; keep cursor on line 1, keep top on line 1
(should (string= (buffer-string) old-text))
(should (eq (typewriter-roll--cursor-line) 1))
(should (eq (typewriter-roll--top-line) 1))

;; text is inserted, --scroll-main not called yet
(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))

;; after --scroll-main call
;; move cursor to line 2, move top to line 2
(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))

;; space will be removed by filling, keep previous state
(insert " ")
(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 1c829f6

Please sign in to comment.