diff options
| author | Stefan Monnier | 2022-09-25 16:15:16 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2022-09-25 16:15:16 -0400 |
| commit | 650c20f1ca4e07591a727e1cfcc74b3363d15985 (patch) | |
| tree | 85d11f6437cde22f410c25e0e5f71a3131ebd07d /test/src/buffer-tests.el | |
| parent | 8869332684c2302b5ba1ead4568bbc7ba1c0183e (diff) | |
| parent | 4b85ae6a24380fb67a3315eaec9233f17a872473 (diff) | |
| download | emacs-650c20f1ca4e07591a727e1cfcc74b3363d15985.tar.gz emacs-650c20f1ca4e07591a727e1cfcc74b3363d15985.zip | |
Merge 'master' into noverlay
Diffstat (limited to 'test/src/buffer-tests.el')
| -rw-r--r-- | test/src/buffer-tests.el | 823 |
1 files changed, 651 insertions, 172 deletions
diff --git a/test/src/buffer-tests.el b/test/src/buffer-tests.el index 153aea3a20b..a12d15bc798 100644 --- a/test/src/buffer-tests.el +++ b/test/src/buffer-tests.el | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; buffer-tests.el --- tests for buffer.c functions -*- lexical-binding: t -*- | 1 | ;;; buffer-tests.el --- tests for buffer.c functions -*- lexical-binding: t -*- |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 2015-2017 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 2015-2022 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; This file is part of GNU Emacs. | 5 | ;; This file is part of GNU Emacs. |
| 6 | 6 | ||
| @@ -21,6 +21,201 @@ | |||
| 21 | 21 | ||
| 22 | (require 'ert) | 22 | (require 'ert) |
| 23 | (require 'seq) | 23 | (require 'seq) |
| 24 | (require 'ert-x) | ||
| 25 | (require 'cl-lib) | ||
| 26 | (require 'let-alist) | ||
| 27 | |||
| 28 | (defun overlay-tests-start-recording-modification-hooks (overlay) | ||
| 29 | "Start recording modification hooks on OVERLAY. | ||
| 30 | |||
| 31 | Always overwrites the `insert-in-front-hooks', | ||
| 32 | `modification-hooks' and `insert-behind-hooks' properties. Any | ||
| 33 | recorded history from a previous call is erased. | ||
| 34 | |||
| 35 | The history is stored in a property on the overlay itself. Call | ||
| 36 | `overlay-tests-get-recorded-modification-hooks' to retrieve the | ||
| 37 | recorded calls conveniently." | ||
| 38 | (dolist (hooks-property '(insert-in-front-hooks | ||
| 39 | modification-hooks | ||
| 40 | insert-behind-hooks)) | ||
| 41 | (overlay-put | ||
| 42 | overlay | ||
| 43 | hooks-property | ||
| 44 | (list (lambda (ov &rest args) | ||
| 45 | (message " %S called on %S with args %S" hooks-property ov args) | ||
| 46 | (should inhibit-modification-hooks) | ||
| 47 | (should (eq ov overlay)) | ||
| 48 | (push (list hooks-property args) | ||
| 49 | (overlay-get overlay | ||
| 50 | 'recorded-modification-hook-calls))))) | ||
| 51 | (overlay-put overlay 'recorded-modification-hook-calls nil))) | ||
| 52 | |||
| 53 | (defun overlay-tests-get-recorded-modification-hooks (overlay) | ||
| 54 | "Extract the recorded calls made to modification hooks on OVERLAY. | ||
| 55 | |||
| 56 | Must be preceded by a call to | ||
| 57 | `overlay-tests-start-recording-modification-hooks' on OVERLAY. | ||
| 58 | |||
| 59 | Returns a list. Each element of the list represents a recorded | ||
| 60 | call to a particular modification hook. | ||
| 61 | |||
| 62 | Each call is itself a sub-list where the first element is a | ||
| 63 | symbol matching the modification hook property (one of | ||
| 64 | `insert-in-front-hooks', `modification-hooks' or | ||
| 65 | `insert-behind-hooks') and the second element is the list of | ||
| 66 | arguments passed to the hook. The first hook argument, the | ||
| 67 | overlay itself, is omitted to make test result verification | ||
| 68 | easier." | ||
| 69 | (reverse (overlay-get overlay | ||
| 70 | 'recorded-modification-hook-calls))) | ||
| 71 | |||
| 72 | (ert-deftest overlay-modification-hooks () | ||
| 73 | "Test the basic functionality of overlay modification hooks. | ||
| 74 | |||
| 75 | This exercises hooks registered on the `insert-in-front-hooks', | ||
| 76 | `modification-hooks' and `insert-behind-hooks' overlay | ||
| 77 | properties." | ||
| 78 | ;; This is a data driven test loop. Each test case is described | ||
| 79 | ;; by an alist. The test loop initializes a new temporary buffer | ||
| 80 | ;; for each case, creates an overlay, registers modification hooks | ||
| 81 | ;; on the overlay, modifies the buffer, and then verifies which | ||
| 82 | ;; modification hooks (if any) were called for the overlay, as | ||
| 83 | ;; well as which arguments were passed to the hooks. | ||
| 84 | ;; | ||
| 85 | ;; The following keys are available in the alist: | ||
| 86 | ;; | ||
| 87 | ;; `buffer-text': the initial buffer text of the temporary buffer. | ||
| 88 | ;; Defaults to "1234". | ||
| 89 | ;; | ||
| 90 | ;; `overlay-beg' and `overlay-end': the begin and end positions of | ||
| 91 | ;; the overlay under test. Defaults to 2 and 4 respectively. | ||
| 92 | ;; | ||
| 93 | ;; `insert-at': move to the given position and insert the string | ||
| 94 | ;; "x" into the test case's buffer. | ||
| 95 | ;; | ||
| 96 | ;; `replace': replace the first occurrence of the given string in | ||
| 97 | ;; the test case's buffer with "x". The test will fail if the | ||
| 98 | ;; string is not found. | ||
| 99 | ;; | ||
| 100 | ;; `expected-calls': a description of the expected buffer | ||
| 101 | ;; modification hooks. See | ||
| 102 | ;; `overlay-tests-get-recorded-modification-hooks' for the format. | ||
| 103 | ;; May be omitted, in which case the test will insist that no | ||
| 104 | ;; modification hooks are called. | ||
| 105 | ;; | ||
| 106 | ;; The test will fail itself in the degenerate case where no | ||
| 107 | ;; buffer modifications are requested. | ||
| 108 | (dolist (test-case | ||
| 109 | '( | ||
| 110 | ;; Remember that the default buffer text is "1234" and | ||
| 111 | ;; the default overlay begins at position 2 and ends at | ||
| 112 | ;; position 4. Most of the test cases below assume | ||
| 113 | ;; this. | ||
| 114 | |||
| 115 | ;; TODO: (info "(elisp) Special Properties") says this | ||
| 116 | ;; about `modification-hooks': "Furthermore, insertion | ||
| 117 | ;; will not modify any existing character, so this hook | ||
| 118 | ;; will only be run when removing some characters, | ||
| 119 | ;; replacing them with others, or changing their | ||
| 120 | ;; text-properties." So, why are modification-hooks | ||
| 121 | ;; being called when inserting at position 3 below? | ||
| 122 | ((insert-at . 1)) | ||
| 123 | ((insert-at . 2) | ||
| 124 | (expected-calls . ((insert-in-front-hooks (nil 2 2)) | ||
| 125 | (insert-in-front-hooks (t 2 3 0))))) | ||
| 126 | ((insert-at . 3) | ||
| 127 | (expected-calls . ((modification-hooks (nil 3 3)) | ||
| 128 | (modification-hooks (t 3 4 0))))) | ||
| 129 | ((insert-at . 4) | ||
| 130 | (expected-calls . ((insert-behind-hooks (nil 4 4)) | ||
| 131 | (insert-behind-hooks (t 4 5 0))))) | ||
| 132 | ((insert-at . 5)) | ||
| 133 | |||
| 134 | ;; Replacing text never calls `insert-in-front-hooks' | ||
| 135 | ;; or `insert-behind-hooks'. It calls | ||
| 136 | ;; `modification-hooks' if the overlay covers any text | ||
| 137 | ;; that has changed. | ||
| 138 | ((replace . "1")) | ||
| 139 | ((replace . "2") | ||
| 140 | (expected-calls . ((modification-hooks (nil 2 3)) | ||
| 141 | (modification-hooks (t 2 3 1))))) | ||
| 142 | ((replace . "3") | ||
| 143 | (expected-calls . ((modification-hooks (nil 3 4)) | ||
| 144 | (modification-hooks (t 3 4 1))))) | ||
| 145 | ((replace . "4")) | ||
| 146 | ((replace . "12") | ||
| 147 | (expected-calls . ((modification-hooks (nil 1 3)) | ||
| 148 | (modification-hooks (t 1 2 2))))) | ||
| 149 | ((replace . "23") | ||
| 150 | (expected-calls . ((modification-hooks (nil 2 4)) | ||
| 151 | (modification-hooks (t 2 3 2))))) | ||
| 152 | ((replace . "34") | ||
| 153 | (expected-calls . ((modification-hooks (nil 3 5)) | ||
| 154 | (modification-hooks (t 3 4 2))))) | ||
| 155 | ((replace . "123") | ||
| 156 | (expected-calls . ((modification-hooks (nil 1 4)) | ||
| 157 | (modification-hooks (t 1 2 3))))) | ||
| 158 | ((replace . "234") | ||
| 159 | (expected-calls . ((modification-hooks (nil 2 5)) | ||
| 160 | (modification-hooks (t 2 3 3))))) | ||
| 161 | ((replace . "1234") | ||
| 162 | (expected-calls . ((modification-hooks (nil 1 5)) | ||
| 163 | (modification-hooks (t 1 2 4))))) | ||
| 164 | |||
| 165 | ;; Inserting at the position of a zero-length overlay | ||
| 166 | ;; calls both `insert-in-front-hooks' and | ||
| 167 | ;; `insert-behind-hooks'. | ||
| 168 | ((buffer-text . "") (overlay-beg . 1) (overlay-end . 1) | ||
| 169 | (insert-at . 1) | ||
| 170 | (expected-calls . ((insert-in-front-hooks | ||
| 171 | (nil 1 1)) | ||
| 172 | (insert-behind-hooks | ||
| 173 | (nil 1 1)) | ||
| 174 | (insert-in-front-hooks | ||
| 175 | (t 1 2 0)) | ||
| 176 | (insert-behind-hooks | ||
| 177 | (t 1 2 0))))))) | ||
| 178 | (message "BEGIN overlay-modification-hooks test-case %S" test-case) | ||
| 179 | |||
| 180 | ;; All three hooks ignore the overlay's `front-advance' and | ||
| 181 | ;; `rear-advance' option, so test both ways while expecting the same | ||
| 182 | ;; result. | ||
| 183 | (dolist (advance '(nil t)) | ||
| 184 | (message " advance is %S" advance) | ||
| 185 | (let-alist test-case | ||
| 186 | (with-temp-buffer | ||
| 187 | ;; Set up the temporary buffer and overlay as specified by | ||
| 188 | ;; the test case. | ||
| 189 | (insert (or .buffer-text "1234")) | ||
| 190 | (let ((overlay (make-overlay | ||
| 191 | (or .overlay-beg 2) | ||
| 192 | (or .overlay-end 4) | ||
| 193 | nil | ||
| 194 | advance advance))) | ||
| 195 | (message " (buffer-string) is %S" (buffer-string)) | ||
| 196 | (message " overlay is %S" overlay) | ||
| 197 | (overlay-tests-start-recording-modification-hooks overlay) | ||
| 198 | |||
| 199 | ;; Modify the buffer, possibly inducing calls to the | ||
| 200 | ;; overlay's modification hooks. | ||
| 201 | (should (or .insert-at .replace)) | ||
| 202 | (when .insert-at | ||
| 203 | (goto-char .insert-at) | ||
| 204 | (insert "x") | ||
| 205 | (message " inserted \"x\" at %S, buffer-string now %S" | ||
| 206 | .insert-at (buffer-string))) | ||
| 207 | (when .replace | ||
| 208 | (goto-char (point-min)) | ||
| 209 | (search-forward .replace) | ||
| 210 | (replace-match "x") | ||
| 211 | (message " replaced %S with \"x\"" .replace)) | ||
| 212 | |||
| 213 | ;; Verify that the expected and actual modification hook | ||
| 214 | ;; calls match. | ||
| 215 | (should (equal | ||
| 216 | .expected-calls | ||
| 217 | (overlay-tests-get-recorded-modification-hooks | ||
| 218 | overlay))))))))) | ||
| 24 | 219 | ||
| 25 | (ert-deftest overlay-modification-hooks-message-other-buf () | 220 | (ert-deftest overlay-modification-hooks-message-other-buf () |
| 26 | "Test for bug#21824. | 221 | "Test for bug#21824. |
| @@ -46,34 +241,80 @@ with parameters from the *Messages* buffer modification." | |||
| 46 | (should (eq buf (current-buffer)))) | 241 | (should (eq buf (current-buffer)))) |
| 47 | (when msg-ov (delete-overlay msg-ov)))))) | 242 | (when msg-ov (delete-overlay msg-ov)))))) |
| 48 | 243 | ||
| 244 | (ert-deftest overlay-modification-hooks-deleted-overlay () | ||
| 245 | "Test for bug#30823." | ||
| 246 | (let ((check-point nil) | ||
| 247 | (ov-delete nil) | ||
| 248 | (ov-set nil)) | ||
| 249 | (with-temp-buffer | ||
| 250 | (insert "abc") | ||
| 251 | (setq ov-set (make-overlay 1 3)) | ||
| 252 | (overlay-put ov-set 'modification-hooks | ||
| 253 | (list (lambda (_o after &rest _args) | ||
| 254 | (and after (setq check-point t))))) | ||
| 255 | (setq ov-delete (make-overlay 1 3)) | ||
| 256 | (overlay-put ov-delete 'modification-hooks | ||
| 257 | (list (lambda (o after &rest _args) | ||
| 258 | (and (not after) (delete-overlay o))))) | ||
| 259 | (goto-char 2) | ||
| 260 | (insert "1") | ||
| 261 | (should (eq check-point t))))) | ||
| 262 | |||
| 49 | (ert-deftest test-generate-new-buffer-name-bug27966 () | 263 | (ert-deftest test-generate-new-buffer-name-bug27966 () |
| 50 | (should-not (string-equal "nil" | 264 | (should-not (string-equal "nil" |
| 51 | (progn (get-buffer-create "nil") | 265 | (progn (get-buffer-create "nil") |
| 52 | (generate-new-buffer-name "nil"))))) | 266 | (generate-new-buffer-name "nil"))))) |
| 53 | 267 | ||
| 54 | 268 | (ert-deftest test-buffer-base-buffer-indirect () | |
| 55 | ;; +===================================================================================+ | 269 | (with-temp-buffer |
| 270 | (let* ((ind-buf-name (generate-new-buffer-name "indbuf")) | ||
| 271 | (ind-buf (make-indirect-buffer (current-buffer) ind-buf-name))) | ||
| 272 | (should (eq (buffer-base-buffer ind-buf) (current-buffer)))))) | ||
| 273 | |||
| 274 | (ert-deftest test-buffer-base-buffer-non-indirect () | ||
| 275 | (with-temp-buffer | ||
| 276 | (should (eq (buffer-base-buffer (current-buffer)) nil)))) | ||
| 277 | |||
| 278 | (ert-deftest overlay-evaporation-after-killed-buffer () | ||
| 279 | (let* ((ols (with-temp-buffer | ||
| 280 | (insert "toto") | ||
| 281 | (list | ||
| 282 | (make-overlay (point-min) (point-max)) | ||
| 283 | (make-overlay (point-min) (point-max)) | ||
| 284 | (make-overlay (point-min) (point-max))))) | ||
| 285 | (ol (nth 1 ols))) | ||
| 286 | (overlay-put ol 'evaporate t) | ||
| 287 | ;; Evaporation within move-overlay of an overlay that was deleted because | ||
| 288 | ;; of a kill-buffer, triggered an assertion failure in unchain_both. | ||
| 289 | (with-temp-buffer | ||
| 290 | (insert "toto") | ||
| 291 | (move-overlay ol (point-min) (point-min))))) | ||
| 292 | |||
| 293 | |||
| 294 | ;; +==========================================================================+ | ||
| 56 | ;; | Overlay test setup | 295 | ;; | Overlay test setup |
| 57 | ;; +===================================================================================+ | 296 | ;; +==========================================================================+ |
| 58 | 297 | ||
| 59 | (eval-when-compile | 298 | (eval-and-compile |
| 60 | (defun make-overlay-test-name (fn x y) | 299 | (defun buffer-tests--make-test-name (fn x y) |
| 61 | (intern (format "test-%s-%s-%s" fn x y)))) | 300 | (intern (format "buffer-tests--%s-%s-%s" fn x y)))) |
| 62 | 301 | ||
| 63 | (defun unmake-ov-test-name (symbol) | 302 | (defun buffer-tests--unmake-test-name (symbol) |
| 64 | (let ((name (if (stringp symbol) symbol (symbol-name symbol)))) | 303 | (let ((name (if (stringp symbol) symbol (symbol-name symbol)))) |
| 65 | (when (string-match "\\`test-\\(.*\\)-\\(.*\\)-\\(.*\\)\\'" name) | 304 | (when (string-match "\\`buffer-tests--\\(.*\\)-\\(.*\\)-\\(.*\\)\\'" name) |
| 66 | (list (match-string 1 name) (match-string 2 name) (match-string 3 name))))) | 305 | (list (match-string 1 name) |
| 306 | (match-string 2 name) | ||
| 307 | (match-string 3 name))))) | ||
| 67 | 308 | ||
| 68 | (defmacro deftest-make-overlay-1 (id args) | 309 | (defmacro deftest-make-overlay-1 (id args) |
| 69 | (declare (indent 1)) | 310 | (declare (indent 1)) |
| 70 | `(ert-deftest ,(make-overlay-test-name 'make-overlay 1 id) () | 311 | `(ert-deftest ,(buffer-tests--make-test-name 'make-overlay 1 id) () |
| 71 | (with-temp-buffer | 312 | (with-temp-buffer |
| 72 | (should ,(cons 'make-overlay args))))) | 313 | (should ,(cons 'make-overlay args))))) |
| 73 | 314 | ||
| 74 | (defmacro deftest-make-overlay-2 (id args condition) | 315 | (defmacro deftest-make-overlay-2 (id args condition) |
| 75 | (declare (indent 1)) | 316 | (declare (indent 1)) |
| 76 | `(ert-deftest ,(make-overlay-test-name 'make-overlay 2 id) () | 317 | `(ert-deftest ,(buffer-tests--make-test-name 'make-overlay 2 id) () |
| 77 | (with-temp-buffer | 318 | (with-temp-buffer |
| 78 | (should-error | 319 | (should-error |
| 79 | ,(cons 'make-overlay args) | 320 | ,(cons 'make-overlay args) |
| @@ -84,7 +325,7 @@ with parameters from the *Messages* buffer modification." | |||
| 84 | (declare (indent 1)) | 325 | (declare (indent 1)) |
| 85 | (cl-destructuring-bind (start end sstart send) | 326 | (cl-destructuring-bind (start end sstart send) |
| 86 | (append start-end-args start-end-should) | 327 | (append start-end-args start-end-should) |
| 87 | `(ert-deftest ,(make-overlay-test-name 'overlay-start/end 1 id) () | 328 | `(ert-deftest ,(buffer-tests--make-test-name 'overlay-start/end 1 id) () |
| 88 | (with-temp-buffer | 329 | (with-temp-buffer |
| 89 | (insert (make-string 9 ?\n)) | 330 | (insert (make-string 9 ?\n)) |
| 90 | (let ((ov (make-overlay ,start ,end))) | 331 | (let ((ov (make-overlay ,start ,end))) |
| @@ -93,25 +334,26 @@ with parameters from the *Messages* buffer modification." | |||
| 93 | 334 | ||
| 94 | (defmacro deftest-overlay-buffer-1 (id arg-expr should-expr) | 335 | (defmacro deftest-overlay-buffer-1 (id arg-expr should-expr) |
| 95 | (declare (indent 1)) | 336 | (declare (indent 1)) |
| 96 | `(ert-deftest ,(make-overlay-test-name 'overlay-buffer 1 id) () | 337 | `(ert-deftest ,(buffer-tests--make-test-name 'overlay-buffer 1 id) () |
| 97 | (with-temp-buffer | 338 | (with-temp-buffer |
| 98 | (should (equal (overlay-buffer (make-overlay 1 1 ,arg-expr)) | 339 | (should (equal (overlay-buffer (make-overlay 1 1 ,arg-expr)) |
| 99 | ,should-expr))))) | 340 | ,should-expr))))) |
| 100 | 341 | ||
| 101 | (defmacro deftest-overlayp-1 (id arg-expr should-expr) | 342 | (defmacro deftest-overlayp-1 (id arg-expr should-expr) |
| 102 | (declare (indent 1)) | 343 | (declare (indent 1)) |
| 103 | `(ert-deftest ,(make-overlay-test-name 'overlay-buffer 1 id) () | 344 | `(ert-deftest ,(buffer-tests--make-test-name 'overlayp 1 id) () |
| 104 | (with-temp-buffer | 345 | (with-temp-buffer |
| 105 | (should (equal ,should-expr (overlayp ,arg-expr)))))) | 346 | (should (equal ,should-expr (overlayp ,arg-expr)))))) |
| 106 | 347 | ||
| 107 | (defmacro deftest-next-overlay-change-1 (id pos result &rest ov-tuple) | 348 | (defmacro deftest-next-overlay-change-1 (id pos result &rest ov-tuple) |
| 108 | `(ert-deftest ,(make-overlay-test-name 'next-overlay-change 1 id) () | 349 | `(ert-deftest ,(buffer-tests--make-test-name 'next-overlay-change 1 id) () |
| 109 | (let ((tuple (copy-sequence ',ov-tuple))) | 350 | (let ((tuple (copy-sequence ',ov-tuple))) |
| 110 | (with-temp-buffer | 351 | (with-temp-buffer |
| 111 | (insert (make-string (max 100 (if tuple | 352 | (insert (make-string (max 100 (if tuple |
| 112 | (apply #'max | 353 | (apply #'max |
| 113 | (mapcar | 354 | (mapcar |
| 114 | (lambda (m) (apply #'max m)) tuple)) | 355 | (lambda (m) (apply #'max m)) |
| 356 | tuple)) | ||
| 115 | 0)) | 357 | 0)) |
| 116 | ?\n)) | 358 | ?\n)) |
| 117 | (dolist (tup tuple) | 359 | (dolist (tup tuple) |
| @@ -120,13 +362,14 @@ with parameters from the *Messages* buffer modification." | |||
| 120 | ,result)))))) | 362 | ,result)))))) |
| 121 | 363 | ||
| 122 | (defmacro deftest-previous-overlay-change-1 (id pos result &rest ov-tuple) | 364 | (defmacro deftest-previous-overlay-change-1 (id pos result &rest ov-tuple) |
| 123 | `(ert-deftest ,(make-overlay-test-name 'previous-overlay-change 1 id) () | 365 | `(ert-deftest ,(buffer-tests--make-test-name 'previous-overlay-change 1 id) () |
| 124 | (let ((tuple ',ov-tuple)) | 366 | (let ((tuple ',ov-tuple)) |
| 125 | (with-temp-buffer | 367 | (with-temp-buffer |
| 126 | (insert (make-string (max 100 (if tuple | 368 | (insert (make-string (max 100 (if tuple |
| 127 | (apply #'max | 369 | (apply #'max |
| 128 | (mapcar | 370 | (mapcar |
| 129 | (lambda (m) (apply #'max m)) tuple)) | 371 | (lambda (m) (apply #'max m)) |
| 372 | tuple)) | ||
| 130 | 0)) | 373 | 0)) |
| 131 | ?\n)) | 374 | ?\n)) |
| 132 | (dolist (tup tuple) | 375 | (dolist (tup tuple) |
| @@ -135,7 +378,7 @@ with parameters from the *Messages* buffer modification." | |||
| 135 | ,result)))))) | 378 | ,result)))))) |
| 136 | 379 | ||
| 137 | (defmacro deftest-overlays-at-1 (id pos result &rest ov-triple) | 380 | (defmacro deftest-overlays-at-1 (id pos result &rest ov-triple) |
| 138 | `(ert-deftest ,(make-overlay-test-name 'overlays-at 1 id) () | 381 | `(ert-deftest ,(buffer-tests--make-test-name 'overlays-at 1 id) () |
| 139 | (let ((pos* ,pos)) | 382 | (let ((pos* ,pos)) |
| 140 | (with-temp-buffer | 383 | (with-temp-buffer |
| 141 | (insert (make-string 100 ?\s)) | 384 | (insert (make-string 100 ?\s)) |
| @@ -150,7 +393,7 @@ with parameters from the *Messages* buffer modification." | |||
| 150 | (should (memq (overlay-get ov 'tag) ',result)))))))) | 393 | (should (memq (overlay-get ov 'tag) ',result)))))))) |
| 151 | 394 | ||
| 152 | (defmacro deftest-overlays-in-1 (id beg end result &rest ov-triple) | 395 | (defmacro deftest-overlays-in-1 (id beg end result &rest ov-triple) |
| 153 | `(ert-deftest ,(make-overlay-test-name 'overlays-in 1 id) () | 396 | `(ert-deftest ,(buffer-tests--make-test-name 'overlays-in 1 id) () |
| 154 | (let ((beg* ,beg) | 397 | (let ((beg* ,beg) |
| 155 | (end* ,end)) | 398 | (end* ,end)) |
| 156 | (with-temp-buffer | 399 | (with-temp-buffer |
| @@ -176,39 +419,42 @@ with parameters from the *Messages* buffer modification." | |||
| 176 | ,@body)))) | 419 | ,@body)))) |
| 177 | 420 | ||
| 178 | (defmacro deftest-overlays-equal-1 (id result ov1-args ov2-args) | 421 | (defmacro deftest-overlays-equal-1 (id result ov1-args ov2-args) |
| 179 | `(ert-deftest ,(make-overlay-test-name 'overlays-equal 1 id) () | 422 | `(ert-deftest ,(buffer-tests--make-test-name 'overlays-equal 1 id) () |
| 180 | (cl-labels ((create-overlay (args) | 423 | (cl-flet ((create-overlay (args) |
| 181 | (cl-destructuring-bind (start end &optional fa ra &rest properties) | 424 | (cl-destructuring-bind (start end &optional fa ra |
| 182 | args | 425 | &rest properties) |
| 183 | (let ((ov (make-overlay start end nil fa ra))) | 426 | args |
| 184 | (while properties | 427 | (let ((ov (make-overlay start end nil fa ra))) |
| 185 | (overlay-put ov (pop properties) (pop properties))) | 428 | (while properties |
| 186 | ov)))) | 429 | (overlay-put ov (pop properties) (pop properties))) |
| 430 | ov)))) | ||
| 187 | (with-temp-buffer | 431 | (with-temp-buffer |
| 188 | (insert (make-string 1024 ?\s)) | 432 | (insert (make-string 1024 ?\s)) |
| 189 | (should (,(if result 'identity 'not) | 433 | (should (,(if result 'identity 'not) |
| 190 | (equal (create-overlay ',ov1-args) | 434 | (equal (create-overlay ',ov1-args) |
| 191 | (create-overlay ',ov2-args)))))))) | 435 | (create-overlay ',ov2-args)))))))) |
| 192 | |||
| 193 | 436 | ||
| 194 | (defun find-ert-overlay-test (name) | 437 | |
| 195 | (let ((test (unmake-ov-test-name name))) | 438 | (defun buffer-tests--find-ert-test (name) |
| 439 | (let ((test (buffer-tests--unmake-test-name name))) | ||
| 196 | (or (and test | 440 | (or (and test |
| 197 | (cl-destructuring-bind (fn x y) | 441 | (cl-destructuring-bind (fn x y) |
| 198 | test | 442 | test |
| 199 | (let ((regexp (format "deftest-%s-%s +%s" fn x y))) | 443 | (let ((regexp (format "deftest-%s-%s +%s" fn x y))) |
| 200 | (re-search-forward regexp nil t)))) | 444 | (re-search-forward regexp nil t)))) |
| 201 | (let ((find-function-regexp-alist | 445 | (let ((find-function-regexp-alist |
| 202 | (cl-remove 'find-ert-overlay-test find-function-regexp-alist :key #'cdr))) | 446 | (cl-remove #'buffer-tests--find-ert-test |
| 203 | (find-function-do-it name 'ert-deftest 'switch-to-buffer-other-window))))) | 447 | find-function-regexp-alist :key #'cdr))) |
| 448 | (find-function-do-it name 'ert-deftest | ||
| 449 | #'switch-to-buffer-other-window))))) | ||
| 204 | 450 | ||
| 205 | (add-to-list 'find-function-regexp-alist | 451 | (add-to-list 'find-function-regexp-alist |
| 206 | '(ert-deftest . find-ert-overlay-test)) | 452 | `(ert-deftest . ,#'buffer-tests--find-ert-test)) |
| 207 | 453 | ||
| 208 | 454 | ||
| 209 | ;; +===================================================================================+ | 455 | ;; +==========================================================================+ |
| 210 | ;; | make-overlay | 456 | ;; | make-overlay |
| 211 | ;; +===================================================================================+ | 457 | ;; +==========================================================================+ |
| 212 | 458 | ||
| 213 | ;; Test if making an overlay succeeds. | 459 | ;; Test if making an overlay succeeds. |
| 214 | (deftest-make-overlay-1 A (1 1)) | 460 | (deftest-make-overlay-1 A (1 1)) |
| @@ -237,12 +483,12 @@ with parameters from the *Messages* buffer modification." | |||
| 237 | (deftest-make-overlay-2 I (1 [1]) wrong-type-argument) | 483 | (deftest-make-overlay-2 I (1 [1]) wrong-type-argument) |
| 238 | (deftest-make-overlay-2 J (1 1 (with-temp-buffer | 484 | (deftest-make-overlay-2 J (1 1 (with-temp-buffer |
| 239 | (current-buffer))) | 485 | (current-buffer))) |
| 240 | error) | 486 | error) |
| 241 | 487 | ||
| 242 | 488 | ||
| 243 | ;; +===================================================================================+ | 489 | ;; +==========================================================================+ |
| 244 | ;; | overlay-start/end | 490 | ;; | overlay-start/end |
| 245 | ;; +===================================================================================+ | 491 | ;; +==========================================================================+ |
| 246 | 492 | ||
| 247 | ;; Test if the overlays return proper positions. point-max of the | 493 | ;; Test if the overlays return proper positions. point-max of the |
| 248 | ;; buffer will equal 10. ARG RESULT | 494 | ;; buffer will equal 10. ARG RESULT |
| @@ -253,7 +499,8 @@ with parameters from the *Messages* buffer modification." | |||
| 253 | (deftest-overlay-start/end-1 E (1 11) (1 10)) | 499 | (deftest-overlay-start/end-1 E (1 11) (1 10)) |
| 254 | (deftest-overlay-start/end-1 F (1 most-positive-fixnum) (1 10)) | 500 | (deftest-overlay-start/end-1 F (1 most-positive-fixnum) (1 10)) |
| 255 | (deftest-overlay-start/end-1 G (most-positive-fixnum 1) (1 10)) | 501 | (deftest-overlay-start/end-1 G (most-positive-fixnum 1) (1 10)) |
| 256 | (deftest-overlay-start/end-1 H (most-positive-fixnum most-positive-fixnum) (10 10)) | 502 | (deftest-overlay-start/end-1 H (most-positive-fixnum most-positive-fixnum) |
| 503 | (10 10)) | ||
| 257 | (deftest-overlay-start/end-1 I (100 11) (10 10)) | 504 | (deftest-overlay-start/end-1 I (100 11) (10 10)) |
| 258 | (deftest-overlay-start/end-1 J (11 100) (10 10)) | 505 | (deftest-overlay-start/end-1 J (11 100) (10 10)) |
| 259 | (deftest-overlay-start/end-1 K (0 1) (1 1)) | 506 | (deftest-overlay-start/end-1 K (0 1) (1 1)) |
| @@ -264,10 +511,10 @@ with parameters from the *Messages* buffer modification." | |||
| 264 | (should-not (overlay-start (with-temp-buffer (make-overlay 1 1)))) | 511 | (should-not (overlay-start (with-temp-buffer (make-overlay 1 1)))) |
| 265 | (should-not (overlay-end (with-temp-buffer (make-overlay 1 1))))) | 512 | (should-not (overlay-end (with-temp-buffer (make-overlay 1 1))))) |
| 266 | 513 | ||
| 267 | 514 | ||
| 268 | ;; +===================================================================================+ | 515 | ;; +==========================================================================+ |
| 269 | ;; | overlay-buffer | 516 | ;; | overlay-buffer |
| 270 | ;; +===================================================================================+ | 517 | ;; +==========================================================================+ |
| 271 | 518 | ||
| 272 | ;; Test if overlay-buffer returns appropriate values. | 519 | ;; Test if overlay-buffer returns appropriate values. |
| 273 | (deftest-overlay-buffer-1 A (current-buffer) (current-buffer)) | 520 | (deftest-overlay-buffer-1 A (current-buffer) (current-buffer)) |
| @@ -276,10 +523,10 @@ with parameters from the *Messages* buffer modification." | |||
| 276 | (should-error (make-overlay | 523 | (should-error (make-overlay |
| 277 | 1 1 (with-temp-buffer (current-buffer))))) | 524 | 1 1 (with-temp-buffer (current-buffer))))) |
| 278 | 525 | ||
| 279 | 526 | ||
| 280 | ;; +===================================================================================+ | 527 | ;; +==========================================================================+ |
| 281 | ;; | overlayp | 528 | ;; | overlayp |
| 282 | ;; +===================================================================================+ | 529 | ;; +==========================================================================+ |
| 283 | 530 | ||
| 284 | ;; Check the overlay predicate. | 531 | ;; Check the overlay predicate. |
| 285 | (deftest-overlayp-1 A (make-overlay 1 1) t) | 532 | (deftest-overlayp-1 A (make-overlay 1 1) t) |
| @@ -298,10 +545,10 @@ with parameters from the *Messages* buffer modification." | |||
| 298 | (deftest-overlayp-1 N (selected-window) nil) | 545 | (deftest-overlayp-1 N (selected-window) nil) |
| 299 | (deftest-overlayp-1 O (selected-frame) nil) | 546 | (deftest-overlayp-1 O (selected-frame) nil) |
| 300 | 547 | ||
| 301 | 548 | ||
| 302 | ;; +===================================================================================+ | 549 | ;; +==========================================================================+ |
| 303 | ;; | overlay equality | 550 | ;; | overlay equality |
| 304 | ;; +===================================================================================+ | 551 | ;; +==========================================================================+ |
| 305 | 552 | ||
| 306 | (deftest-overlays-equal-1 A t (1 1) (1 1)) | 553 | (deftest-overlays-equal-1 A t (1 1) (1 1)) |
| 307 | (deftest-overlays-equal-1 B t (5 10) (5 10)) | 554 | (deftest-overlays-equal-1 B t (5 10) (5 10)) |
| @@ -313,10 +560,10 @@ with parameters from the *Messages* buffer modification." | |||
| 313 | (deftest-overlays-equal-1 H t (10 20 nil nil foo 42) (10 20 nil nil foo 42)) | 560 | (deftest-overlays-equal-1 H t (10 20 nil nil foo 42) (10 20 nil nil foo 42)) |
| 314 | (deftest-overlays-equal-1 I nil (10 20 nil nil foo 42) (10 20 nil nil foo 43)) | 561 | (deftest-overlays-equal-1 I nil (10 20 nil nil foo 42) (10 20 nil nil foo 43)) |
| 315 | 562 | ||
| 316 | 563 | ||
| 317 | ;; +===================================================================================+ | 564 | ;; +==========================================================================+ |
| 318 | ;; | overlay-lists | 565 | ;; | overlay-lists |
| 319 | ;; +===================================================================================+ | 566 | ;; +==========================================================================+ |
| 320 | 567 | ||
| 321 | ;; Check whether overlay-lists returns something sensible. | 568 | ;; Check whether overlay-lists returns something sensible. |
| 322 | (ert-deftest test-overlay-lists-1 () | 569 | (ert-deftest test-overlay-lists-1 () |
| @@ -330,10 +577,10 @@ with parameters from the *Messages* buffer modification." | |||
| 330 | (should (= 10 (length list))) | 577 | (should (= 10 (length list))) |
| 331 | (should (seq-every-p #'overlayp list))))) | 578 | (should (seq-every-p #'overlayp list))))) |
| 332 | 579 | ||
| 333 | 580 | ||
| 334 | ;; +===================================================================================+ | 581 | ;; +==========================================================================+ |
| 335 | ;; | overlay-put/get/properties | 582 | ;; | overlay-put/get/properties |
| 336 | ;; +===================================================================================+ | 583 | ;; +==========================================================================+ |
| 337 | 584 | ||
| 338 | ;; Test if overlay-put properties can be retrieved by overlay-get and | 585 | ;; Test if overlay-put properties can be retrieved by overlay-get and |
| 339 | ;; overlay-properties. | 586 | ;; overlay-properties. |
| @@ -361,10 +608,10 @@ with parameters from the *Messages* buffer modification." | |||
| 361 | ;; Check if overlay-properties is a subset. | 608 | ;; Check if overlay-properties is a subset. |
| 362 | (should (= (length (overlay-properties ov)) (* n 2)))))) | 609 | (should (= (length (overlay-properties ov)) (* n 2)))))) |
| 363 | 610 | ||
| 364 | 611 | ||
| 365 | ;; +===================================================================================+ | 612 | ;; +==========================================================================+ |
| 366 | ;; | next-overlay-change | 613 | ;; | next-overlay-change |
| 367 | ;; +===================================================================================+ | 614 | ;; +==========================================================================+ |
| 368 | 615 | ||
| 369 | ;; Test if next-overlay-change returns RESULT if called with POS in a | 616 | ;; Test if next-overlay-change returns RESULT if called with POS in a |
| 370 | ;; buffer with overlays corresponding to OVS and point-max >= 100. | 617 | ;; buffer with overlays corresponding to OVS and point-max >= 100. |
| @@ -383,14 +630,14 @@ with parameters from the *Messages* buffer modification." | |||
| 383 | (deftest-next-overlay-change-1 I 10 (point-max) (10 10)) | 630 | (deftest-next-overlay-change-1 I 10 (point-max) (10 10)) |
| 384 | (deftest-next-overlay-change-1 J 20 (point-max) (10 10)) | 631 | (deftest-next-overlay-change-1 J 20 (point-max) (10 10)) |
| 385 | ;; 2 non-empty, non-intersecting | 632 | ;; 2 non-empty, non-intersecting |
| 386 | (deftest-next-overlay-change-1 D 10 20 (20 30) (40 50)) | 633 | (deftest-next-overlay-change-1 D2 10 20 (20 30) (40 50)) |
| 387 | (deftest-next-overlay-change-1 E 35 40 (20 30) (40 50)) | 634 | (deftest-next-overlay-change-1 E2 35 40 (20 30) (40 50)) |
| 388 | (deftest-next-overlay-change-1 F 60 (point-max) (20 30) (40 50)) | 635 | (deftest-next-overlay-change-1 F2 60 (point-max) (20 30) (40 50)) |
| 389 | (deftest-next-overlay-change-1 G 30 40 (20 30) (40 50)) | 636 | (deftest-next-overlay-change-1 G2 30 40 (20 30) (40 50)) |
| 390 | (deftest-next-overlay-change-1 H 50 (point-max) (20 30) (40 50)) | 637 | (deftest-next-overlay-change-1 H2 50 (point-max) (20 30) (40 50)) |
| 391 | ;; 2 non-empty, intersecting | 638 | ;; 2 non-empty, intersecting |
| 392 | (deftest-next-overlay-change-1 I 10 20 (20 30) (25 35)) | 639 | (deftest-next-overlay-change-1 I2 10 20 (20 30) (25 35)) |
| 393 | (deftest-next-overlay-change-1 J 20 25 (20 30) (25 35)) | 640 | (deftest-next-overlay-change-1 J2 20 25 (20 30) (25 35)) |
| 394 | (deftest-next-overlay-change-1 K 23 25 (20 30) (25 35)) | 641 | (deftest-next-overlay-change-1 K 23 25 (20 30) (25 35)) |
| 395 | (deftest-next-overlay-change-1 L 25 30 (20 30) (25 35)) | 642 | (deftest-next-overlay-change-1 L 25 30 (20 30) (25 35)) |
| 396 | (deftest-next-overlay-change-1 M 28 30 (20 30) (25 35)) | 643 | (deftest-next-overlay-change-1 M 28 30 (20 30) (25 35)) |
| @@ -420,11 +667,11 @@ with parameters from the *Messages* buffer modification." | |||
| 420 | (deftest-next-overlay-change-1 k 30 (point-max) (20 20) (20 30)) | 667 | (deftest-next-overlay-change-1 k 30 (point-max) (20 20) (20 30)) |
| 421 | (deftest-next-overlay-change-1 l 40 (point-max) (20 20) (20 30)) | 668 | (deftest-next-overlay-change-1 l 40 (point-max) (20 20) (20 30)) |
| 422 | ;; 1 empty, 1 non-empty, intersecting at end | 669 | ;; 1 empty, 1 non-empty, intersecting at end |
| 423 | (deftest-next-overlay-change-1 h 10 20 (30 30) (20 30)) | 670 | (deftest-next-overlay-change-1 h2 10 20 (30 30) (20 30)) |
| 424 | (deftest-next-overlay-change-1 i 20 30 (30 30) (20 30)) | 671 | (deftest-next-overlay-change-1 i2 20 30 (30 30) (20 30)) |
| 425 | (deftest-next-overlay-change-1 j 25 30 (30 30) (20 30)) | 672 | (deftest-next-overlay-change-1 j2 25 30 (30 30) (20 30)) |
| 426 | (deftest-next-overlay-change-1 k 30 (point-max) (20 20) (20 30)) | 673 | (deftest-next-overlay-change-1 k2 30 (point-max) (20 20) (20 30)) |
| 427 | (deftest-next-overlay-change-1 l 40 (point-max) (20 20) (20 30)) | 674 | (deftest-next-overlay-change-1 l2 40 (point-max) (20 20) (20 30)) |
| 428 | ;; 1 empty, 1 non-empty, intersecting in the middle | 675 | ;; 1 empty, 1 non-empty, intersecting in the middle |
| 429 | (deftest-next-overlay-change-1 m 10 20 (25 25) (20 30)) | 676 | (deftest-next-overlay-change-1 m 10 20 (25 25) (20 30)) |
| 430 | (deftest-next-overlay-change-1 n 20 25 (25 25) (20 30)) | 677 | (deftest-next-overlay-change-1 n 20 25 (25 25) (20 30)) |
| @@ -452,10 +699,10 @@ with parameters from the *Messages* buffer modification." | |||
| 452 | (58 66) (41 10) (9 67) (28 88) (27 43) | 699 | (58 66) (41 10) (9 67) (28 88) (27 43) |
| 453 | (24 27) (48 36) (5 90) (61 9)) | 700 | (24 27) (48 36) (5 90) (61 9)) |
| 454 | 701 | ||
| 455 | 702 | ||
| 456 | ;; +===================================================================================+ | 703 | ;; +==========================================================================+ |
| 457 | ;; | previous-overlay-change. | 704 | ;; | previous-overlay-change. |
| 458 | ;; +===================================================================================+ | 705 | ;; +==========================================================================+ |
| 459 | 706 | ||
| 460 | ;; Same for previous-overlay-change. | 707 | ;; Same for previous-overlay-change. |
| 461 | ;; 1 non-empty overlay | 708 | ;; 1 non-empty overlay |
| @@ -471,14 +718,14 @@ with parameters from the *Messages* buffer modification." | |||
| 471 | (deftest-previous-overlay-change-1 I 10 1 (10 10)) | 718 | (deftest-previous-overlay-change-1 I 10 1 (10 10)) |
| 472 | (deftest-previous-overlay-change-1 J 20 10 (10 10)) | 719 | (deftest-previous-overlay-change-1 J 20 10 (10 10)) |
| 473 | ;; 2 non-empty, non-intersecting | 720 | ;; 2 non-empty, non-intersecting |
| 474 | (deftest-previous-overlay-change-1 D 10 1 (20 30) (40 50)) | 721 | (deftest-previous-overlay-change-1 D2 10 1 (20 30) (40 50)) |
| 475 | (deftest-previous-overlay-change-1 E 35 30 (20 30) (40 50)) | 722 | (deftest-previous-overlay-change-1 E2 35 30 (20 30) (40 50)) |
| 476 | (deftest-previous-overlay-change-1 F 60 50 (20 30) (40 50)) | 723 | (deftest-previous-overlay-change-1 F2 60 50 (20 30) (40 50)) |
| 477 | (deftest-previous-overlay-change-1 G 30 20 (20 30) (40 50)) | 724 | (deftest-previous-overlay-change-1 G2 30 20 (20 30) (40 50)) |
| 478 | (deftest-previous-overlay-change-1 H 50 40 (20 30) (40 50)) | 725 | (deftest-previous-overlay-change-1 H2 50 40 (20 30) (40 50)) |
| 479 | ;; 2 non-empty, intersecting | 726 | ;; 2 non-empty, intersecting |
| 480 | (deftest-previous-overlay-change-1 I 10 1 (20 30) (25 35)) | 727 | (deftest-previous-overlay-change-1 I2 10 1 (20 30) (25 35)) |
| 481 | (deftest-previous-overlay-change-1 J 20 1 (20 30) (25 35)) | 728 | (deftest-previous-overlay-change-1 J2 20 1 (20 30) (25 35)) |
| 482 | (deftest-previous-overlay-change-1 K 23 20 (20 30) (25 35)) | 729 | (deftest-previous-overlay-change-1 K 23 20 (20 30) (25 35)) |
| 483 | (deftest-previous-overlay-change-1 L 25 20 (20 30) (25 35)) | 730 | (deftest-previous-overlay-change-1 L 25 20 (20 30) (25 35)) |
| 484 | (deftest-previous-overlay-change-1 M 28 25 (20 30) (25 35)) | 731 | (deftest-previous-overlay-change-1 M 28 25 (20 30) (25 35)) |
| @@ -513,7 +760,7 @@ with parameters from the *Messages* buffer modification." | |||
| 513 | (deftest-previous-overlay-change-1 o 25 20 (30 30) (20 30)) | 760 | (deftest-previous-overlay-change-1 o 25 20 (30 30) (20 30)) |
| 514 | (deftest-previous-overlay-change-1 p 30 20 (20 20) (20 30)) | 761 | (deftest-previous-overlay-change-1 p 30 20 (20 20) (20 30)) |
| 515 | (deftest-previous-overlay-change-1 q 40 30 (20 20) (20 30)) | 762 | (deftest-previous-overlay-change-1 q 40 30 (20 20) (20 30)) |
| 516 | ;; 1 empty, 1 non-empty, intersectig in the middle | 763 | ;; 1 empty, 1 non-empty, intersecting in the middle |
| 517 | (deftest-previous-overlay-change-1 r 10 1 (25 25) (20 30)) | 764 | (deftest-previous-overlay-change-1 r 10 1 (25 25) (20 30)) |
| 518 | (deftest-previous-overlay-change-1 s 20 1 (25 25) (20 30)) | 765 | (deftest-previous-overlay-change-1 s 20 1 (25 25) (20 30)) |
| 519 | (deftest-previous-overlay-change-1 t 25 20 (25 25) (20 30)) | 766 | (deftest-previous-overlay-change-1 t 25 20 (25 25) (20 30)) |
| @@ -540,10 +787,10 @@ with parameters from the *Messages* buffer modification." | |||
| 540 | (58 66) (41 10) (9 67) (28 88) (27 43) | 787 | (58 66) (41 10) (9 67) (28 88) (27 43) |
| 541 | (24 27) (48 36) (5 90) (61 9)) | 788 | (24 27) (48 36) (5 90) (61 9)) |
| 542 | 789 | ||
| 543 | 790 | ||
| 544 | ;; +===================================================================================+ | 791 | ;; +==========================================================================+ |
| 545 | ;; | overlays-at | 792 | ;; | overlays-at |
| 546 | ;; +===================================================================================+ | 793 | ;; +==========================================================================+ |
| 547 | 794 | ||
| 548 | 795 | ||
| 549 | ;; Test whether overlay-at returns RESULT at POS after overlays OVL were | 796 | ;; Test whether overlay-at returns RESULT at POS after overlays OVL were |
| @@ -568,36 +815,36 @@ with parameters from the *Messages* buffer modification." | |||
| 568 | (deftest-overlays-at-1 P 50 () (a 10 20) (b 30 40)) | 815 | (deftest-overlays-at-1 P 50 () (a 10 20) (b 30 40)) |
| 569 | 816 | ||
| 570 | ;; 2 non-empty overlays intersecting | 817 | ;; 2 non-empty overlays intersecting |
| 571 | (deftest-overlays-at-1 G 1 () (a 10 30) (b 20 40)) | 818 | (deftest-overlays-at-1 G2 1 () (a 10 30) (b 20 40)) |
| 572 | (deftest-overlays-at-1 H 10 (a) (a 10 30) (b 20 40)) | 819 | (deftest-overlays-at-1 H2 10 (a) (a 10 30) (b 20 40)) |
| 573 | (deftest-overlays-at-1 I 15 (a) (a 10 30) (b 20 40)) | 820 | (deftest-overlays-at-1 I2 15 (a) (a 10 30) (b 20 40)) |
| 574 | (deftest-overlays-at-1 K 20 (a b) (a 10 30) (b 20 40)) | 821 | (deftest-overlays-at-1 K2 20 (a b) (a 10 30) (b 20 40)) |
| 575 | (deftest-overlays-at-1 L 25 (a b) (a 10 30) (b 20 40)) | 822 | (deftest-overlays-at-1 L2 25 (a b) (a 10 30) (b 20 40)) |
| 576 | (deftest-overlays-at-1 M 30 (b) (a 10 30) (b 20 40)) | 823 | (deftest-overlays-at-1 M2 30 (b) (a 10 30) (b 20 40)) |
| 577 | (deftest-overlays-at-1 N 35 (b) (a 10 30) (b 20 40)) | 824 | (deftest-overlays-at-1 N2 35 (b) (a 10 30) (b 20 40)) |
| 578 | (deftest-overlays-at-1 O 40 () (a 10 30) (b 20 40)) | 825 | (deftest-overlays-at-1 O2 40 () (a 10 30) (b 20 40)) |
| 579 | (deftest-overlays-at-1 P 50 () (a 10 30) (b 20 40)) | 826 | (deftest-overlays-at-1 P2 50 () (a 10 30) (b 20 40)) |
| 580 | 827 | ||
| 581 | ;; 2 non-empty overlays continuous | 828 | ;; 2 non-empty overlays continuous |
| 582 | (deftest-overlays-at-1 G 1 () (a 10 20) (b 20 30)) | 829 | (deftest-overlays-at-1 G3 1 () (a 10 20) (b 20 30)) |
| 583 | (deftest-overlays-at-1 H 10 (a) (a 10 20) (b 20 30)) | 830 | (deftest-overlays-at-1 H3 10 (a) (a 10 20) (b 20 30)) |
| 584 | (deftest-overlays-at-1 I 15 (a) (a 10 20) (b 20 30)) | 831 | (deftest-overlays-at-1 I3 15 (a) (a 10 20) (b 20 30)) |
| 585 | (deftest-overlays-at-1 K 20 (b) (a 10 20) (b 20 30)) | 832 | (deftest-overlays-at-1 K3 20 (b) (a 10 20) (b 20 30)) |
| 586 | (deftest-overlays-at-1 L 25 (b) (a 10 20) (b 20 30)) | 833 | (deftest-overlays-at-1 L3 25 (b) (a 10 20) (b 20 30)) |
| 587 | (deftest-overlays-at-1 M 30 () (a 10 20) (b 20 30)) | 834 | (deftest-overlays-at-1 M3 30 () (a 10 20) (b 20 30)) |
| 588 | 835 | ||
| 589 | ;; overlays-at never returns empty overlays. | 836 | ;; overlays-at never returns empty overlays. |
| 590 | (deftest-overlays-at-1 N 1 (a) (a 1 60) (c 1 1) (b 30 30) (d 50 50)) | 837 | (deftest-overlays-at-1 N3 1 (a) (a 1 60) (c 1 1) (b 30 30) (d 50 50)) |
| 591 | (deftest-overlays-at-1 O 20 (a) (a 1 60) (c 1 1) (b 30 30) (d 50 50)) | 838 | (deftest-overlays-at-1 O3 20 (a) (a 1 60) (c 1 1) (b 30 30) (d 50 50)) |
| 592 | (deftest-overlays-at-1 P 30 (a) (a 1 60) (c 1 1) (b 30 30) (d 50 50)) | 839 | (deftest-overlays-at-1 P3 30 (a) (a 1 60) (c 1 1) (b 30 30) (d 50 50)) |
| 593 | (deftest-overlays-at-1 Q 40 (a) (a 1 60) (c 1 1) (b 30 30) (d 50 50)) | 840 | (deftest-overlays-at-1 Q 40 (a) (a 1 60) (c 1 1) (b 30 30) (d 50 50)) |
| 594 | (deftest-overlays-at-1 R 50 (a) (a 1 60) (c 1 1) (b 30 30) (d 50 50)) | 841 | (deftest-overlays-at-1 R 50 (a) (a 1 60) (c 1 1) (b 30 30) (d 50 50)) |
| 595 | (deftest-overlays-at-1 S 60 () (a 1 60) (c 1 1) (b 30 30) (d 50 50)) | 842 | (deftest-overlays-at-1 S 60 () (a 1 60) (c 1 1) (b 30 30) (d 50 50)) |
| 596 | 843 | ||
| 597 | ;; behaviour at point-min and point-max | 844 | ;; behavior at point-min and point-max |
| 598 | (ert-deftest test-overlays-at-2 () | 845 | (ert-deftest test-overlays-at-2 () |
| 599 | (cl-macrolet ((should-length (n list) | 846 | (cl-macrolet ((should-length (n list) |
| 600 | `(should (= ,n (length ,list))))) | 847 | `(should (= ,n (length ,list))))) |
| 601 | (with-temp-buffer | 848 | (with-temp-buffer |
| 602 | (insert (make-string 100 ?\s)) | 849 | (insert (make-string 100 ?\s)) |
| 603 | (make-overlay 1 (point-max)) | 850 | (make-overlay 1 (point-max)) |
| @@ -613,10 +860,10 @@ with parameters from the *Messages* buffer modification." | |||
| 613 | (should-length 1 (overlays-at 15)) | 860 | (should-length 1 (overlays-at 15)) |
| 614 | (should-length 1 (overlays-at (point-max)))))) | 861 | (should-length 1 (overlays-at (point-max)))))) |
| 615 | 862 | ||
| 616 | 863 | ||
| 617 | ;; +===================================================================================+ | 864 | ;; +==========================================================================+ |
| 618 | ;; | overlay-in | 865 | ;; | overlay-in |
| 619 | ;; +===================================================================================+ | 866 | ;; +==========================================================================+ |
| 620 | 867 | ||
| 621 | 868 | ||
| 622 | ;; Test whether overlays-in returns RES in BEG,END after overlays OVL were | 869 | ;; Test whether overlays-in returns RES in BEG,END after overlays OVL were |
| @@ -691,10 +938,10 @@ with parameters from the *Messages* buffer modification." | |||
| 691 | (deftest-overlays-in-1 af 10 11 (a) (a 10 10)) | 938 | (deftest-overlays-in-1 af 10 11 (a) (a 10 10)) |
| 692 | 939 | ||
| 693 | 940 | ||
| 694 | ;; behaviour at point-max | 941 | ;; behavior at point-max |
| 695 | (ert-deftest test-overlays-in-2 () | 942 | (ert-deftest test-overlays-in-2 () |
| 696 | (cl-macrolet ((should-length (n list) | 943 | (cl-macrolet ((should-length (n list) |
| 697 | `(should (= ,n (length ,list))))) | 944 | `(should (= ,n (length ,list))))) |
| 698 | (with-temp-buffer | 945 | (with-temp-buffer |
| 699 | (insert (make-string 100 ?\s)) | 946 | (insert (make-string 100 ?\s)) |
| 700 | (make-overlay (point-max) (point-max)) | 947 | (make-overlay (point-max) (point-max)) |
| @@ -703,13 +950,13 @@ with parameters from the *Messages* buffer modification." | |||
| 703 | (should-length 2 (overlays-in 1 (point-max))) | 950 | (should-length 2 (overlays-in 1 (point-max))) |
| 704 | (should-length 1 (overlays-in (point-max) (point-max))) | 951 | (should-length 1 (overlays-in (point-max) (point-max))) |
| 705 | (narrow-to-region 1 50) | 952 | (narrow-to-region 1 50) |
| 706 | (should-length 0 (overlays-in 1 (point-max))) | 953 | (should-length 1 (overlays-in 1 (point-max))) |
| 707 | (should-length 1 (overlays-in (point-max) (point-max)))))) | 954 | (should-length 1 (overlays-in (point-max) (point-max)))))) |
| 708 | 955 | ||
| 709 | 956 | ||
| 710 | ;; +===================================================================================+ | 957 | ;; +==========================================================================+ |
| 711 | ;; | overlay-recenter | 958 | ;; | overlay-recenter |
| 712 | ;; +===================================================================================+ | 959 | ;; +==========================================================================+ |
| 713 | 960 | ||
| 714 | ;; This function is a noop in the overlay tree branch. | 961 | ;; This function is a noop in the overlay tree branch. |
| 715 | (ert-deftest test-overlay-recenter () | 962 | (ert-deftest test-overlay-recenter () |
| @@ -720,10 +967,10 @@ with parameters from the *Messages* buffer modification." | |||
| 720 | (make-overlay i (1+ i)) | 967 | (make-overlay i (1+ i)) |
| 721 | (should-not (overlay-recenter i))))) | 968 | (should-not (overlay-recenter i))))) |
| 722 | 969 | ||
| 723 | 970 | ||
| 724 | ;; +===================================================================================+ | 971 | ;; +==========================================================================+ |
| 725 | ;; | move-overlay | 972 | ;; | move-overlay |
| 726 | ;; +===================================================================================+ | 973 | ;; +==========================================================================+ |
| 727 | 974 | ||
| 728 | ;; buffer nil with live overlay | 975 | ;; buffer nil with live overlay |
| 729 | (ert-deftest test-move-overlay-1 () | 976 | (ert-deftest test-move-overlay-1 () |
| @@ -767,23 +1014,9 @@ with parameters from the *Messages* buffer modification." | |||
| 767 | (should-not (overlay-end ov)) | 1014 | (should-not (overlay-end ov)) |
| 768 | (should-not (overlay-buffer ov)))) | 1015 | (should-not (overlay-buffer ov)))) |
| 769 | 1016 | ||
| 770 | ;; This used to fail. | 1017 | ;; +==========================================================================+ |
| 771 | (ert-deftest test-move-overlay-5 () | ||
| 772 | (skip-unless (fboundp 'overlay-tree)) | ||
| 773 | (with-temp-buffer | ||
| 774 | (insert (make-string 1 ?.)) | ||
| 775 | (let ((other (make-overlay 1 1))) | ||
| 776 | (make-overlay 1 1) | ||
| 777 | (insert "()") | ||
| 778 | (move-overlay other (point-max) (1+ (point-max)) (current-buffer)) | ||
| 779 | (delete-overlay other)) | ||
| 780 | (should (= (plist-get (car (with-no-warnings (overlay-tree))) :limit) | ||
| 781 | 1)))) | ||
| 782 | |||
| 783 | |||
| 784 | ;; +===================================================================================+ | ||
| 785 | ;; | delete-(all-)overlay | 1018 | ;; | delete-(all-)overlay |
| 786 | ;; +===================================================================================+ | 1019 | ;; +==========================================================================+ |
| 787 | 1020 | ||
| 788 | ;; delete live overlay | 1021 | ;; delete live overlay |
| 789 | (ert-deftest test-delete-overlay-1 () | 1022 | (ert-deftest test-delete-overlay-1 () |
| @@ -814,22 +1047,22 @@ with parameters from the *Messages* buffer modification." | |||
| 814 | (should-not (delete-all-overlays (current-buffer))) | 1047 | (should-not (delete-all-overlays (current-buffer))) |
| 815 | (should-not (delete-all-overlays)))) | 1048 | (should-not (delete-all-overlays)))) |
| 816 | 1049 | ||
| 817 | 1050 | ||
| 818 | ;; +===================================================================================+ | 1051 | ;; +==========================================================================+ |
| 819 | ;; | get-char-property(-and-overlay) | 1052 | ;; | get-char-property(-and-overlay) |
| 820 | ;; +===================================================================================+ | 1053 | ;; +==========================================================================+ |
| 821 | 1054 | ||
| 822 | ;; FIXME: TBD | 1055 | ;; FIXME: TBD |
| 823 | 1056 | ||
| 824 | 1057 | ||
| 825 | ;; +===================================================================================+ | 1058 | ;; +==========================================================================+ |
| 826 | ;; | Moving by insertions | 1059 | ;; | Moving by insertions |
| 827 | ;; +===================================================================================+ | 1060 | ;; +==========================================================================+ |
| 828 | 1061 | ||
| 829 | (defmacro deftest-moving-insert-1 (id beg-end insert sbeg-send fa ra) | 1062 | (defmacro deftest-moving-insert-1 (id beg-end insert sbeg-send fa ra) |
| 830 | (cl-destructuring-bind (beg end ipos ilen sbeg send fa ra) | 1063 | (cl-destructuring-bind (beg end ipos ilen sbeg send fa ra) |
| 831 | (append beg-end insert sbeg-send (list fa ra) nil) | 1064 | (append beg-end insert sbeg-send (list fa ra) nil) |
| 832 | `(ert-deftest ,(make-overlay-test-name 'moving-insert 1 id) () | 1065 | `(ert-deftest ,(buffer-tests--make-test-name 'moving-insert 1 id) () |
| 833 | (test-with-overlay-in-buffer (ov ,beg ,end ,fa ,ra) | 1066 | (test-with-overlay-in-buffer (ov ,beg ,end ,fa ,ra) |
| 834 | (should (= ,beg (overlay-start ov))) | 1067 | (should (= ,beg (overlay-start ov))) |
| 835 | (should (= ,end (overlay-end ov))) | 1068 | (should (= ,end (overlay-end ov))) |
| @@ -931,21 +1164,21 @@ with parameters from the *Messages* buffer modification." | |||
| 931 | (should (= 25 (overlay-start right))) | 1164 | (should (= 25 (overlay-start right))) |
| 932 | (should (= 75 (overlay-end right))) | 1165 | (should (= 75 (overlay-end right))) |
| 933 | ;; Try to detect the error, by removing left. The should fail | 1166 | ;; Try to detect the error, by removing left. The should fail |
| 934 | ;; an eassert, since it won't be found by a reular tree | 1167 | ;; an eassert, since it won't be found by a regular tree |
| 935 | ;; traversal - in theory. | 1168 | ;; traversal - in theory. |
| 936 | (delete-overlay left) | 1169 | (delete-overlay left) |
| 937 | (should (= 2 (length (overlays-in 1 (point-max)))))))) | 1170 | (should (= 2 (length (overlays-in 1 (point-max)))))))) |
| 938 | 1171 | ||
| 939 | 1172 | ||
| 940 | 1173 | ||
| 941 | ;; +===================================================================================+ | 1174 | ;; +==========================================================================+ |
| 942 | ;; | Moving by deletions | 1175 | ;; | Moving by deletions |
| 943 | ;; +===================================================================================+ | 1176 | ;; +==========================================================================+ |
| 944 | 1177 | ||
| 945 | (defmacro deftest-moving-delete-1 (id beg-end delete sbeg-send fa ra) | 1178 | (defmacro deftest-moving-delete-1 (id beg-end delete sbeg-send fa ra) |
| 946 | (cl-destructuring-bind (beg end dpos dlen sbeg send fa ra) | 1179 | (cl-destructuring-bind (beg end dpos dlen sbeg send fa ra) |
| 947 | (append beg-end delete sbeg-send (list fa ra) nil) | 1180 | (append beg-end delete sbeg-send (list fa ra) nil) |
| 948 | `(ert-deftest ,(make-overlay-test-name 'moving-delete 1 id) () | 1181 | `(ert-deftest ,(buffer-tests--make-test-name 'moving-delete 1 id) () |
| 949 | (test-with-overlay-in-buffer (ov ,beg ,end ,fa ,ra) | 1182 | (test-with-overlay-in-buffer (ov ,beg ,end ,fa ,ra) |
| 950 | (should (= ,beg (overlay-start ov))) | 1183 | (should (= ,beg (overlay-start ov))) |
| 951 | (should (= ,end (overlay-end ov))) | 1184 | (should (= ,end (overlay-end ov))) |
| @@ -1002,12 +1235,12 @@ with parameters from the *Messages* buffer modification." | |||
| 1002 | (deftest-moving-delete-1 e (15 15) (5 5) (10 10) t t) | 1235 | (deftest-moving-delete-1 e (15 15) (5 5) (10 10) t t) |
| 1003 | (deftest-moving-delete-1 f (15 15) (15 3) (15 15) t t) | 1236 | (deftest-moving-delete-1 f (15 15) (15 3) (15 15) t t) |
| 1004 | 1237 | ||
| 1005 | 1238 | ||
| 1006 | ;; +===================================================================================+ | 1239 | ;; +==========================================================================+ |
| 1007 | ;; | make-indirect-buffer | 1240 | ;; | make-indirect-buffer |
| 1008 | ;; +===================================================================================+ | 1241 | ;; +==========================================================================+ |
| 1009 | 1242 | ||
| 1010 | ;; Check if overlays are cloned/seperate from indirect buffer. | 1243 | ;; Check if overlays are cloned/separate from indirect buffer. |
| 1011 | (ert-deftest test-make-indirect-buffer-1 () | 1244 | (ert-deftest test-make-indirect-buffer-1 () |
| 1012 | (with-temp-buffer | 1245 | (with-temp-buffer |
| 1013 | (dotimes (_ 10) (make-overlay 1 1)) | 1246 | (dotimes (_ 10) (make-overlay 1 1)) |
| @@ -1045,22 +1278,22 @@ with parameters from the *Messages* buffer modification." | |||
| 1045 | (kill-buffer indirect)))))) | 1278 | (kill-buffer indirect)))))) |
| 1046 | 1279 | ||
| 1047 | 1280 | ||
| 1048 | 1281 | ||
| 1049 | ;; +===================================================================================+ | 1282 | ;; +==========================================================================+ |
| 1050 | ;; | buffer-swap-text | 1283 | ;; | buffer-swap-text |
| 1051 | ;; +===================================================================================+ | 1284 | ;; +==========================================================================+ |
| 1052 | 1285 | ||
| 1053 | (defmacro test-with-temp-buffers (vars &rest body) | 1286 | (defmacro buffer-tests--with-temp-buffers (vars &rest body) |
| 1054 | (declare (indent 1) (debug (sexp &rest form))) | 1287 | (declare (indent 1) (debug (sexp &rest form))) |
| 1055 | (if (null vars) | 1288 | (if (null vars) |
| 1056 | `(progn ,@body) | 1289 | `(progn ,@body) |
| 1057 | `(with-temp-buffer | 1290 | `(with-temp-buffer |
| 1058 | (let ((,(car vars) (current-buffer))) | 1291 | (let ((,(car vars) (current-buffer))) |
| 1059 | (test-with-temp-buffers ,(cdr vars) ,@body))))) | 1292 | (buffer-tests--with-temp-buffers ,(cdr vars) ,@body))))) |
| 1060 | 1293 | ||
| 1061 | ;; basic | 1294 | ;; basic |
| 1062 | (ert-deftest test-buffer-swap-text-1 () | 1295 | (ert-deftest test-buffer-swap-text-1 () |
| 1063 | (test-with-temp-buffers (buffer other) | 1296 | (buffer-tests--with-temp-buffers (buffer other) |
| 1064 | (with-current-buffer buffer | 1297 | (with-current-buffer buffer |
| 1065 | (let ((ov (make-overlay 1 1))) | 1298 | (let ((ov (make-overlay 1 1))) |
| 1066 | (buffer-swap-text other) | 1299 | (buffer-swap-text other) |
| @@ -1070,8 +1303,8 @@ with parameters from the *Messages* buffer modification." | |||
| 1070 | (should (eq ov (car (overlays-in 1 1))))))))) | 1303 | (should (eq ov (car (overlays-in 1 1))))))))) |
| 1071 | 1304 | ||
| 1072 | ;; properties | 1305 | ;; properties |
| 1073 | (ert-deftest test-buffer-swap-text-1 () | 1306 | (ert-deftest test-buffer-swap-text-2 () |
| 1074 | (test-with-temp-buffers (buffer other) | 1307 | (buffer-tests--with-temp-buffers (buffer other) |
| 1075 | (with-current-buffer other | 1308 | (with-current-buffer other |
| 1076 | (overlay-put (make-overlay 1 1) 'buffer 'other)) | 1309 | (overlay-put (make-overlay 1 1) 'buffer 'other)) |
| 1077 | (with-current-buffer buffer | 1310 | (with-current-buffer buffer |
| @@ -1083,10 +1316,10 @@ with parameters from the *Messages* buffer modification." | |||
| 1083 | (should (= 1 (length (overlays-in 1 1)))) | 1316 | (should (= 1 (length (overlays-in 1 1)))) |
| 1084 | (should (eq (overlay-get (car (overlays-in 1 1)) 'buffer) 'buffer))))) | 1317 | (should (eq (overlay-get (car (overlays-in 1 1)) 'buffer) 'buffer))))) |
| 1085 | 1318 | ||
| 1086 | 1319 | ||
| 1087 | ;; +===================================================================================+ | 1320 | ;; +==========================================================================+ |
| 1088 | ;; | priorities | 1321 | ;; | priorities |
| 1089 | ;; +===================================================================================+ | 1322 | ;; +==========================================================================+ |
| 1090 | 1323 | ||
| 1091 | (ert-deftest test-overlay-priorities-1 () | 1324 | (ert-deftest test-overlay-priorities-1 () |
| 1092 | (with-temp-buffer | 1325 | (with-temp-buffer |
| @@ -1107,10 +1340,10 @@ with parameters from the *Messages* buffer modification." | |||
| 1107 | (overlay-put ov 'value i))) | 1340 | (overlay-put ov 'value i))) |
| 1108 | (should (eq 9 (get-char-property 1 'value))))) | 1341 | (should (eq 9 (get-char-property 1 'value))))) |
| 1109 | 1342 | ||
| 1110 | 1343 | ||
| 1111 | ;; +===================================================================================+ | 1344 | ;; +==========================================================================+ |
| 1112 | ;; | Other | 1345 | ;; | Other |
| 1113 | ;; +===================================================================================+ | 1346 | ;; +==========================================================================+ |
| 1114 | 1347 | ||
| 1115 | (defun test-overlay-regions () | 1348 | (defun test-overlay-regions () |
| 1116 | (sort (mapcar (lambda (ov) | 1349 | (sort (mapcar (lambda (ov) |
| @@ -1226,9 +1459,10 @@ with parameters from the *Messages* buffer modification." | |||
| 1226 | (nonempty-eob (make-overlay 4 5)) | 1459 | (nonempty-eob (make-overlay 4 5)) |
| 1227 | (empty-eob (make-overlay 5 5))) | 1460 | (empty-eob (make-overlay 5 5))) |
| 1228 | (set-buffer-multibyte nil) | 1461 | (set-buffer-multibyte nil) |
| 1229 | (cl-macrolet ((ovshould (ov begin end) | 1462 | (cl-macrolet |
| 1230 | `(should (equal (list (overlay-start ,ov) (overlay-end ,ov)) | 1463 | ((ovshould (ov begin end) |
| 1231 | (list ,begin ,end))))) | 1464 | `(should (equal (list (overlay-start ,ov) (overlay-end ,ov)) |
| 1465 | (list ,begin ,end))))) | ||
| 1232 | (ovshould nonempty-bob 1 3) | 1466 | (ovshould nonempty-bob 1 3) |
| 1233 | (ovshould empty-bob 1 1) | 1467 | (ovshould empty-bob 1 1) |
| 1234 | (ovshould empty 3 3) | 1468 | (ovshould empty 3 3) |
| @@ -1257,9 +1491,10 @@ with parameters from the *Messages* buffer modification." | |||
| 1257 | (nonempty-eob-end (make-overlay 6 9)) | 1491 | (nonempty-eob-end (make-overlay 6 9)) |
| 1258 | (empty-eob (make-overlay 9 9))) | 1492 | (empty-eob (make-overlay 9 9))) |
| 1259 | (set-buffer-multibyte t) | 1493 | (set-buffer-multibyte t) |
| 1260 | (cl-macrolet ((ovshould (ov begin end) | 1494 | (cl-macrolet |
| 1261 | `(should (equal (list (overlay-start ,ov) (overlay-end ,ov)) | 1495 | ((ovshould (ov begin end) |
| 1262 | (list ,begin ,end))))) | 1496 | `(should (equal (list (overlay-start ,ov) (overlay-end ,ov)) |
| 1497 | (list ,begin ,end))))) | ||
| 1263 | (ovshould nonempty-bob-end 1 2) | 1498 | (ovshould nonempty-bob-end 1 2) |
| 1264 | (ovshould nonempty-bob-beg 1 2) | 1499 | (ovshould nonempty-bob-beg 1 2) |
| 1265 | (ovshould empty-bob 1 1) | 1500 | (ovshould empty-bob 1 1) |
| @@ -1280,6 +1515,7 @@ with parameters from the *Messages* buffer modification." | |||
| 1280 | ;; | Autogenerated insert/delete/narrow tests | 1515 | ;; | Autogenerated insert/delete/narrow tests |
| 1281 | ;; +===================================================================================+ | 1516 | ;; +===================================================================================+ |
| 1282 | 1517 | ||
| 1518 | (when nil ;; Let's comment these out for now. | ||
| 1283 | 1519 | ||
| 1284 | ;; (defun test-overlay-generate-test (name) | 1520 | ;; (defun test-overlay-generate-test (name) |
| 1285 | ;; (interactive) | 1521 | ;; (interactive) |
| @@ -7733,4 +7969,247 @@ with parameters from the *Messages* buffer modification." | |||
| 7733 | (101 . 138) | 7969 | (101 . 138) |
| 7734 | (103 . 103)))))) | 7970 | (103 . 103)))))) |
| 7735 | 7971 | ||
| 7972 | ) ;; End of `when nil' for autogenerated insert/delete/narrow tests. | ||
| 7973 | |||
| 7974 | (ert-deftest buffer-multibyte-overlong-sequences () | ||
| 7975 | (dolist (uni '("\xE0\x80\x80" | ||
| 7976 | "\xF0\x80\x80\x80" | ||
| 7977 | "\xF8\x8F\xBF\xBF\x80")) | ||
| 7978 | (let ((multi (string-to-multibyte uni))) | ||
| 7979 | (should | ||
| 7980 | (string-equal | ||
| 7981 | multi | ||
| 7982 | (with-temp-buffer | ||
| 7983 | (set-buffer-multibyte nil) | ||
| 7984 | (insert uni) | ||
| 7985 | (set-buffer-multibyte t) | ||
| 7986 | (buffer-string))))))) | ||
| 7987 | |||
| 7988 | ;; https://debbugs.gnu.org/33492 | ||
| 7989 | (ert-deftest buffer-tests-buffer-local-variables-undo () | ||
| 7990 | "Test that `buffer-undo-list' appears in `buffer-local-variables'." | ||
| 7991 | (with-temp-buffer | ||
| 7992 | (should (assq 'buffer-undo-list (buffer-local-variables))))) | ||
| 7993 | |||
| 7994 | (ert-deftest buffer-tests-inhibit-buffer-hooks () | ||
| 7995 | "Test `get-buffer-create' argument INHIBIT-BUFFER-HOOKS." | ||
| 7996 | (let* (run-bluh (bluh (lambda () (setq run-bluh t)))) | ||
| 7997 | (unwind-protect | ||
| 7998 | (let* ( run-kbh (kbh (lambda () (setq run-kbh t))) | ||
| 7999 | run-kbqf (kbqf (lambda () (setq run-kbqf t))) ) | ||
| 8000 | |||
| 8001 | ;; Inhibited. | ||
| 8002 | (add-hook 'buffer-list-update-hook bluh) | ||
| 8003 | (with-current-buffer (generate-new-buffer " foo" t) | ||
| 8004 | (add-hook 'kill-buffer-hook kbh nil t) | ||
| 8005 | (add-hook 'kill-buffer-query-functions kbqf nil t) | ||
| 8006 | (kill-buffer)) | ||
| 8007 | (with-temp-buffer (ignore)) | ||
| 8008 | (with-output-to-string (ignore)) | ||
| 8009 | (should-not run-bluh) | ||
| 8010 | (should-not run-kbh) | ||
| 8011 | (should-not run-kbqf) | ||
| 8012 | |||
| 8013 | ;; Not inhibited. | ||
| 8014 | (with-current-buffer (generate-new-buffer " foo") | ||
| 8015 | (should run-bluh) | ||
| 8016 | (add-hook 'kill-buffer-hook kbh nil t) | ||
| 8017 | (add-hook 'kill-buffer-query-functions kbqf nil t) | ||
| 8018 | (kill-buffer)) | ||
| 8019 | (should run-kbh) | ||
| 8020 | (should run-kbqf)) | ||
| 8021 | (remove-hook 'buffer-list-update-hook bluh)))) | ||
| 8022 | |||
| 8023 | (ert-deftest buffer-tests-inhibit-buffer-hooks-indirect () | ||
| 8024 | "Indirect buffers do not call `get-buffer-create'." | ||
| 8025 | (dolist (inhibit '(nil t)) | ||
| 8026 | (let ((base (get-buffer-create "foo" inhibit))) | ||
| 8027 | (unwind-protect | ||
| 8028 | (dotimes (_i 11) | ||
| 8029 | (let* (flag* | ||
| 8030 | (flag (lambda () (prog1 t (setq flag* t)))) | ||
| 8031 | (indirect (make-indirect-buffer base "foo[indirect]" nil | ||
| 8032 | inhibit))) | ||
| 8033 | (unwind-protect | ||
| 8034 | (progn | ||
| 8035 | (with-current-buffer indirect | ||
| 8036 | (add-hook 'kill-buffer-query-functions flag nil t)) | ||
| 8037 | (kill-buffer indirect) | ||
| 8038 | (if inhibit | ||
| 8039 | (should-not flag*) | ||
| 8040 | (should flag*))) | ||
| 8041 | (let (kill-buffer-query-functions) | ||
| 8042 | (when (buffer-live-p indirect) | ||
| 8043 | (kill-buffer indirect)))))) | ||
| 8044 | (let (kill-buffer-query-functions) | ||
| 8045 | (when (buffer-live-p base) | ||
| 8046 | (kill-buffer base))))))) | ||
| 8047 | |||
| 8048 | (ert-deftest zero-length-overlays-and-not () | ||
| 8049 | (with-temp-buffer | ||
| 8050 | (insert "hello") | ||
| 8051 | (let ((long-overlay (make-overlay 2 4)) | ||
| 8052 | (zero-overlay (make-overlay 3 3))) | ||
| 8053 | ;; Exclude. | ||
| 8054 | (should (= (length (overlays-at 3)) 1)) | ||
| 8055 | (should (eq (car (overlays-at 3)) long-overlay)) | ||
| 8056 | ;; Include. | ||
| 8057 | (should (= (length (overlays-in 3 3)) 2)) | ||
| 8058 | (should (memq long-overlay (overlays-in 3 3))) | ||
| 8059 | (should (memq zero-overlay (overlays-in 3 3)))))) | ||
| 8060 | |||
| 8061 | (ert-deftest test-remove-overlays () | ||
| 8062 | (with-temp-buffer | ||
| 8063 | (insert "foo") | ||
| 8064 | (make-overlay (point) (point)) | ||
| 8065 | (should (= (length (overlays-in (point-min) (point-max))) 1)) | ||
| 8066 | (remove-overlays) | ||
| 8067 | (should (= (length (overlays-in (point-min) (point-max))) 0))) | ||
| 8068 | |||
| 8069 | (with-temp-buffer | ||
| 8070 | (insert "foo") | ||
| 8071 | (goto-char 2) | ||
| 8072 | (make-overlay (point) (point)) | ||
| 8073 | ;; We only count zero-length overlays at the end of the buffer. | ||
| 8074 | (should (= (length (overlays-in 1 2)) 0)) | ||
| 8075 | (narrow-to-region 1 2) | ||
| 8076 | ;; We've now narrowed, so the zero-length overlay is at the end of | ||
| 8077 | ;; the (accessible part of the) buffer. | ||
| 8078 | (should (= (length (overlays-in 1 2)) 1)) | ||
| 8079 | (remove-overlays) | ||
| 8080 | (should (= (length (overlays-in (point-min) (point-max))) 0)))) | ||
| 8081 | |||
| 8082 | (ert-deftest test-kill-buffer-auto-save-default () | ||
| 8083 | (ert-with-temp-file file | ||
| 8084 | (let (auto-save) | ||
| 8085 | ;; Always answer yes. | ||
| 8086 | (cl-letf (((symbol-function #'yes-or-no-p) (lambda (_) t))) | ||
| 8087 | (unwind-protect | ||
| 8088 | (progn | ||
| 8089 | (find-file file) | ||
| 8090 | (auto-save-mode t) | ||
| 8091 | (insert "foo\n") | ||
| 8092 | (should buffer-auto-save-file-name) | ||
| 8093 | (setq auto-save buffer-auto-save-file-name) | ||
| 8094 | (do-auto-save) | ||
| 8095 | (should (file-exists-p auto-save)) | ||
| 8096 | (kill-buffer (current-buffer)) | ||
| 8097 | (should (file-exists-p auto-save))) | ||
| 8098 | (when auto-save | ||
| 8099 | (ignore-errors (delete-file auto-save)))))))) | ||
| 8100 | |||
| 8101 | (ert-deftest test-kill-buffer-auto-save-delete () | ||
| 8102 | (ert-with-temp-file file | ||
| 8103 | (let (auto-save) | ||
| 8104 | (should (file-exists-p file)) | ||
| 8105 | (setq kill-buffer-delete-auto-save-files t) | ||
| 8106 | ;; Always answer yes. | ||
| 8107 | (cl-letf (((symbol-function #'yes-or-no-p) (lambda (_) t))) | ||
| 8108 | (unwind-protect | ||
| 8109 | (progn | ||
| 8110 | (find-file file) | ||
| 8111 | (auto-save-mode t) | ||
| 8112 | (insert "foo\n") | ||
| 8113 | (should buffer-auto-save-file-name) | ||
| 8114 | (setq auto-save buffer-auto-save-file-name) | ||
| 8115 | (do-auto-save) | ||
| 8116 | (should (file-exists-p auto-save)) | ||
| 8117 | ;; This should delete the auto-save file. | ||
| 8118 | (kill-buffer (current-buffer)) | ||
| 8119 | (should-not (file-exists-p auto-save))) | ||
| 8120 | (ignore-errors (delete-file file)) | ||
| 8121 | (when auto-save | ||
| 8122 | (ignore-errors (delete-file auto-save))))) | ||
| 8123 | ;; Answer no to deletion. | ||
| 8124 | (cl-letf (((symbol-function #'yes-or-no-p) | ||
| 8125 | (lambda (prompt) | ||
| 8126 | (not (string-search "Delete auto-save file" prompt))))) | ||
| 8127 | (unwind-protect | ||
| 8128 | (progn | ||
| 8129 | (find-file file) | ||
| 8130 | (auto-save-mode t) | ||
| 8131 | (insert "foo\n") | ||
| 8132 | (should buffer-auto-save-file-name) | ||
| 8133 | (setq auto-save buffer-auto-save-file-name) | ||
| 8134 | (do-auto-save) | ||
| 8135 | (should (file-exists-p auto-save)) | ||
| 8136 | ;; This should not delete the auto-save file. | ||
| 8137 | (kill-buffer (current-buffer)) | ||
| 8138 | (should (file-exists-p auto-save))) | ||
| 8139 | (when auto-save | ||
| 8140 | (ignore-errors (delete-file auto-save)))))))) | ||
| 8141 | |||
| 8142 | (ert-deftest test-buffer-modifications () | ||
| 8143 | (ert-with-temp-file file | ||
| 8144 | (with-current-buffer (find-file file) | ||
| 8145 | (auto-save-mode 1) | ||
| 8146 | (should-not (buffer-modified-p)) | ||
| 8147 | (insert "foo") | ||
| 8148 | (should (buffer-modified-p)) | ||
| 8149 | (should-not (eq (buffer-modified-p) 'autosaved)) | ||
| 8150 | (do-auto-save nil t) | ||
| 8151 | (should (eq (buffer-modified-p) 'autosaved)) | ||
| 8152 | (with-silent-modifications | ||
| 8153 | (put-text-property 1 3 'face 'bold)) | ||
| 8154 | (should (eq (buffer-modified-p) 'autosaved)) | ||
| 8155 | (save-buffer) | ||
| 8156 | (should-not (buffer-modified-p)) | ||
| 8157 | (with-silent-modifications | ||
| 8158 | (put-text-property 1 3 'face 'italic)) | ||
| 8159 | (should-not (buffer-modified-p))))) | ||
| 8160 | |||
| 8161 | (ert-deftest test-restore-buffer-modified-p () | ||
| 8162 | (ert-with-temp-file file | ||
| 8163 | ;; This avoids the annoying "foo and bar are the same file" on | ||
| 8164 | ;; MS-Windows. | ||
| 8165 | (setq file (file-truename file)) | ||
| 8166 | (with-current-buffer (find-file file) | ||
| 8167 | (auto-save-mode 1) | ||
| 8168 | (should-not (eq (buffer-modified-p) t)) | ||
| 8169 | (insert "foo") | ||
| 8170 | (should (buffer-modified-p)) | ||
| 8171 | (restore-buffer-modified-p nil) | ||
| 8172 | (should-not (buffer-modified-p)) | ||
| 8173 | (insert "bar") | ||
| 8174 | (do-auto-save nil t) | ||
| 8175 | (should (eq (buffer-modified-p) 'autosaved)) | ||
| 8176 | (insert "zot") | ||
| 8177 | (restore-buffer-modified-p 'autosaved) | ||
| 8178 | (should (eq (buffer-modified-p) 'autosaved)) | ||
| 8179 | |||
| 8180 | ;; Clean up. | ||
| 8181 | (when (file-exists-p buffer-auto-save-file-name) | ||
| 8182 | (delete-file buffer-auto-save-file-name)))) | ||
| 8183 | |||
| 8184 | (ert-with-temp-file file | ||
| 8185 | (setq file (file-truename file)) | ||
| 8186 | (with-current-buffer (find-file file) | ||
| 8187 | (auto-save-mode 1) | ||
| 8188 | (should-not (eq (buffer-modified-p) t)) | ||
| 8189 | (insert "foo") | ||
| 8190 | (should (buffer-modified-p)) | ||
| 8191 | (should-not (eq (buffer-modified-p) 'autosaved)) | ||
| 8192 | (restore-buffer-modified-p 'autosaved) | ||
| 8193 | (should (eq (buffer-modified-p) 'autosaved))))) | ||
| 8194 | |||
| 8195 | (ert-deftest test-buffer-chars-modified-ticks () | ||
| 8196 | "Test `buffer-chars-modified-tick'." | ||
| 8197 | (setq temporary-file-directory (file-truename temporary-file-directory)) | ||
| 8198 | (let ((text "foobar") | ||
| 8199 | f1 f2) | ||
| 8200 | (unwind-protect | ||
| 8201 | (progn | ||
| 8202 | (setq f1 (make-temp-file "buf-modiff-tests") | ||
| 8203 | f2 (make-temp-file "buf-modiff-tests")) | ||
| 8204 | (with-current-buffer (find-file f1) | ||
| 8205 | (should (= (buffer-chars-modified-tick) 1)) | ||
| 8206 | (should (= (buffer-chars-modified-tick) (buffer-modified-tick))) | ||
| 8207 | (write-region text nil f2 nil 'silent) | ||
| 8208 | (insert-file-contents f2) | ||
| 8209 | (should (= (buffer-chars-modified-tick) (buffer-modified-tick))) | ||
| 8210 | (should (> (buffer-chars-modified-tick) 1)))) | ||
| 8211 | (if f1 (delete-file f1)) | ||
| 8212 | (if f2 (delete-file f2)) | ||
| 8213 | ))) | ||
| 8214 | |||
| 7736 | ;;; buffer-tests.el ends here | 8215 | ;;; buffer-tests.el ends here |