all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "N. Raghavendra" <nyraghu27132@gmail.com>
To: emacs-devel@gnu.org
Subject: Test comment-search-backward
Date: Sun, 10 Sep 2017 17:54:57 +0530	[thread overview]
Message-ID: <87wp56u4fa.fsf@gmail.com> (raw)

I am using Emacs 26.0.50.1.  While testing some functions that I had
defined, I came across a behaviour of `comment-search-backward' that
seems to be at odds with its docstring:

----------------------------------------------------------------------
(comment-search-backward &optional LIMIT NOERROR)

Find a comment start between LIMIT and point.
Moves point to inside the comment and returns the position of the
comment-starter.  If no comment is found, moves point to LIMIT
and raises an error or returns nil if NOERROR is non-nil.

Ensure that ‘comment-normalize-vars’ has been called before you use this.
----------------------------------------------------------------------

Here is a file which, I think, defines a test of this behaviour:

[/tmp]$ cat test.el
----------------------------------------------------------------------
(ert-deftest test-comment-search-backward-absent ()
  "Test `comment-search-backward' when there is no comment in context.
Check that when there is no comment in the portion of the buffer between
the search limit and point, it moves point to the search limit and raises
an error."
  (with-temp-buffer
    (emacs-lisp-mode)
    (comment-normalize-vars)
    (insert "(require 'foo)
\(bar) ; first comment
;; second comment
\(provide 'baz)")
    (let ((limit (save-excursion (search-backward "second"))))
      (should (equal (should-error (comment-search-backward limit))
                     '(error "No comment")))
      (should (= (point) limit)))))
----------------------------------------------------------------------

Running the test fails:

[/tmp]$ emacs -Q --batch --load=test.el --funcall=ert-run-tests-batch-and-exit
----------------------------------------------------------------------
(ert-test-failed
     ((should
       (=
        (point)
        limit))
      :form
      (= 70 41)
      :value nil))
   FAILED  1/1  test-comment-search-backward-absent
----------------------------------------------------------------------

It looks like `comment-search-backward' does raise an error as promised,
but does not move point to LIMIT from its previous position at the end
of the buffer.

Is there something I am missing?

Thanks,
Raghu.

--
N. Raghavendra <raghu@hri.res.in>, http://www.retrotexts.net/
Harish-Chandra Research Institute, http://www.hri.res.in/



             reply	other threads:[~2017-09-10 12:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-10 12:24 N. Raghavendra [this message]
2017-09-20 16:10 ` Test comment-search-backward N. Raghavendra

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=87wp56u4fa.fsf@gmail.com \
    --to=nyraghu27132@gmail.com \
    --cc=emacs-devel@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 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.