From 2fc6e715a2931523a52d541d5b9868ca6cb144ff Mon Sep 17 00:00:00 2001 From: Matt Armstrong Date: Fri, 4 Nov 2022 15:02:17 -0700 Subject: [PATCH] Tweak the overlay related `insert-before-markers' tests * test/src/buffer-tests.el (test-overlay-insert-before-markers-empty): Move code down to the other tests related to insertion. Test all front/rear insert combinations. To make the test more clear, at least to me, hard code all character positions. (test-overlay-insert-before-markers-at-start): For both front-advance modes verify that `insert-before-markers' at and overlay's start advances it. (test-overlay-insert-before-markers-at-end): For both rear-advance modes test that `insert-before-markers' at an overlay's end advances it. (test-overlay-insert-before-markers-non-empty): Delete, replaced by the two tests above. --- test/src/buffer-tests.el | 61 +++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/test/src/buffer-tests.el b/test/src/buffer-tests.el index a39d7d51de1..0e9e84ef7a1 100644 --- a/test/src/buffer-tests.el +++ b/test/src/buffer-tests.el @@ -528,28 +528,6 @@ with parameters from the *Messages* buffer modification." (deftest-overlay-start/end-1 L (1 0) (1 1)) (deftest-overlay-start/end-1 M (0 0) (1 1)) -(ert-deftest test-overlay-insert-before-markers-empty () - (with-temp-buffer - (insert "1234") - (goto-char (1+ (point-min))) - (let ((overlay (make-overlay (point) (point)))) - (insert-before-markers "x") - (should (equal (point) (overlay-end overlay))) - (should (equal (point) (overlay-start overlay)))))) - -(ert-deftest test-overlay-insert-before-markers-non-empty () - (with-temp-buffer - (insert "1234") - (goto-char (+ 2 (point))) - (let ((overlay (make-overlay (1- (point)) (point)))) - (insert-before-markers "x") - (should (equal (point) (overlay-end overlay))) - (should (equal (- (point) 2) (overlay-start overlay))) - (forward-char -2) - (insert-before-markers "y") - (should (equal (+ 2 (point)) (overlay-end overlay))) - (should (equal (point) (overlay-start overlay)))))) - (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))))) @@ -1315,7 +1293,46 @@ Regression test for bug#58706." (delete-overlay left) (should (= 2 (length (overlays-in 1 (point-max)))))))) +;; +==========================================================================+ +;; | Moving overlays with insert-before-markers +;; +==========================================================================+ +(ert-deftest test-overlay-insert-before-markers-at-start () + "`insert-before-markers' always advances an overlay's start. +Test both front-advance and non-front-advance overlays." + (dolist (front-advance '(nil t)) + (ert-info ((format "front-advance %S" front-advance)) + (with-temp-buffer + (insert "1234") + (let ((overlay (make-overlay 2 3 nil front-advance nil))) + (goto-char 2) + (insert-before-markers "x") + (should (equal 3 (overlay-start overlay))) + (should (equal 4 (overlay-end overlay)))))))) + +(ert-deftest test-overlay-insert-before-markers-at-end () + "`insert-before-markers' always advances an overlay's end. +Test both rear-advance and non-rear-advance overlays." + (dolist (rear-advance '(nil t)) + (ert-info ((format "rear-advance %S" rear-advance)) + (with-temp-buffer + (insert "1234") + (let ((overlay (make-overlay 2 3 nil nil rear-advance))) + (goto-char 3) + (insert-before-markers "x") + (should (equal 2 (overlay-start overlay))) + (should (equal 4 (overlay-end overlay)))))))) + +(ert-deftest test-overlay-insert-before-markers-empty () + (dolist (advance-args '((nil nil) (t nil) (nil t) (t t))) + (ert-info ((format "advance args %S" advance-args)) + (with-temp-buffer + (insert "1234") + (let ((overlay (apply #'make-overlay 2 2 nil advance-args))) + (goto-char 2) + (insert-before-markers "x") + (should (equal 3 (overlay-start overlay))) + (should (equal 3 (overlay-end overlay)))))))) ;; +==========================================================================+ ;; | Moving by deletions -- 2.39.2