Sync NEWS with the documentation
[emacs.git] / test / lisp / mouse-tests.el
bloba8eca28365e7ad9a8861c80cbd772feae6eaea21
1 ;;; mouse-tests.el --- unit tests for mouse.el -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2016-2017 Free Software Foundation, Inc.
5 ;; Author: Philipp Stephani <phst@google.com>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22 ;;; Commentary:
24 ;; Unit tests for lisp/mouse.el.
26 ;;; Code:
28 (ert-deftest bug23288-use-return-value ()
29 "If ‘mouse-on-link-p’ returns a string, its first character is
30 used."
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) "abc")))
36 (should-not (mouse--down-1-maybe-follows-link))
37 (should (equal unread-command-events '(?a)))))
39 (ert-deftest bug23288-translate-to-mouse-2 ()
40 "If ‘mouse-on-link-p’ doesn’t return a string or vector,
41 translate ‘mouse-1’ events into ‘mouse-2’ events."
42 (cl-letf ((last-input-event '(down-mouse-1 nil 1))
43 (unread-command-events '((mouse-1 nil 1)))
44 (mouse-1-click-follows-link t)
45 (mouse-1-click-in-non-selected-windows t)
46 ((symbol-function 'mouse-on-link-p) (lambda (_pos) t)))
47 (should-not (mouse--down-1-maybe-follows-link))
48 (should (equal unread-command-events '((mouse-2 nil 1))))))
50 (ert-deftest bug26816-mouse-frame-movement ()
51 "Mouse moves relative to frame."
52 (skip-unless (display-graphic-p))
53 (let ((frame (selected-frame)))
54 (set-mouse-position frame 0 0)
55 (should (equal (mouse-position)
56 (cons frame (cons 0 0))))))
59 ;;; mouse-tests.el ends here