summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorPhilipp Stephani <phst@google.com>2016-03-25 13:17:38 +0300
committerEli Zaretskii <eliz@gnu.org>2016-03-25 13:17:38 +0300
commit90fb9b38dd4a386a71cdf7c3bf6b42292db43c42 (patch)
tree4ebbe0a89215012e8519b5ec580a014d293ac920 /test
parentf14d463661f46f614125f88b56d73106fab9ece6 (diff)
downloademacs-90fb9b38dd4a386a71cdf7c3bf6b42292db43c42.tar.gz
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 @@
+;;; xt-mouse-tests.el --- Test suite for xt-mouse. -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2016 Free Software Foundation, Inc.
+
+;; Author: Philipp Stephani <phst@google.com>
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;; Code:
+
+(require 'xt-mouse)
+
+(defmacro with-xterm-mouse-mode (&rest body)
+ "Run BODY with `xterm-mouse-mode' temporarily enabled."
+ (declare (indent 0))
+ ;; Make the frame huge so that the test input events below don't hit
+ ;; the menu bar.
+ `(cl-letf (((frame-width nil) 2000)
+ ((frame-height nil) 2000)
+ ;; Reset XTerm parameters so that the tests don't get
+ ;; confused.
+ ((terminal-parameter nil 'xterm-mouse-x) nil)
+ ((terminal-parameter nil 'xterm-mouse-y) nil)
+ ((terminal-parameter nil 'xterm-mouse-last-down) nil)
+ ((terminal-parameter nil 'xterm-mouse-last-click) nil))
+ (if xterm-mouse-mode
+ (progn ,@body)
+ (unwind-protect
+ (progn
+ ;; `xterm-mouse-mode' doesn't work in the initial
+ ;; terminal. Since we can't create a second terminal in
+ ;; batch mode, fake it temporarily.
+ (cl-letf (((symbol-function 'terminal-name)
+ (lambda (&optional _terminal) "fake-terminal")))
+ (xterm-mouse-mode))
+ ,@body)
+ (xterm-mouse-mode 0)))))
+
+(ert-deftest xt-mouse-tracking-basic ()
+ (should (equal (xterm-mouse-tracking-enable-sequence)
+ "\e[?1000h\e[?1002h\e[?1006h"))
+ (should (equal (xterm-mouse-tracking-disable-sequence)
+ "\e[?1006l\e[?1002l\e[?1000l"))
+ (with-xterm-mouse-mode
+ (should xterm-mouse-mode)
+ (should (terminal-parameter nil 'xterm-mouse-mode))
+ (should-not (terminal-parameter nil 'xterm-mouse-utf-8))
+ (let* ((unread-command-events (append "\e[M%\xD9\x81"
+ "\e[M'\xD9\x81" nil))
+ (key (read-key)))
+ (should (consp key))
+ (cl-destructuring-bind (event-type position . rest) key
+ (should (equal event-type 'S-mouse-2))
+ (should (consp position))
+ (cl-destructuring-bind (_ _ xy . rest) position
+ (should (equal xy '(184 . 95))))))))
+
+(ert-deftest xt-mouse-tracking-utf-8 ()
+ (let ((xterm-mouse-utf-8 t))
+ (should (equal (xterm-mouse-tracking-enable-sequence)
+ "\e[?1000h\e[?1002h\e[?1005h\e[?1006h"))
+ (should (equal (xterm-mouse-tracking-disable-sequence)
+ "\e[?1006l\e[?1005l\e[?1002l\e[?1000l"))
+ (with-xterm-mouse-mode
+ (should xterm-mouse-mode)
+ (should (terminal-parameter nil 'xterm-mouse-mode))
+ (should (terminal-parameter nil 'xterm-mouse-utf-8))
+ ;; The keyboard driver doesn't decode bytes in
+ ;; `unread-command-events'.
+ (let* ((unread-command-events (append "\e[M%\u0640\u0131"
+ "\e[M'\u0640\u0131" nil))
+ (key (read-key)))
+ (should (consp key))
+ (cl-destructuring-bind (event-type position . rest) key
+ (should (equal event-type 'S-mouse-2))
+ (should (consp position))
+ (cl-destructuring-bind (_ _ xy . rest) position
+ (should (equal xy '(1567 . 271)))))))))
+
+(ert-deftest xt-mouse-tracking-sgr ()
+ (with-xterm-mouse-mode
+ (should xterm-mouse-mode)
+ (should (terminal-parameter nil 'xterm-mouse-mode))
+ (should-not (terminal-parameter nil 'xterm-mouse-utf-8))
+ (let* ((unread-command-events (append "\e[<5;1569;273;M"
+ "\e[<5;1569;273;m" nil))
+ (key (read-key)))
+ (should (consp key))
+ (cl-destructuring-bind (event-type position . rest) key
+ (should (equal event-type 'S-mouse-2))
+ (should (consp position))
+ (cl-destructuring-bind (_ _ xy . rest) position
+ (should (equal xy '(1568 . 271))))))))
+
+;;; xt-mouse-tests.el ends here