unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Test comment-search-backward
@ 2017-09-10 12:24 N. Raghavendra
  2017-09-20 16:10 ` N. Raghavendra
  0 siblings, 1 reply; 2+ messages in thread
From: N. Raghavendra @ 2017-09-10 12:24 UTC (permalink / raw)
  To: emacs-devel

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/



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-09-20 16:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-10 12:24 Test comment-search-backward N. Raghavendra
2017-09-20 16:10 ` N. Raghavendra

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).