unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Matt Armstrong <matt@rfc20.org>
To: 57150@debbugs.gnu.org
Subject: bug#57150: 29.0.50; [PATCH] Add test coverage for overlay modification hooks
Date: Thu, 11 Aug 2022 21:41:21 -0700	[thread overview]
Message-ID: <87edxmgjke.fsf@rfc20.org> (raw)
In-Reply-To: <87ilmygjyv.fsf@rfc20.org> (Matt Armstrong's message of "Thu, 11 Aug 2022 21:32:40 -0700")

[-- Attachment #1: Type: text/plain, Size: 514 bytes --]

Matt Armstrong <matt@rfc20.org> writes:

> I noticed there was no explicit test against the overlay modification
> hook boundary conditions.  The attached patch adds some, which might
> be nice to have if a person (possibly me) someday optimizes overlay
> performance with a change in data structure.
>
> In writing this I was surprised to learn that the hooks do not behave
> differently if the overlay is `front-advance' or `rear-advance', so
> this is explicitly tested.

...follow up with a comment typo fix.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-test-coverage-for-overlay-modification-hooks.patch --]
[-- Type: text/x-diff, Size: 4206 bytes --]

From 372c894e8d33eb5271b6c19b2e2e2843197a7353 Mon Sep 17 00:00:00 2001
From: Matt Armstrong <matt@rfc20.org>
Date: Thu, 11 Aug 2022 21:11:36 -0700
Subject: [PATCH] Add test coverage for overlay modification hooks

* test/src/buffer-tests.el: (overlay-modification-hooks) new
ert-deftest.
---
 test/src/buffer-tests.el | 67 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)

diff --git a/test/src/buffer-tests.el b/test/src/buffer-tests.el
index 3c6a9208ff..381d8618aa 100644
--- a/test/src/buffer-tests.el
+++ b/test/src/buffer-tests.el
@@ -22,6 +22,73 @@
 (require 'ert)
 (require 'ert-x)
 (require 'cl-lib)
+(require 'pcase)
+
+(ert-deftest overlay-modification-hooks ()
+  "Test the `modification-hooks' overlay property.
+
+This also tests `insert-in-front-hooks' and `insert-behind-hooks'."
+  ;; Perform operation against the given needle (a position or string)
+  ;; and expect the `modification-hook', `insert-in-front-hooks' and
+  ;; `insert-behind-hooks' to be called with the given arguments.  All
+  ;; tests are performed against the same fixed buffer and overlay.
+  (pcase-dolist (`(,operation
+                   ,needle
+                   ,expected-insert-in-front-calls
+                   ,expected-modification-calls
+                   ,expected-insert-behind-calls)
+                 '((insert 1 nil nil nil)
+                   (insert 2 ((nil 2 2) (t 2 3 0)) nil nil)
+                   (insert 3 nil ((nil 3 3) (t 3 4 0)) nil)
+                   (insert 4 nil nil ((nil 4 4) (t 4 5 0)))
+                   (insert 5 nil nil nil)
+                   (replace "1" nil nil nil)
+                   (replace "2" nil ((nil 2 3) (t 2 3 1)) nil)
+                   (replace "3" nil ((nil 3 4) (t 3 4 1)) nil)
+                   (replace "4" nil nil nil)
+                   (replace "12" nil ((nil 1 3) (t 1 2 2)) nil)
+                   (replace "23" nil ((nil 2 4) (t 2 3 2)) nil)
+                   (replace "34" nil ((nil 3 5) (t 3 4 2)) nil)
+                   (replace "123" nil ((nil 1 4) (t 1 2 3)) nil)
+                   (replace "234" nil ((nil 2 5) (t 2 3 3)) nil)
+                   (replace "1234" nil ((nil 1 5) (t 1 2 4)) nil)))
+    ;; All three hooks ignore the overlay's `front-advance' and
+    ;; `rear-advance' option, so test both ways and expect the same
+    ;; result.
+    (dolist (advance '(nil t))
+      (with-temp-buffer
+        (insert "1234")
+        (let (modification-calls insert-in-front-calls insert-behind-calls
+              (overlay (make-overlay 2 4 nil advance advance)))
+          (overlay-put overlay
+                       'modification-hooks
+                       (list (lambda (ov &rest args)
+                               (should inhibit-modification-hooks)
+                               (should (eq ov overlay))
+                               (push args modification-calls))))
+          (overlay-put overlay
+                       'insert-in-front-hooks
+                       (list (lambda (ov &rest args)
+                               (should inhibit-modification-hooks)
+                               (should (eq ov overlay))
+                               (push args insert-in-front-calls))))
+          (overlay-put overlay
+                       'insert-behind-hooks
+                       (list (lambda (ov &rest args)
+                               (should inhibit-modification-hooks)
+                               (should (eq ov overlay))
+                               (push args insert-behind-calls))))
+          (pcase-exhaustive operation
+            (`insert (goto-char needle)
+                     (insert "x"))
+            (`replace (goto-char (point-min))
+                      (replace-string needle "x")))
+          (should (equal (reverse insert-in-front-calls)
+                         expected-insert-in-front-calls))
+          (should (equal (reverse modification-calls)
+                         expected-modification-calls))
+          (should (equal (reverse insert-behind-calls)
+                         expected-insert-behind-calls)))))))
 
 (ert-deftest overlay-modification-hooks-message-other-buf ()
   "Test for bug#21824.
-- 
2.35.1


  reply	other threads:[~2022-08-12  4:41 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-12  4:32 bug#57150: 29.0.50; [PATCH] Add test coverage for overlay modification hooks Matt Armstrong
2022-08-12  4:41 ` Matt Armstrong [this message]
2022-08-12  6:19   ` Eli Zaretskii
2022-08-12 17:57     ` Matt Armstrong
2022-08-12 18:53       ` Eli Zaretskii
2022-08-14  4:52     ` Matt Armstrong
2022-08-14  7:15       ` Eli Zaretskii
2022-09-04 21:59       ` Lars Ingebrigtsen
2022-08-13  4:07 ` Ihor Radchenko
2022-08-14  0:44   ` Matt Armstrong
2022-08-15  4:14     ` Ihor Radchenko
2022-08-15 11:26       ` Eli Zaretskii
2022-08-17  2:50         ` Richard Stallman
2022-08-17 10:05           ` Ihor Radchenko
2022-08-17 11:51           ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87edxmgjke.fsf@rfc20.org \
    --to=matt@rfc20.org \
    --cc=57150@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).