diff options
| author | Alan Mackenzie | 2017-02-12 10:59:03 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2017-02-12 10:59:03 +0000 |
| commit | f4d5b687150810129b7a1d5b006e31ccf82b691b (patch) | |
| tree | 4229b13800349032697daae3904dc3773e6b7a80 /test/manual/scroll-tests.el | |
| parent | d5514332d4a6092673ce1f78fadcae0c57f7be64 (diff) | |
| parent | 148100d98319499f0ac6f57b8be08cbd14884a5c (diff) | |
| download | emacs-comment-cache.tar.gz emacs-comment-cache.zip | |
Merge branch 'master' into comment-cachecomment-cache
Diffstat (limited to 'test/manual/scroll-tests.el')
| -rw-r--r-- | test/manual/scroll-tests.el | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/test/manual/scroll-tests.el b/test/manual/scroll-tests.el new file mode 100644 index 00000000000..1167efd6a66 --- /dev/null +++ b/test/manual/scroll-tests.el | |||
| @@ -0,0 +1,130 @@ | |||
| 1 | ;;; scroll-tests.el -- tests for scrolling -*- lexical-binding: t -*- | ||
| 2 | |||
| 3 | ;; Copyright (C) 2017 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; This file is part of GNU Emacs. | ||
| 6 | |||
| 7 | ;; This program is free software; you can redistribute it and/or modify | ||
| 8 | ;; it under the terms of the GNU General Public License as published by | ||
| 9 | ;; the Free Software Foundation, either version 3 of the License, or | ||
| 10 | ;; (at your option) any later version. | ||
| 11 | |||
| 12 | ;; This program is distributed in the hope that it will be useful, | ||
| 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 15 | ;; GNU General Public License for more details. | ||
| 16 | |||
| 17 | ;; You should have received a copy of the GNU General Public License | ||
| 18 | ;; along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 19 | |||
| 20 | ;;; Commentary: | ||
| 21 | |||
| 22 | ;; These are mostly automated ert tests, but they don't work in batch | ||
| 23 | ;; mode which is why they are under test/manual. | ||
| 24 | |||
| 25 | ;;; Code: | ||
| 26 | |||
| 27 | (require 'ert) | ||
| 28 | (eval-when-compile (require 'cl-lib)) | ||
| 29 | |||
| 30 | (defun scroll-tests-up-and-down (margin &optional effective-margin) | ||
| 31 | (unless effective-margin | ||
| 32 | (setq effective-margin margin)) | ||
| 33 | (erase-buffer) | ||
| 34 | (insert (mapconcat #'number-to-string | ||
| 35 | (number-sequence 1 200) "\n")) | ||
| 36 | (goto-char 1) | ||
| 37 | (sit-for 0) | ||
| 38 | (let ((scroll-margin margin) | ||
| 39 | (wstart (window-start))) | ||
| 40 | ;; Stopping before `scroll-margin' so we shouldn't have | ||
| 41 | ;; scrolled. | ||
| 42 | (let ((current-prefix-arg (- (window-text-height) 1 effective-margin))) | ||
| 43 | (call-interactively 'next-line)) | ||
| 44 | (sit-for 0) | ||
| 45 | (should (= wstart (window-start))) | ||
| 46 | ;; Passing `scroll-margin' should trigger scrolling. | ||
| 47 | (call-interactively 'next-line) | ||
| 48 | (sit-for 0) | ||
| 49 | (should (/= wstart (window-start))) | ||
| 50 | ;; Scroll back to top. | ||
| 51 | (let ((current-prefix-arg (window-start))) | ||
| 52 | (call-interactively 'scroll-down-command)) | ||
| 53 | (sit-for 0) | ||
| 54 | (should (= 1 (window-start))))) | ||
| 55 | |||
| 56 | (defmacro scroll-tests-with-buffer-window (&rest body) | ||
| 57 | (declare (debug t)) | ||
| 58 | `(with-temp-buffer | ||
| 59 | (with-selected-window (display-buffer (current-buffer)) | ||
| 60 | ,@body))) | ||
| 61 | |||
| 62 | (ert-deftest scroll-tests-scroll-margin-0 () | ||
| 63 | (skip-unless (not noninteractive)) | ||
| 64 | (scroll-tests-with-buffer-window | ||
| 65 | (scroll-tests-up-and-down 0))) | ||
| 66 | |||
| 67 | (ert-deftest scroll-tests-scroll-margin-negative () | ||
| 68 | "A negative `scroll-margin' should be the same as 0." | ||
| 69 | (skip-unless (not noninteractive)) | ||
| 70 | (scroll-tests-with-buffer-window | ||
| 71 | (scroll-tests-up-and-down -10 0))) | ||
| 72 | |||
| 73 | (ert-deftest scroll-tests-scroll-margin-max () | ||
| 74 | (skip-unless (not noninteractive)) | ||
| 75 | (scroll-tests-with-buffer-window | ||
| 76 | (let ((max-margin (/ (window-text-height) 4))) | ||
| 77 | (scroll-tests-up-and-down max-margin)))) | ||
| 78 | |||
| 79 | (ert-deftest scroll-tests-scroll-margin-over-max () | ||
| 80 | "A `scroll-margin' more than max should be the same as max." | ||
| 81 | (skip-unless (not noninteractive)) | ||
| 82 | (scroll-tests-with-buffer-window | ||
| 83 | (set-window-text-height nil 7) | ||
| 84 | (let ((max-margin (/ (window-text-height) 4))) | ||
| 85 | (scroll-tests-up-and-down (+ max-margin 1) max-margin) | ||
| 86 | (scroll-tests-up-and-down (+ max-margin 2) max-margin)))) | ||
| 87 | |||
| 88 | (defun scroll-tests--point-in-middle-of-window-p () | ||
| 89 | (= (count-lines (window-start) (window-point)) | ||
| 90 | (/ (1- (window-text-height)) 2))) | ||
| 91 | |||
| 92 | (cl-defun scroll-tests--scroll-margin-whole-window (&key with-line-spacing) | ||
| 93 | "Test `maximum-scroll-margin' at 0.5. | ||
| 94 | With a high `scroll-margin', this should keep cursor in the | ||
| 95 | middle of the window." | ||
| 96 | (let ((maximum-scroll-margin 0.5) | ||
| 97 | (scroll-margin 100)) | ||
| 98 | (scroll-tests-with-buffer-window | ||
| 99 | (setq-local line-spacing with-line-spacing) | ||
| 100 | ;; Choose an odd number, so there is one line in the middle. | ||
| 101 | (set-window-text-height nil 7) | ||
| 102 | ;; `set-window-text-height' doesn't count `line-spacing'. | ||
| 103 | (when with-line-spacing | ||
| 104 | (window-resize nil (* line-spacing 7) nil nil 'pixels)) | ||
| 105 | (erase-buffer) | ||
| 106 | (insert (mapconcat #'number-to-string | ||
| 107 | (number-sequence 1 200) "\n")) | ||
| 108 | (goto-char 1) | ||
| 109 | (sit-for 0) | ||
| 110 | (call-interactively 'scroll-up-command) | ||
| 111 | (sit-for 0) | ||
| 112 | (should (scroll-tests--point-in-middle-of-window-p)) | ||
| 113 | (call-interactively 'scroll-up-command) | ||
| 114 | (sit-for 0) | ||
| 115 | (should (scroll-tests--point-in-middle-of-window-p)) | ||
| 116 | (call-interactively 'scroll-down-command) | ||
| 117 | (sit-for 0) | ||
| 118 | (should (scroll-tests--point-in-middle-of-window-p))))) | ||
| 119 | |||
| 120 | (ert-deftest scroll-tests-scroll-margin-whole-window () | ||
| 121 | (skip-unless (not noninteractive)) | ||
| 122 | (scroll-tests--scroll-margin-whole-window)) | ||
| 123 | |||
| 124 | (ert-deftest scroll-tests-scroll-margin-whole-window-line-spacing () | ||
| 125 | ;; `line-spacing' has no effect on tty displays. | ||
| 126 | (skip-unless (display-graphic-p)) | ||
| 127 | (scroll-tests--scroll-margin-whole-window :with-line-spacing 3)) | ||
| 128 | |||
| 129 | |||
| 130 | ;;; scroll-tests.el ends here | ||