From: Marcin Borkowski <mbork@amu.edu.pl>
To: Eli Zaretskii <eliz@gnu.org>
Cc: rfflrccrd@gmail.com, 21072@debbugs.gnu.org
Subject: bug#21072: 24.5; inconsistent behaviour of `C-M-h (mark-defun)' in Emacs Lisp
Date: Tue, 21 Jun 2016 09:58:46 +0200 [thread overview]
Message-ID: <87shw76ki1.fsf@amu.edu.pl> (raw)
In-Reply-To: <8737omh8yk.fsf@amu.edu.pl>
On 2016-06-09, at 13:56, Marcin Borkowski <mbork@mbork.pl> wrote:
> 2b. Write a few tests for `mark-defun',_then_ fix the problem, and check
> whether these tests pass. Of course, all these tests would be for Elisp
> (and maybe for C and/or JavaScript).
Hi all,
it seems nobody cared enough to answer my question, so I made the choice
of doing the Right Thing™, and started from developing some tests for
mark-defun. Here's what I've got now.
--8<---------------cut here---------------start------------->8---
;;; elisp-mode-tests.el --- Tests for emacs-lisp-mode -*- lexical-binding: t; -*-
;; Copyright (C) 2015-2016 Free Software Foundation, Inc.
;; Author: Marcin Borkowski <mbork@mbork.pl>
;; Author: Dmitry Gutov <dgutov@yandex.ru>
;; Author: Stephen Leake <stephen_leake@member.fsf.org>
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Code:
(require 'ert)
\f
;;; Helpers
;; Copied and modified from `python-tests-with-temp-buffer'
(defmacro elisp-tests-with-temp-buffer (contents &rest body)
"Create a `emacs-lisp-mode' enabled temp buffer with CONTENTS.
BODY is code to be executed within the temp buffer. Point is
always located at the beginning of buffer."
(declare (indent 1) (debug t))
`(with-temp-buffer
(emacs-lisp-mode)
(insert ,contents)
(goto-char (point-min))
,@body))
(defmacro conditional-save-excursion (arg &rest body)
"Wrap BODY in `save-excursion', but only if ARG is non-nil."
(declare (indent 1) (debug t))
`(if ,arg
(save-excursion ,@body)
,@body))
(defun look-at (string &optional count restore-point)
"Move the point to the beginning of STRING in current buffer.
Return the new point value. If COUNT is non-nil, move to COUNTth
occurrence. If RESTORE-POINT is non-nil, return the found
position, but do not move point."
(conditional-save-excursion restore-point
(setq count (or count 1))
(when (search-forward string nil t count)
(goto-char (match-beginning 0)))
(point)))
\f
;;; Mark
(ert-deftest mark-defun-1 ()
"Test `mark-defun' with point inside the defun."
(elisp-tests-with-temp-buffer
"
\(defun func-a ()
\"A parameterless function.\"
(ignore))
;; A comment right before a defun.
\(defun func-b (argument)
\"A function with one ARGUMENT.\"
(ignore argument)
(message \"%s\" \"Argument ignored.\"))
\(defmacro macro-a (&rest body)
\"A macro with BODY.\"
`(,@body))
"
(let ((expected-mark-beginning-position-1-2
(progn
(look-at "(defun func-a ")
(previous-line 1)
(point)))
(expected-mark-end-position-1
(save-excursion
(look-at "(ignore))")
(next-line 1)
(point)))
(expected-mark-end-position-2
(save-excursion
(point)
(look-at "\"))")
(next-line 1)
(point)))
(expected-mark-beginning-position-3
(progn
(look-at "(defmacro macro-a ")
(previous-line 1)
(point)))
(expected-mark-end-position-3
(progn
(look-at "(,@body)")
(next-line 1)
(point))))
;; select the first defun
(goto-char (point-min))
(look-at "A parameterless function.")
(mark-defun)
(should (= (point) expected-mark-beginning-position-1-2))
(should (= (marker-position (mark-marker))
expected-mark-end-position-1))
;; expand to the second defun
(mark-defun 1)
(should (= (point) expected-mark-beginning-position-1-2))
(should (= (marker-position (mark-marker))
expected-mark-end-position-2))
;; select the macro
(look-at "A macro")
(mark-defun)
(should (= (point) expected-mark-beginning-position-3))
(should (= (marker-position (mark-marker))
expected-mark-end-position-3)))))
(ert-deftest mark-defun-2 ()
"Test `mark-defun' with point between defuns."
(elisp-tests-with-temp-buffer
"
\(defun func-a ()
\"A parameterless function.\"
(ignore))
;; A comment right before a defun.
\(defun func-b (argument)
\"A function with one ARGUMENT.\"
(ignore argument)
(message \"%s\" \"Argument ignored.\"))
\(defmacro macro-a (&rest body)
\"A macro with BODY.\"
`(,@body))
"
(let ((expected-mark-beginning-position-1
(progn
(look-at "(defun func-b ")
(point)))
(expected-mark-end-position-1
(save-excursion
(look-at "ignored.\"))")
(next-line 1)
(point))))
;; select the first defun
(goto-char expected-mark-end-position-1)
(previous-line 1)
(mark-defun)
(should (= (point) expected-mark-beginning-position-1))
(should (= (marker-position (mark-marker))
expected-mark-end-position-1)))))
(provide 'elisp-mode-tests)
;;; elisp-mode-tests.el ends here
--8<---------------cut here---------------end--------------->8---
These two tests pass now. The next thing would be to change them to
what /should/ pass. Before that, though, let me ask: what are your
opinion on these simple tests? Are they enough? Would you add
something?
Best,
--
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University
next prev parent reply other threads:[~2016-06-21 7:58 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-16 6:12 bug#21072: 24.5; inconsistent behaviour of `C-M-h (mark-defun)' in Emacs Lisp Raffaele Ricciardi
2016-04-25 11:11 ` Marcin Borkowski
2016-05-01 17:17 ` Eli Zaretskii
2016-05-01 17:49 ` Marcin Borkowski
2016-05-01 18:09 ` Eli Zaretskii
2016-05-01 19:45 ` Marcin Borkowski
2016-05-01 19:56 ` Eli Zaretskii
2016-05-03 18:58 ` Marcin Borkowski
2016-05-04 14:45 ` Eli Zaretskii
2016-05-06 12:27 ` Marcin Borkowski
2016-05-06 12:59 ` Eli Zaretskii
2016-05-07 3:47 ` Marcin Borkowski
2016-05-07 5:07 ` Drew Adams
2016-10-11 12:31 ` Marcin Borkowski
2016-10-11 15:30 ` Drew Adams
2016-10-11 17:07 ` Marcin Borkowski
2016-10-11 17:52 ` Clément Pit--Claudel
2016-10-11 20:26 ` Drew Adams
2016-10-11 21:15 ` Drew Adams
2016-10-28 5:35 ` Marcin Borkowski
2016-10-28 14:32 ` Drew Adams
2016-11-02 7:28 ` Marcin Borkowski
2016-11-02 18:25 ` Drew Adams
2016-11-04 7:48 ` Marcin Borkowski
2016-11-27 7:40 ` Marcin Borkowski
2016-11-27 18:51 ` Drew Adams
2017-02-07 6:22 ` Marcin Borkowski
2017-02-07 16:14 ` Drew Adams
2016-05-07 6:47 ` Eli Zaretskii
2016-06-05 6:30 ` Marcin Borkowski
2016-06-05 7:01 ` bug#21072: Forgotten attachment (was: bug#21072: 24.5; inconsistent behaviour of `C-M-h (mark-defun)' in Emacs Lisp) Marcin Borkowski
2016-06-09 11:56 ` bug#21072: 24.5; inconsistent behaviour of `C-M-h (mark-defun)' in Emacs Lisp Marcin Borkowski
2016-06-21 7:58 ` Marcin Borkowski [this message]
2016-06-21 9:05 ` Andreas Röhler
2016-06-21 10:07 ` Marcin Borkowski
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=87shw76ki1.fsf@amu.edu.pl \
--to=mbork@amu.edu.pl \
--cc=21072@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=rfflrccrd@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 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).