From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Matt Armstrong Newsgroups: gmane.emacs.bugs Subject: bug#57150: 29.0.50; [PATCH] Add test coverage for overlay modification hooks Date: Thu, 11 Aug 2022 21:41:21 -0700 Message-ID: <87edxmgjke.fsf@rfc20.org> References: <87ilmygjyv.fsf@rfc20.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25940"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) To: 57150@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Aug 12 06:42:13 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oMMUu-0006WS-Ay for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 12 Aug 2022 06:42:12 +0200 Original-Received: from localhost ([::1]:53078 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oMMUt-0006D2-6s for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 12 Aug 2022 00:42:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52934) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oMMUk-0006Ct-GB for bug-gnu-emacs@gnu.org; Fri, 12 Aug 2022 00:42:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:37347) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oMMUk-0005P8-7c for bug-gnu-emacs@gnu.org; Fri, 12 Aug 2022 00:42:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oMMUk-00054l-26 for bug-gnu-emacs@gnu.org; Fri, 12 Aug 2022 00:42:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Matt Armstrong Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 12 Aug 2022 04:42:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 57150 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 57150-submit@debbugs.gnu.org id=B57150.166027929419475 (code B ref 57150); Fri, 12 Aug 2022 04:42:02 +0000 Original-Received: (at 57150) by debbugs.gnu.org; 12 Aug 2022 04:41:34 +0000 Original-Received: from localhost ([127.0.0.1]:55329 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oMMUH-000542-Mt for submit@debbugs.gnu.org; Fri, 12 Aug 2022 00:41:34 -0400 Original-Received: from relay12.mail.gandi.net ([217.70.178.232]:46401) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oMMUE-00053l-JY for 57150@debbugs.gnu.org; Fri, 12 Aug 2022 00:41:32 -0400 Original-Received: (Authenticated sender: matt@rfc20.org) by mail.gandi.net (Postfix) with ESMTPSA id F185C200004 for <57150@debbugs.gnu.org>; Fri, 12 Aug 2022 04:41:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rfc20.org; s=gm1; t=1660279284; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=jI/hAu0/mkRFage4cpb+FvdeNd8aqXXbZ35apflFynA=; b=dcDyflshlb30uXOcMd+2RKdMWfG52xTjuaxdn3BTyLEOm64f6wzEzrk/6pQxH9LUbMahmZ ZpFOFnwfEkZ0sYADpQbS7G8h4RVnHzpuZo1I/CVxylzQqHKuM51QH0tFD2xx36tKjTGTQv FRenz+VGjvuXIMVozhTQZeLpUeIv5RfNAPECBeqqTC3nxIKYONSKBl/GLNsriZotFyLzwI yAM+CMKLODst7Jzukh+nY4WxmnRI0NzHhFMxF8vGJBzrxYutEILamxU4MwnAnxY1KqR6Up msKNamnq1ptm2nvkMupdGg0IMdsUiRo+clyxDh/LYEZn5KRQJTGFVABtYp6SJA== Original-Received: from matt by naz with local (Exim 4.96) (envelope-from ) id 1oMMU5-0009yE-2b for 57150@debbugs.gnu.org; Thu, 11 Aug 2022 21:41:21 -0700 In-Reply-To: <87ilmygjyv.fsf@rfc20.org> (Matt Armstrong's message of "Thu, 11 Aug 2022 21:32:40 -0700") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:239382 Archived-At: --=-=-= Content-Type: text/plain Matt Armstrong 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. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Add-test-coverage-for-overlay-modification-hooks.patch >From 372c894e8d33eb5271b6c19b2e2e2843197a7353 Mon Sep 17 00:00:00 2001 From: Matt Armstrong 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 --=-=-=--