unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
blob 2b9552a8d81bf4996de48272a689a2d6bab32bc6 5646 bytes (raw)
name: test/lisp/help-mode-tests.el 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
 
;;; help-mode-tests.el --- Tests for help-mode.el    -*- lexical-binding: t; -*-

;; Copyright (C) 2020 Free Software Foundation, Inc.

;; Author: Simen Heggestøyl <simenheg@gmail.com>
;; Keywords:

;; 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 <https://www.gnu.org/licenses/>.

;;; Commentary:

;;

;;; Code:

(require 'ert)
(require 'help-mode)
(require 'pp)

(ert-deftest help-mode-tests-help-buffer ()
  (let ((help-xref-following nil))
    (should (equal "*Help*" (help-buffer)))))

(ert-deftest help-mode-tests-help-buffer-current-buffer ()
  (with-temp-buffer
    (help-mode)
    (let ((help-xref-following t))
      (should (equal (buffer-name (current-buffer))
                     (help-buffer))))))

(ert-deftest help-mode-tests-help-buffer-current-buffer-error ()
  (with-temp-buffer
    (let ((help-xref-following t))
      (should-error (help-buffer)))))

(ert-deftest help-mode-tests-make-xrefs ()
  (with-temp-buffer
    (insert "car is a built-in function in ‘C source code’.

(car LIST)

  Probably introduced at or before Emacs version 1.2.
  This function does not change global state, including the match data.

Return the car of LIST.  If arg is nil, return nil.
Error if arg is not nil and not a cons cell.  See also ‘car-safe’.

See Info node ‘(elisp)Cons Cells’ for a discussion of related basic
Lisp concepts such as car, cdr, cons cell and list.")
    (help-mode)
    (help-make-xrefs)
    (let ((car-safe-button (button-at 298)))
      (should (eq (button-type car-safe-button) 'help-symbol))
      (should (eq (button-get car-safe-button 'help-function)
                  #'describe-symbol)))
    (let ((cons-cells-info-button (button-at 333)))
      (should (eq (button-type cons-cells-info-button) 'help-info))
      (should (eq (button-get cons-cells-info-button 'help-function)
                  #'info)))))

(ert-deftest help-mode-tests-xref-button ()
  (with-temp-buffer
    (insert "See also the function ‘interactive’.")
    (string-match help-xref-symbol-regexp (buffer-string))
    (help-xref-button 8 'help-function)
    (should-not (button-at 22))
    (should-not (button-at 35))
    (let ((button (button-at 30)))
      (should (eq (button-type button) 'help-function)))))

(ert-deftest help-mode-tests-insert-xref-button ()
  (with-temp-buffer
    (help-insert-xref-button "[back]" 'help-back)
    (goto-char (point-min))
    (should (eq (button-type (button-at (point))) 'help-back))
    (help-insert-xref-button "[forward]" 'help-forward)
    ;; The back button should stay unchanged.
    (should (eq (button-type (button-at (point))) 'help-back))))

(ert-deftest help-mode-tests-xref-on-pp ()
  (with-temp-buffer
    (insert (pp '(cons fill-column)))
    (help-xref-on-pp (point-min) (point-max))
    (goto-char (point-min))
    (search-forward "co")
    (should (eq (button-type (button-at (point))) 'help-function))
    (search-forward "-")
    (should (eq (button-type (button-at (point))) 'help-variable))))

(ert-deftest help-mode-tests-xref-go-back ()
  (let ((help-xref-stack
         `((2 ,(lambda () (erase-buffer) (insert "bar"))))))
    (with-temp-buffer
      (insert "foo")
      (help-xref-go-back (current-buffer))
      (should (= (point) 2))
      (should (equal (buffer-string) "bar")))))

(ert-deftest help-mode-tests-xref-go-forward ()
  (let ((help-xref-forward-stack
         `((2 ,(lambda () (erase-buffer) (insert "bar"))))))
    (with-temp-buffer
      (insert "foo")
      (help-xref-go-forward (current-buffer))
      (should (= (point) 2))
      (should (equal (buffer-string) "bar")))))

(ert-deftest help-mode-tests-go-back ()
  (let ((help-xref-stack
         `((2 ,(lambda () (erase-buffer) (insert "bar"))))))
    (with-temp-buffer
      (insert "foo")
      (help-go-back)
      (should (= (point) 2))
      (should (equal (buffer-string) "bar")))))

(ert-deftest help-mode-tests-go-back-no-stack ()
  (let ((help-xref-stack '()))
    (should-error (help-go-back))))

(ert-deftest help-mode-tests-go-forward ()
  (let ((help-xref-forward-stack
         `((2 ,(lambda () (erase-buffer) (insert "bar"))))))
    (with-temp-buffer
      (insert "foo")
      (help-go-forward)
      (should (= (point) 2))
      (should (equal (buffer-string) "bar")))))

(ert-deftest help-mode-tests-go-forward-no-stack ()
  (let ((help-xref-forward-stack '()))
    (should-error (help-go-forward))))

(ert-deftest help-mode-tests-do-xref ()
  (with-temp-buffer
    (help-mode)
    (help-do-xref 0 #'describe-symbol '(car))
    (should (looking-at-p "car is a"))
    (should (string-match-p "[back]" (buffer-string)))))

(ert-deftest help-mode-tests-follow-symbol ()
  (with-temp-buffer
    (insert "car")
    (help-mode)
    (help-follow-symbol 0)
    (should (looking-at-p "car is a"))
    (should (string-match-p "[back]" (buffer-string)))))

(ert-deftest help-mode-tests-follow-symbol-no-symbol ()
  (with-temp-buffer
    (insert "fXYEWnRHI0B9w6VJqQIw")
    (help-mode)
    (should-error (help-follow-symbol 0))))

(provide 'help-mode-tests)
;;; help-mode-tests.el ends here

debug log:

solving 2b9552a8d8 ...
found 2b9552a8d8 in https://git.savannah.gnu.org/cgit/emacs.git

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

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