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:32:40 -0700 Message-ID: <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="27337"; mail-complaints-to="usenet@ciao.gmane.io" 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:34:27 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 1oMMNO-0006oW-LN for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 12 Aug 2022 06:34:27 +0200 Original-Received: from localhost ([::1]:51314 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oMMNN-0003vj-3Y for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 12 Aug 2022 00:34:25 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51924) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oMMN0-0003vL-JJ for bug-gnu-emacs@gnu.org; Fri, 12 Aug 2022 00:34:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:37342) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oMMN0-0004Eh-A1 for bug-gnu-emacs@gnu.org; Fri, 12 Aug 2022 00:34:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oMMN0-0004sj-5f for bug-gnu-emacs@gnu.org; Fri, 12 Aug 2022 00:34: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:34:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 57150 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.166027879818704 (code B ref -1); Fri, 12 Aug 2022 04:34:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 12 Aug 2022 04:33:18 +0000 Original-Received: from localhost ([127.0.0.1]:55323 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oMMMH-0004rb-JS for submit@debbugs.gnu.org; Fri, 12 Aug 2022 00:33:17 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:38612) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oMMME-0004rT-VV for submit@debbugs.gnu.org; Fri, 12 Aug 2022 00:33:15 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51722) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oMMLs-0003qy-Q1 for bug-gnu-emacs@gnu.org; Fri, 12 Aug 2022 00:33:05 -0400 Original-Received: from relay9-d.mail.gandi.net ([217.70.183.199]:39187) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oMMLp-00049Y-HZ for bug-gnu-emacs@gnu.org; Fri, 12 Aug 2022 00:32:51 -0400 Original-Received: (Authenticated sender: matt@rfc20.org) by mail.gandi.net (Postfix) with ESMTPSA id AA38EFF802 for ; Fri, 12 Aug 2022 04:32:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rfc20.org; s=gm1; t=1660278765; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=b89JfyotsG24uElfTDtKusO9vFm5Xl4zId22Aal5b8A=; b=Bkkt0dRpyz3QaJKKoaTA+yqX4FtgZmDFjjdFXnz3JYOgCLbPBWeRi8+Kqj1nqFrGOuJc8p 1cw0JH9MFHP7wtvf6cSUIQR/jtFodde/8yFVKd3wrF6vBfzv7nCqBDFkCq208KlNxHofni tCXcIfljVxP2JfQQVIW+jhpYrQc0KochlkytkpSJQUwKmoNHVmyLj6sgIRd182KdJfWkJ5 E828qiuBJ4dKllidtC4aIZ+VWf2lBnnf+NgbGqKWTJ8Yc4Qcqov0GDLI8hoKaDi5QlwW6j G4uC07pu1bD9dAuSdnrGh+LJqsnrM/u7evzxzY/jdQDEEOlys08CgfVaCMg44A== Original-Received: from matt by naz with local (Exim 4.96) (envelope-from ) id 1oMMLg-0009lF-2E for bug-gnu-emacs@gnu.org; Thu, 11 Aug 2022 21:32:40 -0700 Received-SPF: pass client-ip=217.70.183.199; envelope-from=matt@rfc20.org; helo=relay9-d.mail.gandi.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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:239381 Archived-At: --=-=-= Content-Type: text/plain 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. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Add-test-coverage-for-overlay-modification-hooks.patch >From 9083709cbe12ab97b795bcac8343f9d11f2929b7 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 | 66 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/test/src/buffer-tests.el b/test/src/buffer-tests.el index 3c6a9208ff..ee25b43f9e 100644 --- a/test/src/buffer-tests.el +++ b/test/src/buffer-tests.el @@ -22,6 +22,72 @@ (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 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 --=-=-=--