mouse-tests.el 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. ;;; mouse-tests.el --- unit tests for mouse.el -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2016-2017 Free Software Foundation, Inc.
  3. ;; Author: Philipp Stephani <phst@google.com>
  4. ;; This file is part of GNU Emacs.
  5. ;; GNU Emacs is free software: you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; GNU Emacs is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;; Unit tests for lisp/mouse.el.
  17. ;;; Code:
  18. (ert-deftest bug23288-use-return-value ()
  19. "If ‘mouse-on-link-p’ returns a string, its first character is
  20. used."
  21. (cl-letf ((last-input-event '(down-mouse-1 nil 1))
  22. (unread-command-events '((mouse-1 nil 1)))
  23. (mouse-1-click-follows-link t)
  24. (mouse-1-click-in-non-selected-windows t)
  25. ((symbol-function 'mouse-on-link-p) (lambda (_pos) "abc")))
  26. (should-not (mouse--down-1-maybe-follows-link))
  27. (should (equal unread-command-events '(?a)))))
  28. (ert-deftest bug23288-translate-to-mouse-2 ()
  29. "If ‘mouse-on-link-p’ doesn’t return a string or vector,
  30. translate ‘mouse-1’ events into ‘mouse-2’ events."
  31. (cl-letf ((last-input-event '(down-mouse-1 nil 1))
  32. (unread-command-events '((mouse-1 nil 1)))
  33. (mouse-1-click-follows-link t)
  34. (mouse-1-click-in-non-selected-windows t)
  35. ((symbol-function 'mouse-on-link-p) (lambda (_pos) t)))
  36. (should-not (mouse--down-1-maybe-follows-link))
  37. (should (equal unread-command-events '((mouse-2 nil 1))))))
  38. ;;; mouse-tests.el ends here