summaryrefslogtreecommitdiff
path: root/test/lisp/help-tests.el
diff options
context:
space:
mode:
Diffstat (limited to 'test/lisp/help-tests.el')
-rw-r--r--test/lisp/help-tests.el304
1 files changed, 182 insertions, 122 deletions
diff --git a/test/lisp/help-tests.el b/test/lisp/help-tests.el
index 3d4293cd380..0fcaacb6443 100644
--- a/test/lisp/help-tests.el
+++ b/test/lisp/help-tests.el
@@ -55,18 +55,24 @@
(should (equal (help-split-fundoc nil t 'usage) nil))
(should (equal (help-split-fundoc nil t 'doc) nil))))
+(ert-deftest help--key-description-fontified ()
+ (should (equal (help--key-description-fontified
+ (where-is-internal #'next-line nil t))
+ "C-n"))
+ (should-not (help--key-description-fontified nil)))
+
;;; substitute-command-keys
(defmacro with-substitute-command-keys-test (&rest body)
`(cl-flet* ((test
- (lambda (orig result)
- (should (equal (substitute-command-keys orig)
- result))))
+ (lambda (orig result)
+ (should (equal (substitute-command-keys orig)
+ result))))
(test-re
- (lambda (orig regexp)
- (should (string-match (concat "^" regexp "$")
- (substitute-command-keys orig))))))
+ (lambda (orig regexp)
+ (should (string-match (concat "\\`" regexp "\\'")
+ (substitute-command-keys orig))))))
,@body))
(ert-deftest help-tests-substitute-command-keys/no-change ()
@@ -88,54 +94,105 @@
(test "\\[emacs-version]\\[next-line]" "M-x emacs-versionC-n")
(test-re "\\[emacs-version]`foo'" "M-x emacs-version[`'‘]foo['’]")))
-(ert-deftest help-tests-substitute-command-keys/keymaps ()
+(ert-deftest help-tests-substitute-command-keys/literal-key-sequence ()
+ "Literal replacement."
+ (with-substitute-command-keys-test
+ (test "\\`C-m'" "C-m")
+ (test "\\`C-m'\\`C-j'" "C-mC-j")
+ (test "foo\\`C-m'bar\\`C-j'baz" "fooC-mbarC-jbaz")
+ (test "\\`M-x next-line'" "M-x next-line")
+ (test "\\`mouse-1'" "mouse-1")))
+
+(ert-deftest help-tests-substitute-command-keys/literal-key-sequence-ignore-invalid ()
+ "Ignore any invalid literal key sequence."
(with-substitute-command-keys-test
- (test "\\{minibuffer-local-must-match-map}"
- "\
-key binding
---- -------
+ (test-re "ab\\`'cd" "ab\\\\[`'‘]['’]cd")
+ (test-re "\\`c-c'" "\\\\[`'‘]c-c['’]")
+ (test-re "\\`<foo bar baz>'" "\\\\[`'‘]<foo bar baz>['’]")))
+
+(ert-deftest help-tests-substitute-key-bindings/help-key-binding-face ()
+ (let ((A (substitute-command-keys "\\[next-line]"))
+ (B (substitute-command-keys "\\`f'")))
+ (should (eq (get-text-property 0 'face A) 'help-key-binding))
+ (should (eq (get-text-property 0 'face B) 'help-key-binding))))
+
+(ert-deftest help-tests-substitute-key-bindings/help-key-binding-no-face ()
+ (let ((A (substitute-command-keys "\\[next-line]" t))
+ (B (substitute-command-keys "\\`f'" t)))
+ (should (eq (get-text-property 0 'face A) nil))
+ (should (eq (get-text-property 0 'face B) nil))
+ (should (equal A "C-n"))
+ (should (equal B "f"))))
+
+(defvar-keymap help-tests--test-keymap
+ :doc "Just some keymap for testing."
+ "C-g" #'abort-minibuffers
+ "TAB" #'minibuffer-complete
+ "C-j" #'minibuffer-complete-and-exit
+ "RET" #'minibuffer-complete-and-exit
+ "SPC" #'minibuffer-complete-word
+ "?" #'minibuffer-completion-help
+ "C-<tab>" #'file-cache-minibuffer-complete
+ "<XF86Back>" #'previous-history-element
+ "<XF86Forward>" #'next-history-element
+ "<backtab>" #'minibuffer-complete
+ "<down>" #'next-line-or-history-element
+ "<next>" #'next-history-element
+ "<prior>" #'switch-to-completions
+ "<up>" #'previous-line-or-history-element
+ "M-v" #'switch-to-completions
+ "M-<" #'minibuffer-beginning-of-buffer
+ "M-n" #'next-history-element
+ "M-p" #'previous-history-element
+ "M-r" #'previous-matching-history-element
+ "M-s" #'next-matching-history-element
+ "M-g M-c" #'switch-to-completions)
+(ert-deftest help-tests-substitute-command-keys/keymaps ()
+ (with-substitute-command-keys-test
+ (test-re "\\{help-tests--test-keymap}"
+ "
+Key Binding
+-+
C-g abort-minibuffers
TAB minibuffer-complete
C-j minibuffer-complete-and-exit
RET minibuffer-complete-and-exit
-ESC Prefix Command
SPC minibuffer-complete-word
-? minibuffer-completion-help
+\\? minibuffer-completion-help
C-<tab> file-cache-minibuffer-complete
<XF86Back> previous-history-element
<XF86Forward> next-history-element
+<backtab> minibuffer-complete
<down> next-line-or-history-element
<next> next-history-element
<prior> switch-to-completions
<up> previous-line-or-history-element
-M-g Prefix Command
-M-v switch-to-completions
-
-M-g ESC Prefix Command
-
M-< minibuffer-beginning-of-buffer
M-n next-history-element
M-p previous-history-element
M-r previous-matching-history-element
M-s next-matching-history-element
+M-v switch-to-completions
M-g M-c switch-to-completions
-
")))
(ert-deftest help-tests-substitute-command-keys/keymap-change ()
(with-substitute-command-keys-test
+ ;; Global binding should be found even if specifying a specific map
(test "\\<minibuffer-local-must-match-map>\\[abort-recursive-edit]" "C-]")
- (test "\\<emacs-lisp-mode-map>\\[eval-defun]" "C-M-x")))
+ (test "\\<emacs-lisp-mode-map>\\[eval-defun]" "C-M-x")
+ ;; Specific map overrides advertised-binding
+ (test "\\<undo-repeat-map>\\[undo]" "u")
+ (test "\\[undo]" "C-x u")))
-(defvar help-tests-remap-map
- (let ((map (make-keymap)))
- (define-key map (kbd "x") 'foo)
- (define-key map (kbd "y") 'bar)
- (define-key map [remap foo] 'bar)
- map))
+(defvar-keymap help-tests-remap-map
+ :full t
+ "x" 'foo
+ "y" 'bar
+ "<remap> <foo>" 'bar)
(ert-deftest help-tests-substitute-command-keys/remap ()
(should (equal (substitute-command-keys "\\<help-tests-remap-map>\\[foo]") "y"))
@@ -147,25 +204,45 @@ M-g M-c switch-to-completions
"\nUses keymap [`'‘]foobar-map['’], which is not currently defined.\n")))
(ert-deftest help-tests-substitute-command-keys/quotes ()
- (with-substitute-command-keys-test
+ (with-substitute-command-keys-test
+ (let ((text-quoting-style 'curve))
+ (test "quotes ‘like this’" "quotes ‘like this’")
+ (test "`x'" "‘x’")
+ (test "`" "‘")
+ (test "'" "’")
+ (test "\\`" "\\‘"))
+ (let ((text-quoting-style 'straight))
+ (test "quotes `like this'" "quotes 'like this'")
+ (test "`x'" "'x'")
+ (test "`" "'")
+ (test "'" "'")
+ (test "\\`" "\\'"))
+ (let ((text-quoting-style 'grave))
+ (test "quotes `like this'" "quotes `like this'")
+ (test "`x'" "`x'")
+ (test "`" "`")
+ (test "'" "'")
+ (test "\\`" "\\`"))))
+
+(ert-deftest help-tests-substitute-quotes ()
(let ((text-quoting-style 'curve))
- (test "quotes ‘like this’" "quotes ‘like this’")
- (test "`x'" "‘x’")
- (test "`" "‘")
- (test "'" "’")
- (test "\\`" "\\‘"))
+ (should (string= (substitute-quotes "quotes ‘like this’") "quotes ‘like this’"))
+ (should (string= (substitute-quotes "`x'") "‘x’"))
+ (should (string= (substitute-quotes "`") "‘"))
+ (should (string= (substitute-quotes "'") "’"))
+ (should (string= (substitute-quotes "\\`") "\\‘")))
(let ((text-quoting-style 'straight))
- (test "quotes `like this'" "quotes 'like this'")
- (test "`x'" "'x'")
- (test "`" "'")
- (test "'" "'")
- (test "\\`" "\\'"))
+ (should (string= (substitute-quotes "quotes `like this'") "quotes 'like this'"))
+ (should (string= (substitute-quotes "`x'") "'x'"))
+ (should (string= (substitute-quotes "`") "'"))
+ (should (string= (substitute-quotes "'") "'"))
+ (should (string= (substitute-quotes "\\`") "\\'")))
(let ((text-quoting-style 'grave))
- (test "quotes `like this'" "quotes `like this'")
- (test "`x'" "`x'")
- (test "`" "`")
- (test "'" "'")
- (test "\\`" "\\`"))))
+ (should (string= (substitute-quotes "quotes `like this'") "quotes `like this'"))
+ (should (string= (substitute-quotes "`x'") "`x'"))
+ (should (string= (substitute-quotes "`") "`"))
+ (should (string= (substitute-quotes "'") "'"))
+ (should (string= (substitute-quotes "\\`") "\\`"))))
(ert-deftest help-tests-substitute-command-keys/literals ()
(with-substitute-command-keys-test
@@ -180,7 +257,7 @@ M-g M-c switch-to-completions
(let ((text-quoting-style 'grave))
(test "\\=`x\\='" "`x'"))))
-(ert-deftest help-tests-substitute-command-keys/no-change ()
+(ert-deftest help-tests-substitute-command-keys/no-change-2 ()
(with-substitute-command-keys-test
(test "\\[foobar" "\\[foobar")
(test "\\=" "\\=")))
@@ -199,30 +276,28 @@ M-g M-c switch-to-completions
(goto-char (point-min))
(should (looking-at "Type RET on"))))
-(defvar help-tests-major-mode-map
- (let ((map (make-keymap)))
- (define-key map "x" 'foo-original)
- (define-key map "1" 'foo-range)
- (define-key map "2" 'foo-range)
- (define-key map "3" 'foo-range)
- (define-key map "4" 'foo-range)
- (define-key map (kbd "C-e") 'foo-something)
- (define-key map '[F1] 'foo-function-key1)
- (define-key map "(" 'short-range)
- (define-key map ")" 'short-range)
- (define-key map "a" 'foo-other-range)
- (define-key map "b" 'foo-other-range)
- (define-key map "c" 'foo-other-range)
- map))
+(defvar-keymap help-tests-major-mode-map
+ :full t
+ "x" 'foo-original
+ "1" 'foo-range
+ "2" 'foo-range
+ "3" 'foo-range
+ "4" 'foo-range
+ "C-e" 'foo-something
+ "<f1>" 'foo-function-key1
+ "(" 'short-range
+ ")" 'short-range
+ "a" 'foo-other-range
+ "b" 'foo-other-range
+ "c" 'foo-other-range)
(define-derived-mode help-tests-major-mode nil
"Major mode for testing shadowing.")
-(defvar help-tests-minor-mode-map
- (let ((map (make-keymap)))
- (define-key map "x" 'foo-shadow)
- (define-key map (kbd "C-e") 'foo-shadow)
- map))
+(defvar-keymap help-tests-minor-mode-map
+ :full t
+ "x" 'foo-shadow
+ "C-e" 'foo-shadow)
(define-minor-mode help-tests-minor-mode
"Minor mode for testing shadowing.")
@@ -249,19 +324,17 @@ M-g M-c switch-to-completions
(with-substitute-command-keys-test
(with-temp-buffer
(help-tests-major-mode)
- (test "\\{help-tests-major-mode-map}"
- "\
-key binding
---- -------
-
-( .. ) short-range
+ (test-re "\\{help-tests-major-mode-map}"
+ "
+Key Binding
+-+
1 .. 4 foo-range
a .. c foo-other-range
C-e foo-something
+( .. ) short-range
x foo-original
<F1> foo-function-key1
-
"))))
(ert-deftest help-tests-substitute-command-keys/shadow ()
@@ -269,21 +342,19 @@ x foo-original
(with-temp-buffer
(help-tests-major-mode)
(help-tests-minor-mode)
- (test "\\{help-tests-major-mode-map}"
- "\
-key binding
---- -------
-
-( .. ) short-range
+ (test-re "\\{help-tests-major-mode-map}"
+ "
+Key Binding
+-+
1 .. 4 foo-range
a .. c foo-other-range
C-e foo-something
(this binding is currently shadowed)
+( .. ) short-range
x foo-original
(this binding is currently shadowed)
<F1> foo-function-key1
-
"))))
(ert-deftest help-tests-substitute-command-keys/command-remap ()
@@ -292,15 +363,11 @@ x foo-original
(with-temp-buffer
(help-tests-major-mode)
(define-key help-tests-major-mode-map [remap foo] 'bar)
- (test "\\{help-tests-major-mode-map}"
- "\
-key binding
---- -------
-
-<remap> Prefix Command
-
+ (test-re "\\{help-tests-major-mode-map}"
+ "
+Key Binding
+-+
<remap> <foo> bar
-
")))))
(ert-deftest help-tests-describe-map-tree/no-menu-t ()
@@ -312,12 +379,11 @@ key binding
:enable mark-active
:help "Help text"))))))
(describe-map-tree map nil nil nil nil t nil nil nil)
- (should (equal (buffer-string) "key binding
---- -------
-
-C-a foo
-
-")))))
+ (should (string-match "
+Key Binding
+-+
+C-a foo\n"
+ (buffer-string))))))
(ert-deftest help-tests-describe-map-tree/no-menu-nil ()
(with-temp-buffer
@@ -328,15 +394,13 @@ C-a foo
:enable mark-active
:help "Help text"))))))
(describe-map-tree map nil nil nil nil nil nil nil nil)
- (should (equal (buffer-string) "key binding
---- -------
-
+ (should (string-match "
+Key Binding
+-+
C-a foo
-<menu-bar> Prefix Command
-
-<menu-bar> <foo> foo
-")))))
+<menu-bar> <foo> foo\n"
+ (buffer-string))))))
(ert-deftest help-tests-describe-map-tree/mention-shadow-t ()
(with-temp-buffer
@@ -345,14 +409,13 @@ C-a foo
(2 . bar))))
(shadow-maps '((keymap . ((1 . baz))))))
(describe-map-tree map t shadow-maps nil nil t nil nil t)
- (should (equal (buffer-string) "key binding
---- -------
-
+ (should (string-match "
+Key Binding
+-+
C-a foo
(this binding is currently shadowed)
-C-b bar
-
-")))))
+C-b bar\n"
+ (buffer-string))))))
(ert-deftest help-tests-describe-map-tree/mention-shadow-nil ()
(with-temp-buffer
@@ -361,12 +424,11 @@ C-b bar
(2 . bar))))
(shadow-maps '((keymap . ((1 . baz))))))
(describe-map-tree map t shadow-maps nil nil t nil nil nil)
- (should (equal (buffer-string) "key binding
---- -------
-
-C-b bar
-
-")))))
+ (should (string-match "
+Key Binding
+-+
+C-b bar\n"
+ (buffer-string))))))
(ert-deftest help-tests-describe-map-tree/partial-t ()
(with-temp-buffer
@@ -374,12 +436,11 @@ C-b bar
(map '(keymap . ((1 . foo)
(2 . undefined)))))
(describe-map-tree map t nil nil nil nil nil nil nil)
- (should (equal (buffer-string) "key binding
---- -------
-
-C-a foo
-
-")))))
+ (should (string-match "
+Key Binding
+-+
+C-a foo\n"
+ (buffer-string))))))
(ert-deftest help-tests-describe-map-tree/partial-nil ()
(with-temp-buffer
@@ -387,13 +448,12 @@ C-a foo
(map '(keymap . ((1 . foo)
(2 . undefined)))))
(describe-map-tree map nil nil nil nil nil nil nil nil)
- (should (equal (buffer-string) "key binding
---- -------
-
+ (should (string-match "
+Key Binding
+-+
C-a foo
-C-b undefined
-
-")))))
+C-b undefined\n"
+ (buffer-string))))))
(defvar help-tests--was-in-buffer nil)