emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] 192/287: Add ergoemacs-test-layout


From: Matthew Fidler
Subject: [elpa] 192/287: Add ergoemacs-test-layout
Date: Wed, 02 Jul 2014 14:45:54 +0000

mlf176f2 pushed a commit to branch externals/ergoemacs-mode
in repository elpa.

commit 926426d7e23e96507ff559971392dd1d1bc43ba8
Author: Matthew L. Fidler <address@hidden>
Date:   Mon Jun 23 08:02:29 2014 -0500

    Add ergoemacs-test-layout
---
 ergoemacs-macros.el |   27 ++-
 ergoemacs-test.el   |  799 ++++++++++++++++++++++-----------------------------
 2 files changed, 363 insertions(+), 463 deletions(-)

diff --git a/ergoemacs-macros.el b/ergoemacs-macros.el
index a8f1225..2a3fd2c 100644
--- a/ergoemacs-macros.el
+++ b/ergoemacs-macros.el
@@ -213,7 +213,32 @@ Uses `ergoemacs-theme-component--parse-keys-and-body' and
                  ',(nth 0 kb)
                  '(lambda () ,@(nth 1 kb)))) ergoemacs-theme-comp-hash)))
 
-;;;###autoload
+(defmacro ergoemacs-test-layout (&rest keys-and-body)
+  (let ((kb (make-symbol "body-and-plist"))
+        (plist (make-symbol "plist"))
+        (body (make-symbol "body")))
+    (setq kb (ergoemacs-theme-component--parse keys-and-body t)
+          plist (nth 0 kb)
+          body (nth 1 kb))
+    `(let ((old-ergoemacs-theme ergoemacs-theme)
+           (macro
+            ,(if (plist-get plist ':macro)
+                 `(edmacro-parse-keys ,(plist-get plist ':macro) t)))
+           (old-ergoemacs-keyboard-layout ergoemacs-keyboard-layout))
+       (ergoemacs-mode -1)
+       (setq ergoemacs-theme ,(plist-get plist ':theme))
+       (setq ergoemacs-keyboard-layout ,(or (plist-get plist ':layout) "us"))
+       (ergoemacs-mode 1)
+       ,(if (plist-get plist :cua)
+            `(cua-mode 1))
+       (unwind-protect
+           (progn
+             ,@body)
+         (ergoemacs-mode -1)
+         (setq ergoemacs-theme old-ergoemacs-theme)
+         (setq ergoemacs-keyboard-layout old-ergoemacs-keyboard-layout)
+         (ergoemacs-mode 1)))))
+
 (fset 'ergoemacs-theme-component--parse-keys-and-body
       #'(lambda (keys-and-body &optional parse-function  skip-first)
           "Split KEYS-AND-BODY into keyword-and-value pairs and the remaining 
body.
diff --git a/ergoemacs-test.el b/ergoemacs-test.el
index c6fc6f7..747a347 100644
--- a/ergoemacs-test.el
+++ b/ergoemacs-test.el
@@ -1,6 +1,6 @@
 ;;; ergoemacs-test.el --- tests for ErgoEmacs issues
 
-;; Copyright (C) 2013, 2014 Free Software Foundation, Inc.
+;; Copyright © 2013, 2014 Free Software Foundation, Inc.
 
 ;; Maintainer: Matthew L. Fidler
 ;; Keywords: convenience
@@ -28,6 +28,18 @@
 
 ;;; Code:
 
+(eval-when-compile 
+  (require 'cl)
+  (require 'ergoemacs-macros 
+           (expand-file-name "ergoemacs-macros" 
+                             (file-name-directory (or
+                                                   load-file-name
+                                                   (buffer-file-name)
+                                                   default-directory)))))
+
+(declare-function ergoemacs-set "ergoemacs-theme-engine.el")
+(declare-function ergoemacs-define-key "ergoemacs-theme-engine.el")
+
 (require 'ert)
 (require 'elp)
 ;;; Not sure why `cl-gensym' is called, probably from `ert'/`elp'?
@@ -61,104 +73,70 @@ sunt in culpa qui officia deserunt mollit anim id est 
laborum.")
 (declare-function ergoemacs-mode "ergoemacs-mode.el")
 (ert-deftest ergoemacs-test-google-code-145 ()
   "Backspace doesn't work in `isearch-mode'."
-  (let ((old-ergoemacs-theme ergoemacs-theme)
-        (old-ergoemacs-keyboard-layout ergoemacs-keyboard-layout)
-        (macro (edmacro-parse-keys "C-f ars C-f <backspace> M-n" t))
-        (ret t))
-    (ergoemacs-mode -1)
-    (setq ergoemacs-theme nil)
-    (setq ergoemacs-keyboard-layout "colemak")
-    (ergoemacs-mode 1)
-    (cua-mode 1)
-    (save-excursion
-      (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-      (insert "aars1\nars2\nars3\nars4")
-      (goto-char (point-min))
-      (execute-kbd-macro macro)
-      (when (looking-at ".*")
-        (unless (string= "s1" (match-string 0))
-          (setq ret nil)))
-      (kill-buffer (current-buffer)))
-    (ergoemacs-mode -1)
-    (setq ergoemacs-theme old-ergoemacs-theme)
-    (setq ergoemacs-keyboard-layout old-ergoemacs-keyboard-layout)
-    (ergoemacs-mode 1)
+  (let ((ret t))
+    (ergoemacs-test-layout
+     :layout "colemak"
+     :macro "C-f ars C-f <backspace> M-n"
+     (save-excursion
+       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
+       (insert "aars1\nars2\nars3\nars4")
+       (goto-char (point-min))
+       (execute-kbd-macro macro)
+       (when (looking-at ".*")
+         (unless (string= "s1" (match-string 0))
+           (setq ret nil)))
+       (kill-buffer (current-buffer))))
     (should (equal ret t))))
 
 (ert-deftest ergoemacs-test-google-code-119 ()
   "C-f doesn't work in isearch-mode."
-  (let ((old-ergoemacs-theme ergoemacs-theme)
-        (old-ergoemacs-keyboard-layout ergoemacs-keyboard-layout)
-        (macro (edmacro-parse-keys "C-f ars C-f C-f" t))
-        (ret t))
-    (ergoemacs-mode -1)
-    (setq ergoemacs-theme nil)
-    (setq ergoemacs-keyboard-layout "colemak")
-    (ergoemacs-mode 1)
-    (cua-mode 1)
-    (save-excursion
-      (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-      (insert "aars1\nars2\nars3\nars4")
-      (goto-char (point-min))
-      (execute-kbd-macro macro)
-      (when (looking-at ".*")
-        (unless (string= "3" (match-string 0))
-          (setq ret nil)))
-      (kill-buffer (current-buffer)))
-    (ergoemacs-mode -1)
-    (setq ergoemacs-theme old-ergoemacs-theme)
-    (setq ergoemacs-keyboard-layout old-ergoemacs-keyboard-layout)
-    (ergoemacs-mode 1)
+  (let ((ret t))
+    (ergoemacs-test-layout
+     :layout "colemak"
+     :cua t
+     :macro "C-f ars C-f C-f"
+     (save-excursion
+       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
+       (insert "aars1\nars2\nars3\nars4")
+       (goto-char (point-min))
+       (execute-kbd-macro macro)
+       (when (looking-at ".*")
+         (unless (string= "3" (match-string 0))
+           (setq ret nil)))
+       (kill-buffer (current-buffer))))
     (should (equal ret t))))
 
 (ert-deftest ergoemacs-test-shifted-move-no-mark ()
   "Tests another shifted selection bug."
-  (let ((old-ergoemacs-theme ergoemacs-theme)
-        (old-ergoemacs-keyboard-layout ergoemacs-keyboard-layout)
-        (macro (edmacro-parse-keys "M-H" t))
-        (ret t))
-    (ergoemacs-mode -1)
-    (setq ergoemacs-theme nil)
-    (setq ergoemacs-keyboard-layout "colemak")
-    (ergoemacs-mode 1)
-    (cua-mode 1)
-    (save-excursion
-      (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-      (delete-region (point-min) (point-max))
-      (goto-char (point-min))
-      (insert ";;")
-      (execute-kbd-macro macro)
-      (setq ret (not mark-active)) ;;  Shouldn't be selected
-      (kill-buffer (current-buffer)))
-    (ergoemacs-mode -1)
-    (setq ergoemacs-theme old-ergoemacs-theme)
-    (setq ergoemacs-keyboard-layout old-ergoemacs-keyboard-layout)
-    (ergoemacs-mode 1)
+  (let ((ret t))
+    (ergoemacs-test-layout
+     :macro "M-H"
+     :layout "colemak"
+     (save-excursion
+       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
+       (delete-region (point-min) (point-max))
+       (goto-char (point-min))
+       (insert ";;")
+       (execute-kbd-macro macro)
+       (setq ret (not mark-active)) ;;  Shouldn't be selected
+       (kill-buffer (current-buffer))))
     (should (equal ret t))))
 
 (ert-deftest ergoemacs-test-shifted-move-keep-mark ()
   "Test the shifted selection bug."
-  (let ((old-ergoemacs-theme ergoemacs-theme)
-        (old-ergoemacs-keyboard-layout ergoemacs-keyboard-layout)
-        (macro (edmacro-parse-keys "M-SPC M-h M-I" t))
-        (ret))
-    (ergoemacs-mode -1)
-    (setq ergoemacs-theme nil)
-    (setq ergoemacs-keyboard-layout "colemak")
-    (ergoemacs-mode 1)
-    (cua-mode 1)
-    (save-excursion
-      (switch-to-buffer (get-buffer-create "*ergoemacs-test-shifted-move*"))
-      (delete-region (point-min) (point-max))
-      (insert ";;;;")
-      (goto-char (point-min))
-      (execute-kbd-macro macro)
-      (setq ret mark-active) ;; Should be selected.
-      (kill-buffer (current-buffer)))
-    (ergoemacs-mode -1)
-    (setq ergoemacs-theme old-ergoemacs-theme)
-    (setq ergoemacs-keyboard-layout old-ergoemacs-keyboard-layout)
-    (ergoemacs-mode 1)
+  (let (ret)
+    (ergoemacs-test-layout
+     :macro "M-SPC M-h M-I"
+     :layout "colemak"
+     :cua t
+     (save-excursion
+       (switch-to-buffer (get-buffer-create "*ergoemacs-test-shifted-move*"))
+       (delete-region (point-min) (point-max))
+       (insert ";;;;")
+       (goto-char (point-min))
+       (execute-kbd-macro macro)
+       (setq ret mark-active) ;; Should be selected.
+       (kill-buffer (current-buffer))))
     (should (equal ret t))))
 
 (defvar ergoemacs-dir)
@@ -237,17 +215,23 @@ sunt in culpa qui officia deserunt mollit anim id est 
laborum.")
 
 (ert-deftest ergoemacs-test-global-key-set-apps-m-c-before ()
   "Test setting <apps> m c before loading."
-  (should (equal (ergoemacs-test-global-key-set-before nil
-                                                       (if (eq system-type 
'windows-nt)
-                                                           "<apps> m c"
-                                                         "<menu> m c") nil nil 
"<menu>") t)))
+  (should
+   (equal
+    (ergoemacs-test-global-key-set-before
+     nil
+     (if (eq system-type 'windows-nt)
+         "<apps> m c"
+       "<menu> m c") nil nil "<menu>") t)))
 
 (ert-deftest ergoemacs-test-global-key-set-apps-m-c-before-2 ()
   "Test setting <apps> m c before loading (define-key)."
-  (should (equal (ergoemacs-test-global-key-set-before nil
-                                                       (if (eq system-type 
'windows-nt)
-                                                           "<apps> m c"
-                                                         "<menu> m c") 
'define-key nil "<menu>") t)))
+  (should
+   (equal
+    (ergoemacs-test-global-key-set-before
+     nil
+     (if (eq system-type 'windows-nt)
+         "<apps> m c"
+       "<menu> m c") 'define-key nil "<menu>") t)))
 
 (ert-deftest ergoemacs-test-global-key-set-m-semi-before ()
   "Test setting M-; before loading."
@@ -280,51 +264,71 @@ sunt in culpa qui officia deserunt mollit anim id est 
laborum.")
 
 (ert-deftest ergoemacs-test-global-key-set-apps-m-before ()
   "Test setting <apps> m before loading."
-  (should (equal (ergoemacs-test-global-key-set-before nil
-                                                       (if (eq system-type 
'windows-nt)
-                                                           "<apps> m"
-                                                         "<menu> m") nil nil 
"<menu>") t)))
+  (should
+   (equal
+    (ergoemacs-test-global-key-set-before
+     nil
+     (if (eq system-type 'windows-nt)
+         "<apps> m"
+       "<menu> m") nil nil "<menu>") t)))
 
 (ert-deftest ergoemacs-test-global-key-set-apps-m-before-2 ()
   "Test setting <apps> m before loading (define-key)."
-  (should (equal (ergoemacs-test-global-key-set-before nil
-                                                       (if (eq system-type 
'windows-nt)
-                                                           "<apps> m"
-                                                         "<menu> m") 
'define-key nil "<menu>") t)))
+  (should
+   (equal
+    (ergoemacs-test-global-key-set-before
+     nil
+     (if (eq system-type 'windows-nt)
+         "<apps> m"
+       "<menu> m") 'define-key nil "<menu>") t)))
 
 (ert-deftest ergoemacs-test-global-key-set-apps-m-after ()
   "Test setting <apps> m after loading"
-  (should (equal (ergoemacs-test-global-key-set-before 'after
-                                                       (if (eq system-type 
'windows-nt)
-                                                           "<apps> m"
-                                                         "<menu> m") nil nil 
"<menu>") t)))
+  (should
+   (equal
+    (ergoemacs-test-global-key-set-before
+     'after
+     (if (eq system-type 'windows-nt)
+         "<apps> m"
+       "<menu> m") nil nil "<menu>") t)))
 
 
 (ert-deftest ergoemacs-test-global-key-set-apps-m-after-2 ()
   "Test setting <apps> m after loading (define-key)"
-  (should (equal (ergoemacs-test-global-key-set-before 'after
-                                                       (if (eq system-type 
'windows-nt)
-                                                           "<apps> m"
-                                                         "<menu> m") 
'define-key nil "<menu>") t)))
+  (should
+   (equal
+    (ergoemacs-test-global-key-set-before
+     'after
+     (if (eq system-type 'windows-nt)
+         "<apps> m"
+       "<menu> m") 'define-key nil "<menu>") t)))
 
 (ert-deftest ergoemacs-test-global-key-set-apps-m-c-after ()
   "Test setting <apps> m c after loading."
-  (should (equal (ergoemacs-test-global-key-set-before 'after
-                                                       (if (eq system-type 
'windows-nt)
-                                                           "<apps> m c"
-                                                         "<menu> m c") nil nil 
"<menu>") t)))
+  (should
+   (equal
+    (ergoemacs-test-global-key-set-before
+     'after
+     (if (eq system-type 'windows-nt)
+         "<apps> m c"
+       "<menu> m c") nil nil "<menu>") t)))
 
 (ert-deftest ergoemacs-test-global-key-set-apps-m-c-after-2 ()
   "Test setting <apps> m c after loading (define-key)."
-  (should (equal (ergoemacs-test-global-key-set-before 'after
-                                                       (if (eq system-type 
'windows-nt)
-                                                           "<apps> m c"
-                                                         "<menu> m c") 
'define-key nil "<menu>") t)))
+  (should
+   (equal
+    (ergoemacs-test-global-key-set-before
+     'after
+     (if (eq system-type 'windows-nt)
+         "<apps> m c"
+       "<menu> m c") 'define-key nil "<menu>") t)))
 
 (ert-deftest ergoemast-test-global-key-set-after-c-e ()
   "Test C-e after"
-  (should (equal (ergoemacs-test-global-key-set-before
-                  'after "C-e" 'ergoemacs-key))))
+  (should
+   (equal
+    (ergoemacs-test-global-key-set-before
+     'after "C-e" 'ergoemacs-key))))
 
 (declare-function ergoemacs-pretty-key-rep "ergoemacs-tranlate.el")
 (ert-deftest ergoemacs-test-ctl-c-ctl-c ()
@@ -402,35 +406,21 @@ Hyper Key mapping no longer works."
 
 (ert-deftest ergoemacs-test-issue-98 ()
   "Test full fast-movement-keys"
-  (let ((old-ergoemacs-theme ergoemacs-theme)
-        (old-ergoemacs-keyboard-layout ergoemacs-keyboard-layout)
-        (macro (edmacro-parse-keys "C-f ars C-f <backspace> M-n" t))
-        (ergoemacs-repeat-movement-commands 'all)
-        (ret t))
-    (ergoemacs-mode -1)
-    (setq ergoemacs-theme nil)
-    (setq ergoemacs-keyboard-layout "colemak")
-    (ergoemacs-mode 1)
-    (cua-mode 1)
-    (save-excursion
-      (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-      (insert ergoemacs-test-lorem-ipsum)
-      (goto-char (point-min))
-      (execute-kbd-macro (edmacro-parse-keys "M-e"))
-      (unless (looking-at "do eiusmod")
-        (setq ret nil))
-      (execute-kbd-macro (edmacro-parse-keys "e"))
-      (unless (looking-at "enim ad")
-        (setq ret nil))
-      (execute-kbd-macro (edmacro-parse-keys "u"))
-      (unless (looking-at "do eiusmod")
-        (setq ret nil))
-      (kill-buffer (current-buffer)))
-    (ergoemacs-mode -1)
-    (setq ergoemacs-theme old-ergoemacs-theme)
-    (setq ergoemacs-keyboard-layout old-ergoemacs-keyboard-layout)
-    (ergoemacs-mode 1)
-    (should ret)))
+  (let ((ergoemacs-repeat-movement-commands 'all))
+    (ergoemacs-test-layout
+     :layout "colemak"
+     :cua t
+     (save-excursion
+       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
+       (insert ergoemacs-test-lorem-ipsum)
+       (goto-char (point-min))
+       (execute-kbd-macro (edmacro-parse-keys "M-e"))
+       (should (looking-at "do eiusmod"))
+       (execute-kbd-macro (edmacro-parse-keys "e"))
+       (should (looking-at "enim ad"))
+       (execute-kbd-macro (edmacro-parse-keys "u"))
+       (should (looking-at "do eiusmod"))
+       (kill-buffer (current-buffer))))))
 
 (declare-function ergoemacs-unchorded-alt-modal "ergoemacs-translate.el"
                   nil t)
@@ -448,23 +438,15 @@ Test next and prior translation."
 
 (ert-deftest ergoemacs-test-issue-114 ()
   "Attempts to test Issue #114."
-  (let ((old-ergoemacs-theme ergoemacs-theme)
-        (old-ergoemacs-keyboard-layout ergoemacs-keyboard-layout)
-        (macro (edmacro-parse-keys "C-f ars C-f <backspace> M-n" t))
-        (ret t))
-    (ergoemacs-mode -1)
-    (setq ergoemacs-theme nil)
-    (setq ergoemacs-keyboard-layout "colemak")
-    (ergoemacs-mode 1)
-    (setq ret (lookup-key isearch-mode-map
-                          (read-kbd-macro
-                           (format "<%s> s"
-                                   (if (eq system-type 'windows-nt)
-                                       "apps" "menu")))))
-    (ergoemacs-mode -1)
-    (setq ergoemacs-theme old-ergoemacs-theme)
-    (setq ergoemacs-keyboard-layout old-ergoemacs-keyboard-layout)
-    (ergoemacs-mode 1)
+  (let ((ret t))
+    (ergoemacs-test-layout
+     :macro "C-f ars C-f <backspace> M-n"
+     :layout "colemak"
+     (setq ret (lookup-key isearch-mode-map
+                           (read-kbd-macro
+                            (format "<%s> s"
+                                    (if (eq system-type 'windows-nt)
+                                        "apps" "menu"))))))
     (should ret)))
 
 (defvar ergoemacs-ctl-c-or-ctl-x-delay)
@@ -509,60 +491,42 @@ Test next and prior translation."
 
 (ert-deftest ergoemacs-test-apps-cut ()
   "Tests <apps> x on QWERTY cutting a region, not just a line."
-  (let ((ret nil)
-        (old-ergoemacs-theme ergoemacs-theme)
-        (old-ergoemacs-keyboard-layout ergoemacs-keyboard-layout)
-        (macro (edmacro-parse-keys (format "<%s> x"
-                                           (if (eq system-type 'windows-nt)
-                                               "apps" "menu")) t)))
-    (save-excursion
-      (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-      (ergoemacs-mode -1)
-      (setq ergoemacs-theme nil)
-      (setq ergoemacs-keyboard-layout "us")
-      (ergoemacs-mode 1)
-      (insert ergoemacs-test-lorem-ipsum)
-      (push-mark (point))
-      (push-mark (point-max) nil t)
-      (goto-char (point-min))
-      (execute-kbd-macro macro)
-      (setq ret (string= "" (buffer-string)))
-      (ergoemacs-mode -1)
-      (setq ergoemacs-theme old-ergoemacs-theme)
-      (setq ergoemacs-keyboard-layout old-ergoemacs-keyboard-layout)
-      (ergoemacs-mode 1)
-      (kill-buffer (current-buffer)))
+  (let (ret)
+    (ergoemacs-test-layout
+     :macro (format "<%s> x"
+                    (if (eq system-type 'windows-nt)
+                        "apps" "menu"))
+     (save-excursion
+       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
+       (insert ergoemacs-test-lorem-ipsum)
+       (push-mark (point))
+       (push-mark (point-max) nil t)
+       (goto-char (point-min))
+       (execute-kbd-macro macro)
+       (setq ret (string= "" (buffer-string)))
+       (kill-buffer (current-buffer))))
     (should ret)))
 
 (ert-deftest ergoemacs-test-apps-copy ()
   "Tests <apps> c on QWERTY cutting a region, not just a line."
-  (let ((ret nil)
-        (old-ergoemacs-theme ergoemacs-theme)
-        (old-ergoemacs-keyboard-layout ergoemacs-keyboard-layout)
-        (macro (edmacro-parse-keys (format "<%s> c"
-                                           (if (eq system-type 'windows-nt)
-                                               "apps" "menu")) t)))
-    (save-excursion
-      (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-      (ergoemacs-mode -1)
-      (setq ergoemacs-theme nil)
-      (setq ergoemacs-keyboard-layout "us")
-      (ergoemacs-mode 1)
-      (insert ergoemacs-test-lorem-ipsum)
-      (push-mark (point))
-      (push-mark (point-max) nil t)
-      (goto-char (point-min))
-      (execute-kbd-macro macro)
-      (goto-char (point-max))
-      (ergoemacs-paste)
-      (setq ret (string= (concat ergoemacs-test-lorem-ipsum
-                                 ergoemacs-test-lorem-ipsum)
-                         (buffer-string)))
-      (ergoemacs-mode -1)
-      (setq ergoemacs-theme old-ergoemacs-theme)
-      (setq ergoemacs-keyboard-layout old-ergoemacs-keyboard-layout)
-      (ergoemacs-mode 1)
-      (kill-buffer (current-buffer)))
+  (let (ret)
+    (ergoemacs-test-layout
+     :macro (format "<%s> c"
+                    (if (eq system-type 'windows-nt)
+                        "apps" "menu"))
+     (save-excursion
+       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
+       (insert ergoemacs-test-lorem-ipsum)
+       (push-mark (point))
+       (push-mark (point-max) nil t)
+       (goto-char (point-min))
+       (execute-kbd-macro macro)
+       (goto-char (point-max))
+       (ergoemacs-paste)
+       (setq ret (string= (concat ergoemacs-test-lorem-ipsum
+                                  ergoemacs-test-lorem-ipsum)
+                          (buffer-string)))
+       (kill-buffer (current-buffer))))
     (should ret)))
 
 (ert-deftest ergoemacs-test-shift-selection ()
@@ -601,121 +565,85 @@ See Issue #140."
 (ert-deftest ergoemacs-test-shortcut ()
   "Test that shortcuts don't eat or duplicate key-strokes. (Issue #141)"
   :expected-result (if noninteractive :failed :passed)
-  (let* ((old-ergoemacs-theme ergoemacs-theme)
-         (old-ergoemacs-keyboard-layout ergoemacs-keyboard-layout)
-         (keys (format "<%s> e e M-u"
-                       (if (eq system-type 'windows-nt)
-                           "apps" "menu")))
-         (macro (edmacro-parse-keys keys t))
-         (ret nil))
-    (ergoemacs-mode -1)
-    (setq ergoemacs-theme nil)
-    (setq ergoemacs-keyboard-layout "colemak")
-    (ergoemacs-mode 1)
-    (save-excursion
-      (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-      (insert ergoemacs-test-lorem-ipsum)
-      (goto-char (point-max))
-      (beginning-of-line)
-      (execute-kbd-macro macro)
-      (looking-at ".*")
-      (message "At %s: %s" keys (match-string 0))
-      (when (looking-at "ulla pariatur.")
-        (setq ret t))
-      (kill-buffer (current-buffer)))
-    (ergoemacs-mode -1)
-    (setq ergoemacs-theme old-ergoemacs-theme)
-    (setq ergoemacs-keyboard-layout old-ergoemacs-keyboard-layout)
-    (ergoemacs-mode 1)
+  (let (ret)
+    (ergoemacs-test-layout
+     :macro (format "<%s> e e M-u"
+                    (if (eq system-type 'windows-nt)
+                        "apps" "menu"))
+     :layout "colemak"
+     (save-excursion
+       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
+       (insert ergoemacs-test-lorem-ipsum)
+       (goto-char (point-max))
+       (beginning-of-line)
+       (execute-kbd-macro macro)
+       (looking-at ".*")
+       (when (looking-at "ulla pariatur.")
+         (setq ret t))
+       (kill-buffer (current-buffer))))
     (should (equal ret t))))
 
 
 (ert-deftest ergoemacs-test-misspelled-mark ()
   "Test for mark working with overlays.
 Should test issue #142"
-  (let ((old-ergoemacs-theme ergoemacs-theme)
-        (old-ergoemacs-keyboard-layout ergoemacs-keyboard-layout)
-        (macro (edmacro-parse-keys "M-SPC M-y M-x" t))
-        (ret nil)
+  (let (ret
         tmp (tmp-key (make-sparse-keymap))
         overlays)
-    (define-key tmp-key [ergoemacs-test] 'ignore)
-    (ergoemacs-mode -1)
-    (setq ergoemacs-theme nil)
-    (setq ergoemacs-keyboard-layout "colemak")
-    (ergoemacs-mode 1)
-    (save-excursion
-      (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-      (insert ergoemacs-test-lorem-ipsum)
-      (goto-char (point-min))
-      ;; Put in dummy overlay
-      (while (re-search-forward "[A-Za-z]+" nil t)
-        (setq tmp (make-overlay (match-beginning 0) (match-end 0)))
-        (overlay-put tmp 'keymap tmp-key)
-        (push tmp overlays))
-      (goto-char (point-max))
-      (beginning-of-line)
-      (execute-kbd-macro macro)
-      (when (looking-at " in culpa qui")
-        (setq ret t))
-      (dolist (x overlays)
-        (delete-overlay x))
-      (kill-buffer (current-buffer)))
-    (ergoemacs-mode -1)
-    (setq ergoemacs-theme old-ergoemacs-theme)
-    (setq ergoemacs-keyboard-layout old-ergoemacs-keyboard-layout)
-    (ergoemacs-mode 1)
-    (should (equal ret t))))
+    (ergoemacs-test-layout
+     :macro "M-SPC M-y M-x"
+     :layout "colemak"
+     (define-key tmp-key [ergoemacs-test] 'ignore)
+     (save-excursion
+       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
+       (insert ergoemacs-test-lorem-ipsum)
+       (goto-char (point-min))
+       ;; Put in dummy overlay
+       (while (re-search-forward "[A-Za-z]+" nil t)
+         (setq tmp (make-overlay (match-beginning 0) (match-end 0)))
+         (overlay-put tmp 'keymap tmp-key)
+         (push tmp overlays))
+       (goto-char (point-max))
+       (beginning-of-line)
+       (execute-kbd-macro macro)
+       (when (looking-at " in culpa qui")
+         (setq ret t))
+       (dolist (x overlays)
+         (delete-overlay x))
+       (kill-buffer (current-buffer)))
+     (should (equal ret t)))))
 
 (ert-deftest ergoemacs-test-shift-select-subword ()
   "Test for mark working with shift-selection of `subword-forward'."
-  (let ((old-ergoemacs-theme ergoemacs-theme)
-        (old-ergoemacs-keyboard-layout ergoemacs-keyboard-layout)
-        (macro (edmacro-parse-keys "M-Y M-x" t))
-        (ret nil))
-    (ergoemacs-mode -1)
-    (setq ergoemacs-theme "reduction")
-    (setq ergoemacs-keyboard-layout "colemak")
-    (ergoemacs-mode 1)
-    (save-excursion
-      (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-      (insert ergoemacs-test-lorem-ipsum)
-      (subword-mode 1)
-      (goto-char (point-max))
-      (beginning-of-line)
-      (execute-kbd-macro macro)
-      (when (looking-at " in culpa qui")
-        (setq ret t))
-      (kill-buffer (current-buffer)))
-    (ergoemacs-mode -1)
-    (setq ergoemacs-theme old-ergoemacs-theme)
-    (setq ergoemacs-keyboard-layout old-ergoemacs-keyboard-layout)
-    (ergoemacs-mode 1)
+  (let (ret)
+    (ergoemacs-test-layout
+     :macro "M-Y M-x"
+     :theme "reduction"
+     :layout "colemak"
+     (save-excursion
+       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
+       (insert ergoemacs-test-lorem-ipsum)
+       (subword-mode 1)
+       (goto-char (point-max))
+       (beginning-of-line)
+       (execute-kbd-macro macro)
+       (when (looking-at " in culpa qui")
+         (setq ret t))
+       (kill-buffer (current-buffer))))
     (should (equal ret t))))
 
 (ert-deftest ergoemacs-test-apps-e-t-_ ()
   "Test that colemak <apps> e t sends _.
 Should test for Issue #143."
-  (let ((old-ergoemacs-theme ergoemacs-theme)
-        (old-ergoemacs-keyboard-layout ergoemacs-keyboard-layout)
-        unread-command-events
-        (ret nil))
-    (ergoemacs-mode -1)
-    (setq ergoemacs-theme "reduction")
-    (setq ergoemacs-keyboard-layout "colemak")
-    (ergoemacs-mode 1)
-    (ergoemacs-read-key (format "<%s> e t"
-                                (if (eq system-type 'windows-nt)
-                                    "apps" "menu")))
-    (setq ret (equal (listify-key-sequence (read-kbd-macro "_"))
-                     unread-command-events))
-    (message "%s;%s" (listify-key-sequence (read-kbd-macro "_"))
-             unread-command-events)
-    (ergoemacs-mode -1)
-    (setq ergoemacs-theme old-ergoemacs-theme)
-    (setq ergoemacs-keyboard-layout old-ergoemacs-keyboard-layout)
-    (ergoemacs-mode 1)
-    (should (equal ret t))))
+  (let (unread-command-events)
+    (ergoemacs-test-layout
+     :theme "reduction"
+     :layout "colemak"
+     (ergoemacs-read-key (format "<%s> e t"
+                                 (if (eq system-type 'windows-nt)
+                                     "apps" "menu")))
+     (should (equal (listify-key-sequence (read-kbd-macro "_"))
+                    unread-command-events)))))
 
 (ert-deftest ergoemacs-test-ignore-global-definitions-on-remap ()
   "If someone sets a key on the global keymap, ignore it.
@@ -766,61 +694,46 @@ Part of addressing Issue #147."
 
 (ert-deftest ergoemacs-test-overlay-paren ()
   "Test that overlays will send the appropriate parenthesis"
-  (let ((old-ergoemacs-theme ergoemacs-theme)
-        (old-ergoemacs-keyboard-layout ergoemacs-keyboard-layout)
-        (ret nil)
-        (macro (edmacro-parse-keys (format "M-i <%s> e e"
-                                           (if (eq system-type 'windows-nt)
-                                               "apps" "menu")) t))
+  (let (ret
         tmp (tmp-key (make-sparse-keymap)) overlays)
-    (define-key tmp-key [ergoemacs-test] 'ignore)
-    (ergoemacs-mode -1)
-    (setq ergoemacs-theme nil)
-    (setq ergoemacs-keyboard-layout "colemak")
-    (ergoemacs-mode 1)
-    (save-excursion
-      (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-      (insert ergoemacs-test-lorem-ipsum)
-      (goto-char (point-min))
-      ;; Put in dummy overlay
-      (while (re-search-forward "[A-Za-z]+" nil t)
-        (setq tmp (make-overlay (match-beginning 0) (match-end 0)))
-        (overlay-put tmp 'keymap tmp-key)
-        (push tmp overlays))
-      (goto-char (point-min))
-      (execute-kbd-macro macro)
-      (when (looking-at ")")
-        (setq ret t))
-      (dolist (x overlays)
-        (delete-overlay x))
-      (kill-buffer (current-buffer)))
-    (ergoemacs-mode -1)
-    (setq ergoemacs-theme old-ergoemacs-theme)
-    (setq ergoemacs-keyboard-layout old-ergoemacs-keyboard-layout)
-    (ergoemacs-mode 1)
+    (ergoemacs-test-layout
+     :layout "colemak"
+     :macro (format "M-i <%s> e e"
+                    (if (eq system-type 'windows-nt)
+                        "apps" "menu"))
+     (define-key tmp-key [ergoemacs-test] 'ignore)
+     (save-excursion
+       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
+       (insert ergoemacs-test-lorem-ipsum)
+       (goto-char (point-min))
+       ;; Put in dummy overlay
+       (while (re-search-forward "[A-Za-z]+" nil t)
+         (setq tmp (make-overlay (match-beginning 0) (match-end 0)))
+         (overlay-put tmp 'keymap tmp-key)
+         (push tmp overlays))
+       (goto-char (point-min))
+       (execute-kbd-macro macro)
+       (when (looking-at ")")
+         (setq ret t))
+       (dolist (x overlays)
+         (delete-overlay x))
+       (kill-buffer (current-buffer))))
     (should (equal ret t))))
 
 (ert-deftest ergoemacs-test-shift-selection-reduction ()
   "Test that shift selection works properly in reduction."
-  (let ((old-ergoemacs-theme ergoemacs-theme)
-        (old-ergoemacs-keyboard-layout ergoemacs-keyboard-layout)
-        (ret nil))
-    (ergoemacs-mode -1)
-    (setq ergoemacs-theme "reduction")
-    (setq ergoemacs-keyboard-layout "colemak")
-    (ergoemacs-mode 1)
-    (save-excursion
-      (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-      (insert ergoemacs-test-lorem-ipsum)
-      (goto-char (point-min))
-      (execute-kbd-macro (edmacro-parse-keys "M-E M-E" t))
-      (call-interactively 'ergoemacs-cut-line-or-region)
-      (setq ret (= (point) (point-min)))
-      (kill-buffer (current-buffer)))
-    (ergoemacs-mode -1)
-    (setq ergoemacs-theme old-ergoemacs-theme)
-    (setq ergoemacs-keyboard-layout old-ergoemacs-keyboard-layout)
-    (ergoemacs-mode 1)
+  (let (ret)
+    (ergoemacs-test-layout
+     :theme "reduction"
+     :layout "colemak"
+     (save-excursion
+       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
+       (insert ergoemacs-test-lorem-ipsum)
+       (goto-char (point-min))
+       (execute-kbd-macro (edmacro-parse-keys "M-E M-E" t))
+       (call-interactively 'ergoemacs-cut-line-or-region)
+       (setq ret (= (point) (point-min)))
+       (kill-buffer (current-buffer))))
     (should (equal ret t))))
 
 (ert-deftest ergoemacs-test-isearch-works-with-region ()
@@ -829,47 +742,30 @@ already selected, isearch-ing would expand or shrink 
selection.
 Currently ergoemacs-mode discards selection as soon as isearch key is
 pressed. Reproducible with ergoemacs-clean.
 Issue #186."
-  (let ((old-ergoemacs-theme ergoemacs-theme)
-        (old-ergoemacs-keyboard-layout ergoemacs-keyboard-layout)
-        (macro (edmacro-parse-keys "C-f lab" t))
-        (ret t))
-    (ergoemacs-mode -1)
-    (setq ergoemacs-theme nil)
-    (setq ergoemacs-keyboard-layout "colemak")
-    (ergoemacs-mode 1)
-    (cua-mode 1)
-    (save-excursion
-      (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-      (insert ergoemacs-test-lorem-ipsum)
-      (goto-char (point-min))
-      (mark-word)
-      (execute-kbd-macro macro)
-      (setq ret mark-active)
-      (kill-buffer (current-buffer)))
-    (ergoemacs-mode -1)
-    (setq ergoemacs-theme old-ergoemacs-theme)
-    (setq ergoemacs-keyboard-layout old-ergoemacs-keyboard-layout)
-    (ergoemacs-mode 1)
+  (let ((ret t))
+    (ergoemacs-test-layout
+     :macro "C-f lab"
+     :layout "colemak"
+     :cua t
+     (save-excursion
+       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
+       (insert ergoemacs-test-lorem-ipsum)
+       (goto-char (point-min))
+       (mark-word)
+       (execute-kbd-macro macro)
+       (setq ret mark-active)
+       (kill-buffer (current-buffer))))
     (should (equal ret t))))
 
 (ert-deftest ergoemacs-test-reduction-M-g-works ()
   "Test Ergoemacs M-g works correctly (Issue #171)."
-  (let ((old-ergoemacs-theme ergoemacs-theme)
-        (old-ergoemacs-keyboard-layout ergoemacs-keyboard-layout)
-        (ergoemacs-test-fn t)
-        (ret nil))
-    (ergoemacs-mode -1)
-    (setq ergoemacs-theme "reduction")
-    (setq ergoemacs-keyboard-layout "colemak")
-    (ergoemacs-mode 1)
-    (with-timeout (0.2 nil) (ergoemacs-read-key "M-g"))
-    (message "Test FN: %s" ergoemacs-test-fn)
-    (setq ret (eq ergoemacs-test-fn (or (command-remapping 
'execute-extended-command (point)) 'execute-extended-command)))
-    (ergoemacs-mode -1)
-    (setq ergoemacs-theme old-ergoemacs-theme)
-    (setq ergoemacs-keyboard-layout old-ergoemacs-keyboard-layout)
-    (ergoemacs-mode 1)
-    (should ret)))
+  (let ((ergoemacs-test-fn t))
+    (ergoemacs-test-layout
+     :theme "reduction"
+     :layout "colemak"
+     (with-timeout (0.2 nil) (ergoemacs-read-key "M-g"))
+     (message "Test FN: %s" ergoemacs-test-fn)
+     (should (eq ergoemacs-test-fn (or (command-remapping 
'execute-extended-command (point)) 'execute-extended-command))))))
 
 (declare-function ergoemacs-copy-line-or-region "ergoemacs-functions.el")
 (ert-deftest ergoemacs-test-issue-184-paste ()
@@ -963,39 +859,28 @@ Selected mark would not be cleared after paste."
   "Tests Issue #188"
   :expected-result (if noninteractive :passed :failed)
   (let ((old-map (copy-keymap input-decode-map))
-        (old-ergoemacs-theme ergoemacs-theme)
-        (old-ergoemacs-keyboard-layout ergoemacs-keyboard-layout)
         (ret nil))
-    (setq input-decode-map (make-sparse-keymap)
-          ergoemacs-theme nil
-          ergoemacs-keyboard-layout "us")
-    ;; Setup input decode map just like `xterm' for some common keys.
-    (define-key input-decode-map "\eOA" [up])
-    (define-key input-decode-map "\eOB" [down])
-    (define-key input-decode-map "\eOC" [right])
-    (define-key input-decode-map "\eOD" [left])
-    (define-key input-decode-map "\eOF" [end])
-    (define-key input-decode-map "\eOH" [home])
-    (ergoemacs-mode -1)
-    (ergoemacs-mode 1)
-    (save-excursion
-      (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-      (delete-region (point-min) (point-max))
-      (insert ergoemacs-test-lorem-ipsum)
-      (goto-char (point-max))
-      (beginning-of-line)
-      (with-timeout (0.2 nil)
-        (ergoemacs-read-key "M-O A")) ; by looking at `ergoemacs-read-key' 
this seems to be translating correctly, but... it doesn't run in this context.
-      (message "Decode: %s" (lookup-key input-decode-map (kbd "M-O A")))
-      (setq ret (looking-at "nulla pariatur. Excepteur sint occaecat cupidatat 
non proident,"))
-      (kill-buffer (current-buffer)))
-    ;; Restore old `input-decode-map' & ergoemacs-mode themes.
-    (setq input-decode-map (copy-keymap old-map)
-          ergoemacs-theme old-ergoemacs-theme
-          ergoemacs-keyboard-layout old-ergoemacs-keyboard-layout)
-    (ergoemacs-mode -1)
-    (ergoemacs-mode 1)
-    ;; (progn (require 'ergoemacs-test) (ert 
"ergoemacs-test-terminal-M-O-fight"))
+    (ergoemacs-test-layout
+     (setq input-decode-map (make-sparse-keymap))
+     ;; Setup input decode map just like `xterm' for some common keys.
+     (define-key input-decode-map "\eOA" [up])
+     (define-key input-decode-map "\eOB" [down])
+     (define-key input-decode-map "\eOC" [right])
+     (define-key input-decode-map "\eOD" [left])
+     (define-key input-decode-map "\eOF" [end])
+     (define-key input-decode-map "\eOH" [home])
+     (save-excursion
+       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
+       (delete-region (point-min) (point-max))
+       (insert ergoemacs-test-lorem-ipsum)
+       (goto-char (point-max))
+       (beginning-of-line)
+       (with-timeout (0.2 nil)
+         (ergoemacs-read-key "M-O A")) ; by looking at `ergoemacs-read-key' 
this seems to be translating correctly, but... it doesn't run in this context.
+       (message "Decode: %s" (lookup-key input-decode-map (kbd "M-O A")))
+       (setq ret (looking-at "nulla pariatur. Excepteur sint occaecat 
cupidatat non proident,"))
+       (kill-buffer (current-buffer)))
+     (setq input-decode-map (copy-keymap old-map)))
     (should ret)))
 
 ;; (ert-deftest ergoemacs-test-comment-dwim-deactivate-region ()
@@ -1029,33 +914,21 @@ Selected mark would not be cleared after paste."
 (ert-deftest ergoemacs-test-alt-mode-horizontal-position ()
   "Tests Issue #213"
   :expected-result (if noninteractive :failed :passed) ;; Not sure why.
-  (let ((old-map (copy-keymap input-decode-map))
-        (old-ergoemacs-theme ergoemacs-theme)
-        (old-ergoemacs-keyboard-layout ergoemacs-keyboard-layout)
-        (macro (edmacro-parse-keys "i u u" t))
-        (ret nil))
-    (setq input-decode-map (make-sparse-keymap)
-          ergoemacs-theme nil
-          ergoemacs-keyboard-layout "colemak")
-    (ergoemacs-mode -1)
-    (ergoemacs-mode 1)
-    (save-excursion
-      (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
-      (delete-region (point-min) (point-max))
-      (insert ergoemacs-test-lorem-ipsum)
-      (goto-char (point-max))
-      (beginning-of-line)
-      (ergoemacs-unchorded-alt-modal)
-      (execute-kbd-macro macro)
-      (setq ret (looking-at "eprehenderit"))
-      (ergoemacs-unchorded-alt-modal)
-      (kill-buffer (current-buffer)))
-    ;; Restore old `input-decode-map' & ergoemacs-mode themes.
-    (setq ergoemacs-theme old-ergoemacs-theme
-          ergoemacs-keyboard-layout old-ergoemacs-keyboard-layout)
-    (ergoemacs-mode -1)
-    (ergoemacs-mode 1)
-    ;; (progn (require 'ergoemacs-test) (ert 
"ergoemacs-test-terminal-M-O-fight"))
+  (let (ret)
+    (ergoemacs-test-layout
+     :layout "colemak"
+     :macro "i u u"
+     (save-excursion
+       (switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
+       (delete-region (point-min) (point-max))
+       (insert ergoemacs-test-lorem-ipsum)
+       (goto-char (point-max))
+       (beginning-of-line)
+       (ergoemacs-unchorded-alt-modal)
+       (execute-kbd-macro macro)
+       (setq ret (looking-at "eprehenderit"))
+       (ergoemacs-unchorded-alt-modal)
+       (kill-buffer (current-buffer))))
     (should ret)))
 
 
@@ -1067,6 +940,8 @@ Selected mark would not be cleared after paste."
   "Test global C-c b"
   (should (equal (ergoemacs-test-global-key-set-before nil "C-c b") t)))
 
+
+
 (provide 'ergoemacs-test)
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; ergoemacs-test.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]