diff options
author | Basil L. Contovounesios <contovob@tcd.ie> | 2019-09-27 00:04:33 +0100 |
---|---|---|
committer | Basil L. Contovounesios <contovob@tcd.ie> | 2019-10-03 23:05:14 +0100 |
commit | 0fc8177414801e428ca184e8a9ba8b79a291c15a (patch) | |
tree | 7ed7df57104eee1e0beaa6074efba73670adf3b0 /test/lisp/button-tests.el | |
parent | 660d509acd9da23d9795b5aaa12a5453e6c61bbd (diff) | |
download | emacs-0fc8177414801e428ca184e8a9ba8b79a291c15a.tar.gz emacs-0fc8177414801e428ca184e8a9ba8b79a291c15a.tar.bz2 emacs-0fc8177414801e428ca184e8a9ba8b79a291c15a.zip |
Further improve button.el support for help-echo
The last change to forward-button added support for help-echo values
that are functions. This patch fixes the arguments passed to such
functions and further adds support for help-echo values that are
forms (bug#37515).
* doc/lispref/display.texi (Button Properties): Fix description of
help-echo button property.
* lisp/button.el (button--help-echo): New function.
(forward-button): Use it.
(backward-button): Clarify help-echo reference in docstring.
* test/lisp/button-tests.el (button--help-echo-string)
(button--help-echo-form, button--help-echo-function): New tests.
Diffstat (limited to 'test/lisp/button-tests.el')
-rw-r--r-- | test/lisp/button-tests.el | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/test/lisp/button-tests.el b/test/lisp/button-tests.el index d54a992ab89..44a7ea6f6e5 100644 --- a/test/lisp/button-tests.el +++ b/test/lisp/button-tests.el @@ -37,4 +37,60 @@ (widget-create 'link "link widget") (should-not (button-at (1- (point)))))) +(ert-deftest button--help-echo-string () + "Test `button--help-echo' with strings." + (with-temp-buffer + ;; Text property buttons. + (let ((button (insert-text-button "text" 'help-echo "text help"))) + (should (equal (button--help-echo button) "text help"))) + ;; Overlay buttons. + (let ((button (insert-button "overlay" 'help-echo "overlay help"))) + (should (equal (button--help-echo button) "overlay help"))))) + +(ert-deftest button--help-echo-form () + "Test `button--help-echo' with forms." + (with-temp-buffer + ;; Test text property buttons with dynamic scoping. + (let* ((help (make-symbol "help")) + (form `(funcall (let ((,help "lexical form")) + (lambda () ,help)))) + (button (insert-text-button "text" 'help-echo form))) + (set help "dynamic form") + (should (equal (button--help-echo button) "dynamic form"))) + ;; Test overlay buttons with lexical scoping. + (setq lexical-binding t) + (let* ((help (make-symbol "help")) + (form `(funcall (let ((,help "lexical form")) + (lambda () ,help)))) + (button (insert-button "overlay" 'help-echo form))) + (set help "dynamic form") + (should (equal (button--help-echo button) "lexical form"))))) + +(ert-deftest button--help-echo-function () + "Test `button--help-echo' with functions." + (with-temp-buffer + ;; Text property buttons. + (let* ((owin (selected-window)) + (obuf (current-buffer)) + (opos (point)) + (help (lambda (win obj pos) + (should (eq win owin)) + (should (eq obj obuf)) + (should (= pos opos)) + "text function")) + (button (insert-text-button "text" 'help-echo help))) + (should (equal (button--help-echo button) "text function")) + ;; Overlay buttons. + (setq help (lambda (win obj pos) + (should (eq win owin)) + (should (overlayp obj)) + (should (eq obj button)) + (should (eq (overlay-buffer obj) obuf)) + (should (= (overlay-start obj) opos)) + (should (= pos opos)) + "overlay function")) + (setq opos (point)) + (setq button (insert-button "overlay" 'help-echo help)) + (should (equal (button--help-echo button) "overlay function"))))) + ;;; button-tests.el ends here |