1 ;;; xt-mouse-tests.el --- Test suite for xt-mouse. -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2016-2018 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 <https://www.gnu.org/licenses/>.
28 (defmacro with-xterm-mouse-mode
(&rest body
)
29 "Run BODY with `xterm-mouse-mode' temporarily enabled."
31 ;; Make the frame huge so that the test input events below don't hit
33 `(cl-letf (((frame-width nil
) 2000)
34 ((frame-height nil
) 2000)
35 ;; Reset XTerm parameters so that the tests don't get
37 ((terminal-parameter nil
'xterm-mouse-x
) nil
)
38 ((terminal-parameter nil
'xterm-mouse-y
) nil
)
39 ((terminal-parameter nil
'xterm-mouse-last-down
) nil
)
40 ((terminal-parameter nil
'xterm-mouse-last-click
) nil
))
45 ;; `xterm-mouse-mode' doesn't work in the initial
46 ;; terminal. Since we can't create a second terminal in
47 ;; batch mode, fake it temporarily.
48 (cl-letf (((symbol-function 'terminal-name
)
49 (lambda (&optional _terminal
) "fake-terminal")))
52 (xterm-mouse-mode 0)))))
54 (ert-deftest xt-mouse-tracking-basic
()
55 (should (equal (xterm-mouse-tracking-enable-sequence)
56 "\e[?1000h\e[?1002h\e[?1006h"))
57 (should (equal (xterm-mouse-tracking-disable-sequence)
58 "\e[?1006l\e[?1002l\e[?1000l"))
59 (with-xterm-mouse-mode
60 (should xterm-mouse-mode
)
61 (should (terminal-parameter nil
'xterm-mouse-mode
))
62 (should-not (terminal-parameter nil
'xterm-mouse-utf-8
))
63 (let* ((unread-command-events (append "\e[M%\xD9\x81"
67 (cl-destructuring-bind (event-type position . rest
) key
68 (should (equal event-type
'S-mouse-2
))
69 (should (consp position
))
70 (cl-destructuring-bind (_ _ xy . rest
) position
71 (should (equal xy
'(184 .
95))))))))
73 (ert-deftest xt-mouse-tracking-utf-8
()
74 (let ((xterm-mouse-utf-8 t
))
75 (should (equal (xterm-mouse-tracking-enable-sequence)
76 "\e[?1000h\e[?1002h\e[?1005h\e[?1006h"))
77 (should (equal (xterm-mouse-tracking-disable-sequence)
78 "\e[?1006l\e[?1005l\e[?1002l\e[?1000l"))
79 (with-xterm-mouse-mode
80 (should xterm-mouse-mode
)
81 (should (terminal-parameter nil
'xterm-mouse-mode
))
82 (should (terminal-parameter nil
'xterm-mouse-utf-8
))
83 ;; The keyboard driver doesn't decode bytes in
84 ;; `unread-command-events'.
85 (let* ((unread-command-events (append "\e[M%\u0640\u0131"
86 "\e[M'\u0640\u0131" nil
))
89 (cl-destructuring-bind (event-type position . rest
) key
90 (should (equal event-type
'S-mouse-2
))
91 (should (consp position
))
92 (cl-destructuring-bind (_ _ xy . rest
) position
93 (should (equal xy
'(1567 .
271)))))))))
95 (ert-deftest xt-mouse-tracking-sgr
()
96 (with-xterm-mouse-mode
97 (should xterm-mouse-mode
)
98 (should (terminal-parameter nil
'xterm-mouse-mode
))
99 (should-not (terminal-parameter nil
'xterm-mouse-utf-8
))
100 (let* ((unread-command-events (append "\e[<5;1569;273;M"
101 "\e[<5;1569;273;m" nil
))
104 (cl-destructuring-bind (event-type position . rest
) key
105 (should (equal event-type
'S-mouse-2
))
106 (should (consp position
))
107 (cl-destructuring-bind (_ _ xy . rest
) position
108 (should (equal xy
'(1568 .
271))))))))
110 ;;; xt-mouse-tests.el ends here