aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorPhilipp Stephani2016-03-25 13:17:38 +0300
committerEli Zaretskii2016-03-25 13:17:38 +0300
commit90fb9b38dd4a386a71cdf7c3bf6b42292db43c42 (patch)
tree4ebbe0a89215012e8519b5ec580a014d293ac920 /test
parentf14d463661f46f614125f88b56d73106fab9ece6 (diff)
downloademacs-90fb9b38dd4a386a71cdf7c3bf6b42292db43c42.tar.gz
emacs-90fb9b38dd4a386a71cdf7c3bf6b42292db43c42.zip
Add customization option for using UTF-8 coordinates in xt-mouse
* lisp/xt-mouse.el (xterm-mouse-utf-8): New customization option. (xterm-mouse--read-coordinate): New function to replace `xterm-mouse--read-utf8-char'; uses UTF-8 only if enabled. (xterm-mouse--read-number-from-terminal): Adapt to new name. (xterm-mouse-tracking-enable-sequence) (xterm-mouse-tracking-disable-sequence): Replace constants with functions, mark constants as obsolete. (xterm-mouse--tracking-sequence): New helper function. (turn-on-xterm-mouse-tracking-on-terminal): Use new functions; enable UTF-8 only if customization option says so; store UTF-8 flag in terminal parameter. (Bug#23009) * test/automated/xt-mouse-tests.el: Add tests for xt-mouse.el.
Diffstat (limited to 'test')
-rw-r--r--test/automated/xt-mouse-tests.el110
1 files changed, 110 insertions, 0 deletions
diff --git a/test/automated/xt-mouse-tests.el b/test/automated/xt-mouse-tests.el
new file mode 100644
index 00000000000..c7e835c0311
--- /dev/null
+++ b/test/automated/xt-mouse-tests.el
@@ -0,0 +1,110 @@
1;;; xt-mouse-tests.el --- Test suite for xt-mouse. -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2016 Free Software Foundation, Inc.
4
5;; Author: Philipp Stephani <phst@google.com>
6
7;; This file is part of GNU Emacs.
8
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.
13
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.
18
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/>.
21
22;;; Commentary:
23
24;;; Code:
25
26(require 'xt-mouse)
27
28(defmacro with-xterm-mouse-mode (&rest body)
29 "Run BODY with `xterm-mouse-mode' temporarily enabled."
30 (declare (indent 0))
31 ;; Make the frame huge so that the test input events below don't hit
32 ;; the menu bar.
33 `(cl-letf (((frame-width nil) 2000)
34 ((frame-height nil) 2000)
35 ;; Reset XTerm parameters so that the tests don't get
36 ;; confused.
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))
41 (if xterm-mouse-mode
42 (progn ,@body)
43 (unwind-protect
44 (progn
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")))
50 (xterm-mouse-mode))
51 ,@body)
52 (xterm-mouse-mode 0)))))
53
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"
64 "\e[M'\xD9\x81" nil))
65 (key (read-key)))
66 (should (consp key))
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))))))))
72
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))
87 (key (read-key)))
88 (should (consp key))
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)))))))))
94
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))
102 (key (read-key)))
103 (should (consp key))
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))))))))
109
110;;; xt-mouse-tests.el ends here