Commit bcf4201d authored by Andreas Politz's avatar Andreas Politz Committed by Stefan Monnier

* test/src/buffer-tests.el: Add loads of overlay tests

Taken from the `feature/noverlay` branch.
Suggested by Vladimir Kazanov <vekazanov@gmail.com>.
parent 4c933077
Pipeline #4254 failed with stage
in 90 minutes and 4 seconds
......@@ -20,6 +20,7 @@
;;; Code:
(require 'ert)
(eval-when-compile (require 'cl-lib))
(ert-deftest overlay-modification-hooks-message-other-buf ()
"Test for bug#21824.
......@@ -94,4 +95,1222 @@ with parameters from the *Messages* buffer modification."
(insert "toto")
(move-overlay ol (point-min) (point-min)))))
;; +==========================================================================+
;; | Overlay test setup
;; +==========================================================================+
(eval-when-compile
(defun buffer-tests--make-test-name (fn x y)
(intern (format "buffer-tests--%s-%s-%s" fn x y))))
(defun buffer-tests--unmake-test-name (symbol)
(let ((name (if (stringp symbol) symbol (symbol-name symbol))))
(when (string-match "\\`buffer-tests--\\(.*\\)-\\(.*\\)-\\(.*\\)\\'" name)
(list (match-string 1 name)
(match-string 2 name)
(match-string 3 name)))))
(defmacro deftest-make-overlay-1 (id args)
(declare (indent 1))
`(ert-deftest ,(buffer-tests--make-test-name 'make-overlay 1 id) ()
(with-temp-buffer
(should ,(cons 'make-overlay args)))))
(defmacro deftest-make-overlay-2 (id args condition)
(declare (indent 1))
`(ert-deftest ,(buffer-tests--make-test-name 'make-overlay 2 id) ()
(with-temp-buffer
(should-error
,(cons 'make-overlay args)
:type ',condition
:exclude-subtypes t))))
(defmacro deftest-overlay-start/end-1 (id start-end-args start-end-should)
(declare (indent 1))
(cl-destructuring-bind (start end sstart send)
(append start-end-args start-end-should)
`(ert-deftest ,(buffer-tests--make-test-name 'overlay-start/end 1 id) ()
(with-temp-buffer
(insert (make-string 9 ?\n))
(let ((ov (make-overlay ,start ,end)))
(should (equal ,sstart (overlay-start ov)))
(should (equal ,send (overlay-end ov))))))))
(defmacro deftest-overlay-buffer-1 (id arg-expr should-expr)
(declare (indent 1))
`(ert-deftest ,(buffer-tests--make-test-name 'overlay-buffer 1 id) ()
(with-temp-buffer
(should (equal (overlay-buffer (make-overlay 1 1 ,arg-expr))
,should-expr)))))
(defmacro deftest-overlayp-1 (id arg-expr should-expr)
(declare (indent 1))
`(ert-deftest ,(buffer-tests--make-test-name 'overlay-buffer 1 id) ()
(with-temp-buffer
(should (equal ,should-expr (overlayp ,arg-expr))))))
(defmacro deftest-next-overlay-change-1 (id pos result &rest ov-tuple)
`(ert-deftest ,(buffer-tests--make-test-name 'next-overlay-change 1 id) ()
(let ((tuple (copy-sequence ',ov-tuple)))
(with-temp-buffer
(insert (make-string (max 100 (if tuple
(apply #'max
(mapcar
(lambda (m) (apply #'max m))
tuple))
0))
?\n))
(dolist (tup tuple)
(make-overlay (car tup) (cadr tup)))
(should (equal (next-overlay-change ,pos)
,result))))))
(defmacro deftest-previous-overlay-change-1 (id pos result &rest ov-tuple)
`(ert-deftest ,(buffer-tests--make-test-name 'previous-overlay-change 1 id) ()
(let ((tuple ',ov-tuple))
(with-temp-buffer
(insert (make-string (max 100 (if tuple
(apply #'max
(mapcar
(lambda (m) (apply #'max m))
tuple))
0))
?\n))
(dolist (tup tuple)
(make-overlay (car tup) (cadr tup)))
(should (equal (previous-overlay-change ,pos)
,result))))))
(defmacro deftest-overlays-at-1 (id pos result &rest ov-triple)
`(ert-deftest ,(buffer-tests--make-test-name 'overlays-at 1 id) ()
(let ((pos* ,pos))
(with-temp-buffer
(insert (make-string 100 ?\s))
(should-not (memq nil ',result))
(dolist (v ',ov-triple)
(cl-destructuring-bind (tag start end)
v
(overlay-put (make-overlay start end) 'tag tag)))
(let ((ovl (overlays-at pos*)))
(should (equal (length ovl) (length ',result)))
(dolist (ov ovl)
(should (memq (overlay-get ov 'tag) ',result))))))))
(defmacro deftest-overlays-in-1 (id beg end result &rest ov-triple)
`(ert-deftest ,(buffer-tests--make-test-name 'overlays-in 1 id) ()
(let ((beg* ,beg)
(end* ,end))
(with-temp-buffer
(insert (make-string 100 ?\s))
(should-not (memq nil ',result))
(dolist (v ',ov-triple)
(cl-destructuring-bind (tag start end)
v
(overlay-put (make-overlay start end) 'tag tag)))
(let ((ovl (overlays-in beg* end*)))
(should (equal (length ovl) (length ',result)))
(dolist (ov ovl)
(should (memq (overlay-get ov 'tag) ',result))))))))
(defmacro test-with-overlay-in-buffer (symbol-beg-end-fa-ra &rest body)
(declare (indent 1))
(cl-destructuring-bind (symbol beg end &optional fa ra)
symbol-beg-end-fa-ra
`(with-temp-buffer
(insert (make-string (max 1000 (1- ,end)) ?\s))
(goto-char 1)
(let ((,symbol (make-overlay ,beg ,end nil ,fa ,ra)))
,@body))))
(defmacro deftest-overlays-equal-1 (id result ov1-args ov2-args)
`(ert-deftest ,(buffer-tests--make-test-name 'overlays-equal 1 id) ()
(cl-flet ((create-overlay (args)
(cl-destructuring-bind (start end &optional fa ra
&rest properties)
args
(let ((ov (make-overlay start end nil fa ra)))
(while properties
(overlay-put ov (pop properties) (pop properties)))
ov))))
(with-temp-buffer
(insert (make-string 1024 ?\s))
(should (,(if result 'identity 'not)
(equal (create-overlay ',ov1-args)
(create-overlay ',ov2-args))))))))
(defun buffer-tests--find-ert-test (name)
(let ((test (buffer-tests--unmake-test-name name)))
(or (and test
(cl-destructuring-bind (fn x y)
test
(let ((regexp (format "deftest-%s-%s +%s" fn x y)))
(re-search-forward regexp nil t))))
(let ((find-function-regexp-alist
(cl-remove #'buffer-tests--find-ert-test
find-function-regexp-alist :key #'cdr)))
(find-function-do-it name 'ert-deftest
#'switch-to-buffer-other-window)))))
(add-to-list 'find-function-regexp-alist
`(ert-deftest . ,#'buffer-tests--find-ert-test))
;; +==========================================================================+
;; | make-overlay
;; +==========================================================================+
;; Test if making an overlay succeeds.
(deftest-make-overlay-1 A (1 1))
(deftest-make-overlay-1 B (7 26))
(deftest-make-overlay-1 C (29 7))
(deftest-make-overlay-1 D (most-positive-fixnum 1))
(deftest-make-overlay-1 E (most-negative-fixnum 1))
(deftest-make-overlay-1 F (1 most-positive-fixnum))
(deftest-make-overlay-1 G (1 most-negative-fixnum))
(deftest-make-overlay-1 H (1 1 nil t))
(deftest-make-overlay-1 I (1 1 nil nil))
(deftest-make-overlay-1 J (1 1 nil nil nil))
(deftest-make-overlay-1 K (1 1 nil nil t))
(deftest-make-overlay-1 L (1 1 nil t t))
(deftest-make-overlay-1 M (1 1 nil "yes" "yes"))
;; Test if trying to make an overlay signals conditions.
(deftest-make-overlay-2 A () wrong-number-of-arguments)
(deftest-make-overlay-2 B (1) wrong-number-of-arguments)
(deftest-make-overlay-2 C (1 2 3 4 5 6) wrong-number-of-arguments)
(deftest-make-overlay-2 D ("1") wrong-number-of-arguments)
(deftest-make-overlay-2 E ("1" "2") wrong-type-argument)
(deftest-make-overlay-2 F (1 2 "b") wrong-type-argument)
(deftest-make-overlay-2 G (1 2 3.14) wrong-type-argument)
(deftest-make-overlay-2 H (3.14 3) wrong-type-argument)
(deftest-make-overlay-2 I (1 [1]) wrong-type-argument)
(deftest-make-overlay-2 J (1 1 (with-temp-buffer
(current-buffer)))
error)
;; +==========================================================================+
;; | overlay-start/end
;; +==========================================================================+
;; Test if the overlays return proper positions. point-max of the
;; buffer will equal 10. ARG RESULT
(deftest-overlay-start/end-1 A (1 1) (1 1))
(deftest-overlay-start/end-1 B (2 7) (2 7))
(deftest-overlay-start/end-1 C (7 2) (2 7))
(deftest-overlay-start/end-1 D (1 10) (1 10))
(deftest-overlay-start/end-1 E (1 11) (1 10))
(deftest-overlay-start/end-1 F (1 most-positive-fixnum) (1 10))
(deftest-overlay-start/end-1 G (most-positive-fixnum 1) (1 10))
(deftest-overlay-start/end-1 H (most-positive-fixnum most-positive-fixnum)
(10 10))
(deftest-overlay-start/end-1 I (100 11) (10 10))
(deftest-overlay-start/end-1 J (11 100) (10 10))
(deftest-overlay-start/end-1 K (0 1) (1 1))
(deftest-overlay-start/end-1 L (1 0) (1 1))
(deftest-overlay-start/end-1 M (0 0) (1 1))
(ert-deftest test-overlay-start/end-2 ()
(should-not (overlay-start (with-temp-buffer (make-overlay 1 1))))
(should-not (overlay-end (with-temp-buffer (make-overlay 1 1)))))
;; +==========================================================================+
;; | overlay-buffer
;; +==========================================================================+
;; Test if overlay-buffer returns appropriate values.
(deftest-overlay-buffer-1 A (current-buffer) (current-buffer))
(deftest-overlay-buffer-1 B nil (current-buffer))
(ert-deftest test-overlay-buffer-1-C ()
(should-error (make-overlay
1 1 (with-temp-buffer (current-buffer)))))
;; +==========================================================================+
;; | overlayp
;; +==========================================================================+
;; Check the overlay predicate.
(deftest-overlayp-1 A (make-overlay 1 1) t)
(deftest-overlayp-1 B (with-temp-buffer (make-overlay 1 1)) t)
(deftest-overlayp-1 C nil nil)
(deftest-overlayp-1 D 'symbol nil)
(deftest-overlayp-1 E "string" nil)
(deftest-overlayp-1 F 42 nil)
(deftest-overlayp-1 G [1 2] nil)
(deftest-overlayp-1 H (symbol-function 'car) nil)
(deftest-overlayp-1 I float-pi nil)
(deftest-overlayp-1 J (cons 1 2) nil)
(deftest-overlayp-1 K (make-hash-table) nil)
(deftest-overlayp-1 L (symbol-function 'ert-deftest) nil)
(deftest-overlayp-1 M (current-buffer) nil)
(deftest-overlayp-1 N (selected-window) nil)
(deftest-overlayp-1 O (selected-frame) nil)
;; +==========================================================================+
;; | overlay equality
;; +==========================================================================+
(deftest-overlays-equal-1 A t (1 1) (1 1))
(deftest-overlays-equal-1 B t (5 10) (5 10))
(deftest-overlays-equal-1 C nil (5 11) (5 10))
(deftest-overlays-equal-1 D t (10 20 t) (10 20))
(deftest-overlays-equal-1 E t (10 20 nil t) (10 20))
(deftest-overlays-equal-1 F t (10 20 t t) (10 20 nil t))
(deftest-overlays-equal-1 G t (10 20 t t) (10 20 t nil))
(deftest-overlays-equal-1 H t (10 20 nil nil foo 42) (10 20 nil nil foo 42))
(deftest-overlays-equal-1 I nil (10 20 nil nil foo 42) (10 20 nil nil foo 43))
;; +==========================================================================+
;; | overlay-lists
;; +==========================================================================+
;; Check whether overlay-lists returns something sensible.
(ert-deftest test-overlay-lists-1 ()
(with-temp-buffer
(should (equal (cons nil nil) (overlay-lists)))
(dotimes (i 10) (make-overlay 1 i))
(should (listp (car (overlay-lists))))
(should (listp (cdr (overlay-lists))))
(let ((list (append (car (overlay-lists))
(cdr (overlay-lists)))))
(should (= 10 (length list)))
(should (seq-every-p #'overlayp list)))))
;; +==========================================================================+
;; | overlay-put/get/properties
;; +==========================================================================+
;; Test if overlay-put properties can be retrieved by overlay-get and
;; overlay-properties.
(ert-deftest test-overlay-props-1 ()
(with-temp-buffer
(let* ((keys '(:k1 :k2 :k3))
(values '(1 "v2" v3))
(ov (make-overlay 1 1))
(n (length keys)))
(should (equal (length keys) (length values)))
(should (null (overlay-properties ov)))
;; Insert keys and values.
(dotimes (i n)
(should (equal (overlay-put ov (nth i keys) (nth i values))
(nth i values))))
;; Compare with what overlay-get says.
(dotimes (i n)
(should (equal (overlay-get ov (nth i keys))
(nth i values))))
;; Test if overlay-properties is a superset.
(dotimes (i n)
(should (equal (plist-get (overlay-properties ov)
(nth i keys))
(nth i values))))
;; Check if overlay-properties is a subset.
(should (= (length (overlay-properties ov)) (* n 2))))))
;; +==========================================================================+
;; | next-overlay-change
;; +==========================================================================+
;; Test if next-overlay-change returns RESULT if called with POS in a
;; buffer with overlays corresponding to OVS and point-max >= 100.
;; (POS RESULT &rest OVS)
;; 0 overlays
(deftest-next-overlay-change-1 A (point-min) (point-max))
(deftest-next-overlay-change-1 B (point-max) (point-max))
;; 1 non-empty overlay
(deftest-next-overlay-change-1 C 1 10 (10 20))
(deftest-next-overlay-change-1 D 10 20 (10 20))
(deftest-next-overlay-change-1 E 15 20 (10 20))
(deftest-next-overlay-change-1 F 20 (point-max) (10 20))
(deftest-next-overlay-change-1 G 30 (point-max) (10 20))
;; 1 empty overlay
(deftest-next-overlay-change-1 H 1 10 (10 10))
(deftest-next-overlay-change-1 I 10 (point-max) (10 10))
(deftest-next-overlay-change-1 J 20 (point-max) (10 10))
;; 2 non-empty, non-intersecting
(deftest-next-overlay-change-1 D 10 20 (20 30) (40 50))
(deftest-next-overlay-change-1 E 35 40 (20 30) (40 50))
(deftest-next-overlay-change-1 F 60 (point-max) (20 30) (40 50))
(deftest-next-overlay-change-1 G 30 40 (20 30) (40 50))
(deftest-next-overlay-change-1 H 50 (point-max) (20 30) (40 50))
;; 2 non-empty, intersecting
(deftest-next-overlay-change-1 I 10 20 (20 30) (25 35))
(deftest-next-overlay-change-1 J 20 25 (20 30) (25 35))
(deftest-next-overlay-change-1 K 23 25 (20 30) (25 35))
(deftest-next-overlay-change-1 L 25 30 (20 30) (25 35))
(deftest-next-overlay-change-1 M 28 30 (20 30) (25 35))
(deftest-next-overlay-change-1 N 30 35 (20 30) (25 35))
(deftest-next-overlay-change-1 O 35 (point-max) (20 30) (25 35))
(deftest-next-overlay-change-1 P 50 (point-max) (20 30) (25 35))
;; 2 non-empty, continuous
(deftest-next-overlay-change-1 Q 10 20 (20 30) (30 40))
(deftest-next-overlay-change-1 R 20 30 (20 30) (30 40))
(deftest-next-overlay-change-1 S 25 30 (20 30) (30 40))
(deftest-next-overlay-change-1 T 30 40 (20 30) (30 40))
(deftest-next-overlay-change-1 U 35 40 (20 30) (30 40))
(deftest-next-overlay-change-1 V 40 (point-max) (20 30) (30 40))
(deftest-next-overlay-change-1 W 50 (point-max) (20 30) (30 40))
;; 1 empty, 1 non-empty, non-in
(deftest-next-overlay-change-1 a 10 20 (20 20) (30 40))
(deftest-next-overlay-change-1 b 20 30 (20 30) (30 40))
(deftest-next-overlay-change-1 c 25 30 (20 30) (30 40))
(deftest-next-overlay-change-1 d 30 40 (20 30) (30 40))
(deftest-next-overlay-change-1 e 35 40 (20 30) (30 40))
(deftest-next-overlay-change-1 f 40 (point-max) (20 30) (30 40))
(deftest-next-overlay-change-1 g 50 (point-max) (20 30) (30 40))
;; 1 empty, 1 non-empty, intersecting at begin
(deftest-next-overlay-change-1 h 10 20 (20 20) (20 30))
(deftest-next-overlay-change-1 i 20 30 (20 20) (20 30))
(deftest-next-overlay-change-1 j 25 30 (20 20) (20 30))
(deftest-next-overlay-change-1 k 30 (point-max) (20 20) (20 30))
(deftest-next-overlay-change-1 l 40 (point-max) (20 20) (20 30))
;; 1 empty, 1 non-empty, intersecting at end
(deftest-next-overlay-change-1 h 10 20 (30 30) (20 30))
(deftest-next-overlay-change-1 i 20 30 (30 30) (20 30))
(deftest-next-overlay-change-1 j 25 30 (30 30) (20 30))
(deftest-next-overlay-change-1 k 30 (point-max) (20 20) (20 30))
(deftest-next-overlay-change-1 l 40 (point-max) (20 20) (20 30))
;; 1 empty, 1 non-empty, intersecting in the middle
(deftest-next-overlay-change-1 m 10 20 (25 25) (20 30))
(deftest-next-overlay-change-1 n 20 25 (25 25) (20 30))
(deftest-next-overlay-change-1 o 25 30 (25 25) (20 30))
(deftest-next-overlay-change-1 p 30 (point-max) (25 25) (20 30))
(deftest-next-overlay-change-1 q 40 (point-max) (25 25) (20 30))
;; 2 empty, intersecting
(deftest-next-overlay-change-1 r 10 20 (20 20) (20 20))
(deftest-next-overlay-change-1 s 20 (point-max) (20 20) (20 20))
(deftest-next-overlay-change-1 t 30 (point-max) (20 20) (20 20))
;; 2 empty, non-intersecting
(deftest-next-overlay-change-1 u 10 20 (20 20) (30 30))
(deftest-next-overlay-change-1 v 20 30 (20 20) (30 30))
(deftest-next-overlay-change-1 w 25 30 (20 20) (30 30))
(deftest-next-overlay-change-1 x 30 (point-max) (20 20) (30 30))
(deftest-next-overlay-change-1 y 50 (point-max) (20 20) (30 30))
;; 10 random
(deftest-next-overlay-change-1 aa 1 5
(58 66) (41 10) (9 67) (28 88) (27 43)
(24 27) (48 36) (5 90) (61 9))
(deftest-next-overlay-change-1 ab (point-max) (point-max)
(58 66) (41 10) (9 67) (28 88) (27 43)
(24 27) (48 36) (5 90) (61 9))
(deftest-next-overlay-change-1 ac 67 88
(58 66) (41 10) (9 67) (28 88) (27 43)
(24 27) (48 36) (5 90) (61 9))
;; +==========================================================================+
;; | previous-overlay-change.
;; +==========================================================================+
;; Same for previous-overlay-change.
;; 1 non-empty overlay
(deftest-previous-overlay-change-1 A (point-max) 1)
(deftest-previous-overlay-change-1 B 1 1)
(deftest-previous-overlay-change-1 C 1 1 (10 20))
(deftest-previous-overlay-change-1 D 10 1 (10 20))
(deftest-previous-overlay-change-1 E 15 10 (10 20))
(deftest-previous-overlay-change-1 F 20 10 (10 20))
(deftest-previous-overlay-change-1 G 30 20 (10 20))
;; 1 empty overlay
(deftest-previous-overlay-change-1 H 1 1 (10 10))
(deftest-previous-overlay-change-1 I 10 1 (10 10))
(deftest-previous-overlay-change-1 J 20 10 (10 10))
;; 2 non-empty, non-intersecting
(deftest-previous-overlay-change-1 D 10 1 (20 30) (40 50))
(deftest-previous-overlay-change-1 E 35 30 (20 30) (40 50))
(deftest-previous-overlay-change-1 F 60 50 (20 30) (40 50))
(deftest-previous-overlay-change-1 G 30 20 (20 30) (40 50))
(deftest-previous-overlay-change-1 H 50 40 (20 30) (40 50))
;; 2 non-empty, intersecting
(deftest-previous-overlay-change-1 I 10 1 (20 30) (25 35))
(deftest-previous-overlay-change-1 J 20 1 (20 30) (25 35))
(deftest-previous-overlay-change-1 K 23 20 (20 30) (25 35))
(deftest-previous-overlay-change-1 L 25 20 (20 30) (25 35))
(deftest-previous-overlay-change-1 M 28 25 (20 30) (25 35))
(deftest-previous-overlay-change-1 N 30 25 (20 30) (25 35))
(deftest-previous-overlay-change-1 O 35 30 (20 30) (25 35))
(deftest-previous-overlay-change-1 P 50 35 (20 30) (25 35))
;; 2 non-empty, continuous
(deftest-previous-overlay-change-1 Q 10 1 (20 30) (30 40))
(deftest-previous-overlay-change-1 R 20 1 (20 30) (30 40))
(deftest-previous-overlay-change-1 S 25 20 (20 30) (30 40))
(deftest-previous-overlay-change-1 T 30 20 (20 30) (30 40))
(deftest-previous-overlay-change-1 U 35 30 (20 30) (30 40))
(deftest-previous-overlay-change-1 V 40 30 (20 30) (30 40))
(deftest-previous-overlay-change-1 W 50 40 (20 30) (30 40))
;; 1 empty, 1 non-empty, non-intersecting
(deftest-previous-overlay-change-1 a 10 1 (20 20) (30 40))
(deftest-previous-overlay-change-1 b 20 1 (20 30) (30 40))
(deftest-previous-overlay-change-1 c 25 20 (20 30) (30 40))
(deftest-previous-overlay-change-1 d 30 20 (20 30) (30 40))
(deftest-previous-overlay-change-1 e 35 30 (20 30) (30 40))
(deftest-previous-overlay-change-1 f 40 30 (20 30) (30 40))
(deftest-previous-overlay-change-1 g 50 40 (20 30) (30 40))
;; 1 empty, 1 non-empty, intersecting at begin
(deftest-previous-overlay-change-1 h 10 1 (20 20) (20 30))
(deftest-previous-overlay-change-1 i 20 1 (20 20) (20 30))
(deftest-previous-overlay-change-1 j 25 20 (20 20) (20 30))
(deftest-previous-overlay-change-1 k 30 20 (20 20) (20 30))
(deftest-previous-overlay-change-1 l 40 30 (20 20) (20 30))
;; 1 empty, 1 non-empty, intersecting at end
(deftest-previous-overlay-change-1 m 10 1 (30 30) (20 30))
(deftest-previous-overlay-change-1 n 20 1 (30 30) (20 30))
(deftest-previous-overlay-change-1 o 25 20 (30 30) (20 30))
(deftest-previous-overlay-change-1 p 30 20 (20 20) (20 30))
(deftest-previous-overlay-change-1 q 40 30 (20 20) (20 30))
;; 1 empty, 1 non-empty, intersectig in the middle
(deftest-previous-overlay-change-1 r 10 1 (25 25) (20 30))
(deftest-previous-overlay-change-1 s 20 1 (25 25) (20 30))
(deftest-previous-overlay-change-1 t 25 20 (25 25) (20 30))
(deftest-previous-overlay-change-1 u 30 25 (25 25) (20 30))
(deftest-previous-overlay-change-1 v 40 30 (25 25) (20 30))
;; 2 empty, intersecting
(deftest-previous-overlay-change-1 w 10 1 (20 20) (20 20))
(deftest-previous-overlay-change-1 x 20 1 (20 20) (20 20))
(deftest-previous-overlay-change-1 y 30 20 (20 20) (20 20))
;; 2 empty, non-intersecting
(deftest-previous-overlay-change-1 z 10 1 (20 20) (30 30))
(deftest-previous-overlay-change-1 aa 20 1 (20 20) (30 30))
(deftest-previous-overlay-change-1 ab 25 20 (20 20) (30 30))
(deftest-previous-overlay-change-1 ac 30 20 (20 20) (30 30))
(deftest-previous-overlay-change-1 ad 50 30 (20 20) (30 30))
;; 10 random
(deftest-previous-overlay-change-1 ae 100 90
(58 66) (41 10) (9 67) (28 88) (27 43)
(24 27) (48 36) (5 90) (61 9))
(deftest-previous-overlay-change-1 af (point-min) (point-min)
(58 66) (41 10) (9 67) (28 88) (27 43)
(24 27) (48 36) (5 90) (61 9))
(deftest-previous-overlay-change-1 ag 29 28
(58 66) (41 10) (9 67) (28 88) (27 43)
(24 27) (48 36) (5 90) (61 9))
;; +==========================================================================+
;; | overlays-at
;; +==========================================================================+
;; Test whether overlay-at returns RESULT at POS after overlays OVL were
;; created in a buffer. POS RES OVL
(deftest-overlays-at-1 A 1 ())
;; 1 overlay
(deftest-overlays-at-1 B 10 (a) (a 10 20))
(deftest-overlays-at-1 C 15 (a) (a 10 20))
(deftest-overlays-at-1 D 19 (a) (a 10 20))
(deftest-overlays-at-1 E 20 () (a 10 20))
(deftest-overlays-at-1 F 1 () (a 10 20))
;; 2 non-empty overlays non-intersecting
(deftest-overlays-at-1 G 1 () (a 10 20) (b 30 40))
(deftest-overlays-at-1 H 10 (a) (a 10 20) (b 30 40))
(deftest-overlays-at-1 I 15 (a) (a 10 20) (b 30 40))
(deftest-overlays-at-1 K 20 () (a 10 20) (b 30 40))
(deftest-overlays-at-1 L 25 () (a 10 20) (b 30 40))
(deftest-overlays-at-1 M 30 (b) (a 10 20) (b 30 40))
(deftest-overlays-at-1 N 35 (b) (a 10 20) (b 30 40))
(deftest-overlays-at-1 O 40 () (a 10 20) (b 30 40))
(deftest-overlays-at-1 P 50 () (a 10 20) (b 30 40))
;; 2 non-empty overlays intersecting
(deftest-overlays-at-1 G 1 () (a 10 30) (b 20 40))
(deftest-overlays-at-1 H 10 (a) (a 10 30) (b 20 40))
(deftest-overlays-at-1 I 15 (a) (a 10 30) (b 20 40))
(deftest-overlays-at-1 K 20 (a b) (a 10 30) (b 20 40))
(deftest-overlays-at-1 L 25 (a b) (a 10 30) (b 20 40))
(deftest-overlays-at-1 M 30 (b) (a 10 30) (b 20 40))
(deftest-overlays-at-1 N 35 (b) (a 10 30) (b 20 40))
(deftest-overlays-at-1 O 40 () (a 10 30) (b 20 40))
(deftest-overlays-at-1 P 50 () (a 10 30) (b 20 40))
;; 2 non-empty overlays continuous
(deftest-overlays-at-1 G 1 () (a 10 20) (b 20 30))
(deftest-overlays-at-1 H 10 (a) (a 10 20) (b 20 30))
(deftest-overlays-at-1 I 15 (a) (a 10 20) (b 20 30))
(deftest-overlays-at-1 K 20 (b) (a 10 20) (b 20 30))
(deftest-overlays-at-1 L 25 (b) (a 10 20) (b 20 30))
(deftest-overlays-at-1 M 30 () (a 10 20) (b 20 30))
;; overlays-at never returns empty overlays.
(deftest-overlays-at-1 N 1 (a) (a 1 60) (c 1 1) (b 30 30) (d 50 50))
(deftest-overlays-at-1 O 20 (a) (a 1 60) (c 1 1) (b 30 30) (d 50 50))
(deftest-overlays-at-1 P 30 (a) (a 1 60) (c 1 1) (b 30 30) (d 50 50))
(deftest-overlays-at-1 Q 40 (a) (a 1 60) (c 1 1) (b 30 30) (d 50 50))
(deftest-overlays-at-1 R 50 (a) (a 1 60) (c 1 1) (b 30 30) (d 50 50))
(deftest-overlays-at-1 S 60 () (a 1 60) (c 1 1) (b 30 30) (d 50 50))
;; behaviour at point-min and point-max
(ert-deftest test-overlays-at-2 ()
(cl-macrolet ((should-length (n list)
`(should (= ,n (length ,list)))))
(with-temp-buffer
(insert (make-string 100 ?\s))
(make-overlay 1 (point-max))
(make-overlay 10 10)
(make-overlay 20 20)
(make-overlay (point-max) (point-max))
(should-length 1 (overlays-at 1))
(should-length 1 (overlays-at 10))
(should-length 1 (overlays-at 20))
(should-length 0 (overlays-at (point-max)))
(narrow-to-region 10 20)
(should-length 1 (overlays-at (point-min)))
(should-length 1 (overlays-at 15))
(should-length 1 (overlays-at (point-max))))))
;; +==========================================================================+
;; | overlay-in
;; +==========================================================================+
;; Test whether overlays-in returns RES in BEG,END after overlays OVL were
;; created in a buffer.
(deftest-overlays-in-1 A 1 (point-max) ());;POS RES OVL
;; 1 overlay
(deftest-overlays-in-1 B 1 10 () (a 10 20))
(deftest-overlays-in-1 C 5 10 () (a 10 20))
(deftest-overlays-in-1 D 5 15 (a) (a 10 20))
(deftest-overlays-in-1 E 10 15 (a) (a 10 20))
(deftest-overlays-in-1 F 10 20 (a) (a 10 20))
(deftest-overlays-in-1 G 15 20 (a) (a 10 20))
(deftest-overlays-in-1 H 15 25 (a) (a 10 20))
(deftest-overlays-in-1 I 20 25 () (a 10 20))
(deftest-overlays-in-1 J 30 50 () (a 10 20))
;; 2 non-empty overlays non-intersecting
(deftest-overlays-in-1 K 1 5 () (a 10 20) (b 30 40))
(deftest-overlays-in-1 L 5 10 () (a 10 20) (b 30 40))
(deftest-overlays-in-1 M 5 15 (a) (a 10 20) (b 30 40))
(deftest-overlays-in-1 N 10 15 (a) (a 10 20) (b 30 40))
(deftest-overlays-in-1 O 15 20 (a) (a 10 20) (b 30 40))
(deftest-overlays-in-1 P 15 25 (a) (a 10 20) (b 30 40))
(deftest-overlays-in-1 Q 20 25 () (a 10 20) (b 30 40))
(deftest-overlays-in-1 R 20 30 () (a 10 20) (b 30 40))
(deftest-overlays-in-1 S 25 30 () (a 10 20) (b 30 40))
(deftest-overlays-in-1 T 25 35 (b) (a 10 20) (b 30 40))
(deftest-overlays-in-1 U 30 35 (b) (a 10 20) (b 30 40))
(deftest-overlays-in-1 V 40 50 () (a 10 20) (b 30 40))
(deftest-overlays-in-1 W 50 60 () (a 10 20) (b 30 40))
(deftest-overlays-in-1 X 1 50 (a b) (a 10 20) (b 30 40))
(deftest-overlays-in-1 Y 10 40 (a b) (a 10 20) (b 30 40))
(deftest-overlays-in-1 Z 10 41 (a b) (a 10 20) (b 30 40))
;; 2 non-empty overlays intersecting
(deftest-overlays-in-1 a 1 5 () (a 10 30) (b 20 40))
(deftest-overlays-in-1 b 5 10 () (a 10 30) (b 20 40))
(deftest-overlays-in-1 c 5 15 (a) (a 10 30) (b 20 40))
(deftest-overlays-in-1 d 10 15 (a) (a 10 30) (b 20 40))
(deftest-overlays-in-1 e 10 20 (a) (a 10 30) (b 20 40))
(deftest-overlays-in-1 f 15 20 (a) (a 10 30) (b 20 40))
(deftest-overlays-in-1 g 20 30 (a b) (a 10 30) (b 20 40))
(deftest-overlays-in-1 h 20 40 (a b) (a 10 30) (b 20 40))
(deftest-overlays-in-1 i 25 30 (a b) (a 10 30) (b 20 40))
(deftest-overlays-in-1 j 30 30 (b) (a 10 30) (b 20 40))
(deftest-overlays-in-1 k 30 35 (b) (a 10 30) (b 20 40))
(deftest-overlays-in-1 l 35 40 (b) (a 10 30) (b 20 40))
(deftest-overlays-in-1 m 40 45 () (a 10 30) (b 20 40))
(deftest-overlays-in-1 n 41 45 () (a 10 30) (b 20 40))
(deftest-overlays-in-1 o 50 60 () (a 10 30) (b 20 40))