[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Test comment-search-backward

From: N. Raghavendra
Subject: Test comment-search-backward
Date: Sun, 10 Sep 2017 17:54:57 +0530
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

I am using Emacs  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."
    (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
      (= 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?


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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]