From: Marcin Borkowski <mbork@mbork.pl>
To: Alan Mackenzie <acm@muc.de>
Cc: Eli Zaretskii <eliz@gnu.org>,
ccsmile2008@outlook.com, npostavs@gmail.com, emacs-devel@gnu.org
Subject: Re: beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode]
Date: Mon, 26 Mar 2018 08:57:18 +0200 [thread overview]
Message-ID: <878taf1fzl.fsf@mbork.pl> (raw)
In-Reply-To: <20180103162403.GB5435@ACM>
[-- Attachment #1: Type: text/plain, Size: 312 bytes --]
On 2018-01-03, at 17:24, Alan Mackenzie <acm@muc.de> wrote:
> These things are tricky to test properly. ;-)
Fair enough. But we should at least try to prepare a regression test
when a bug pops its head. ;-)
I attach a set of two patches wit such a test. WDYT?
Best,
--
Marcin Borkowski
http://mbork.pl
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-a-more-general-tests-with-temp-buffer-macro.patch --]
[-- Type: text/x-patch; size=2.61KiB, Size: 2671 bytes --]
From fb6fa889ec026f2b5d265a043ae5c7e0813aa7c5 Mon Sep 17 00:00:00 2001
From: Marcin Borkowski <mbork@mbork.pl>
Date: Tue, 6 Mar 2018 06:46:10 +0100
Subject: [PATCH 1/2] Add a more general "tests-with-temp-buffer" macro
---
test/lisp/emacs-lisp/lisp-tests.el | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/test/lisp/emacs-lisp/lisp-tests.el b/test/lisp/emacs-lisp/lisp-tests.el
index 07eddb74d5..ec197602b6 100644
--- a/test/lisp/emacs-lisp/lisp-tests.el
+++ b/test/lisp/emacs-lisp/lisp-tests.el
@@ -307,12 +307,12 @@ backward-up-list-basic
;;; Helpers
(eval-and-compile
- (defvar elisp-test-point-position-regex "=!\\([a-zA-Z0-9-]+\\)="
+ (defvar test-point-position-regex "=!\\([a-zA-Z0-9-]+\\)="
"A regexp matching placeholders for point position for
`elisp-tests-with-temp-buffer'."))
;; Copied and heavily modified from `python-tests-with-temp-buffer'
-(defmacro elisp-tests-with-temp-buffer (contents &rest body)
+(defmacro tests-with-temp-buffer (mode contents &rest body)
"Create an `emacs-lisp-mode' enabled temp buffer with CONTENTS.
BODY is the code to be executed within the temp buffer. Point is
always located at the beginning of buffer. CONTENTS is an
@@ -320,12 +320,12 @@ elisp-tests-with-temp-buffer
of the form =!NAME= in CONTENTS are removed, and a for each one a
variable called NAME is bound to the position of the word's
start."
- (declare (indent 1) (debug (def-form body)))
+ (declare (indent 2) (debug (def-form body)))
(let* ((var-pos nil)
(text (with-temp-buffer
(insert (eval contents))
(goto-char (point-min))
- (while (re-search-forward elisp-test-point-position-regex nil t)
+ (while (re-search-forward test-point-position-regex nil t)
(push (list (intern (match-string-no-properties 1))
(match-beginning 0))
var-pos)
@@ -333,7 +333,7 @@ elisp-tests-with-temp-buffer
(match-end 0)))
(buffer-string))))
`(with-temp-buffer
- (emacs-lisp-mode)
+ (,mode)
(insert ,text)
(goto-char (point-min))
(let ,var-pos
@@ -341,6 +341,11 @@ elisp-tests-with-temp-buffer
,@(mapcar (lambda (v-p) `(ignore ,(car v-p))) var-pos)
,@body))))
+(defmacro elisp-tests-with-temp-buffer (contents &rest body)
+ "Use TESTS-WITH-TEMP-BUFFER with Emacs Lisp mode."
+ (declare (indent 1) (debug (def-form body)))
+ `(tests-with-temp-buffer emacs-lisp-mode ,contents ,@body))
+
;;; mark-defun
(eval-and-compile
--
2.16.2
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-Add-a-regression-test-for-beginning-of-defun-comment.patch --]
[-- Type: text/x-patch; size=1.09KiB, Size: 1116 bytes --]
From 098f49607e19a3246b087afbebb624a3736ef300 Mon Sep 17 00:00:00 2001
From: Marcin Borkowski <mbork@mbork.pl>
Date: Mon, 19 Mar 2018 06:17:31 +0100
Subject: [PATCH 2/2] Add a regression test for `beginning-of-defun-comments`
---
test/lisp/emacs-lisp/lisp-tests.el | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/test/lisp/emacs-lisp/lisp-tests.el b/test/lisp/emacs-lisp/lisp-tests.el
index ec197602b6..b456a65737 100644
--- a/test/lisp/emacs-lisp/lisp-tests.el
+++ b/test/lisp/emacs-lisp/lisp-tests.el
@@ -372,6 +372,26 @@ elisp-tests-with-temp-buffer
"
"Test buffer for `mark-defun'."))
+(ert-deftest mark-defun-c-mode ()
+ "Test `mark-defun` in C mode."
+ (setq last-command nil)
+ (tests-with-temp-buffer c-mode
+ "int test_func1(int a)
+{
+ int i;
+
+ return 0;
+}
+=!beg-of-defun=int test_func2(int a)
+{
+ int i=!inside-2=;
+
+ return 0;
+}"
+ (goto-char inside-2)
+ (mark-defun)
+ (should (= (point) beg-of-defun))))
+
(ert-deftest mark-defun-no-arg-region-inactive ()
"Test `mark-defun' with no prefix argument and inactive
region."
--
2.16.2
next prev parent reply other threads:[~2018-03-26 6:57 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-30 9:49 26.0.90: mark-defun problem in c-mode zhang cc
2017-12-30 10:30 ` Eli Zaretskii
2017-12-30 10:34 ` Alan Mackenzie
2017-12-30 12:01 ` beginning-of-defun-comments bug [was: Re: 26.0.90: mark-defun problem in c-mode] Alan Mackenzie
2017-12-30 12:53 ` Eli Zaretskii
2017-12-30 13:05 ` Alan Mackenzie
2018-01-03 4:51 ` Marcin Borkowski
2018-01-03 16:24 ` Alan Mackenzie
2018-01-05 14:55 ` zhang cc
2018-01-06 12:00 ` Alan Mackenzie
2018-01-06 13:54 ` zhang cc
2018-01-07 6:25 ` Marcin Borkowski
2018-03-26 6:57 ` Marcin Borkowski [this message]
2017-12-30 15:43 ` Alan Mackenzie
2017-12-30 18:43 ` Stephen Leake
2017-12-31 10:55 ` Alan Mackenzie
2017-12-31 4:26 ` Stefan Monnier
2017-12-31 10:50 ` Alan Mackenzie
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=878taf1fzl.fsf@mbork.pl \
--to=mbork@mbork.pl \
--cc=acm@muc.de \
--cc=ccsmile2008@outlook.com \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
--cc=npostavs@gmail.com \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.