-
Notifications
You must be signed in to change notification settings - Fork 35
/
ergoemacs-test.el
583 lines (491 loc) · 24.4 KB
/
ergoemacs-test.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
;;; ergoemacs-test.el --- tests for ErgoEmacs issues -*- lexical-binding: t; -*-
;; Copyright © 2013-2023 Free Software Foundation, Inc.
;; Maintainer: Matthew L. Fidler
;; Keywords: convenience
;; ErgoEmacs 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.
;; ErgoEmacs 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 ErgoEmacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; Todo:
;;
;;; Code:
(require 'ergoemacs-functions)
(require 'ergoemacs-command-loop)
(require 'ergoemacs-translate)
(eval-when-compile
(require 'cl-lib)
(require 'ergoemacs-macros))
(declare-function ergoemacs-translate--keymap "ergoemacs-translate")
(declare-function ergoemacs-mode-reset "ergoemacs-mode")
(defvar ergoemacs-map--)
(defvar ergoemacs-layout-us)
(defvar ergoemacs-keyboard-layout)
(defvar ergoemacs-command-loop-type)
(defvar ergoemacs-dir)
(defvar ergoemacs-mode)
(defvar dired-sort-map)
(defvar dired-mode-map)
(declare-function ergoemacs-translate--meta-to-escape "ergoemacs-translate")
(declare-function ergoemacs-map-keymap "ergoemacs-mapkeymap")
(declare-function ergoemacs-mode "ergoemacs-mode")
(declare-function ergoemacs-command-loop--mouse-command-drop-first "ergoemacs-command-loop")
(declare-function ergoemacs-copy-line-or-region "ergoemacs-functions")
(declare-function ergoemacs-cut-line-or-region "ergoemacs-functions")
(declare-function ergoemacs-emacs-exe "ergoemacs-functions")
(declare-function ergoemacs-eshell-here "ergoemacs-functions")
(declare-function ergoemacs-paste "ergoemacs-functions")
(declare-function ergoemacs-translate--quail-to-ergoemacs "ergoemacs-translate")
(declare-function ergoemacs-translate-layout "ergoemacs-translate")
(require 'ert)
(require 'elp)
;;; Not sure why `cl-gensym' is called, probably from `ert'/`elp'?
;; Suppress: "the function `cl-gensym' might not be defined at
;; runtime" warning.
(autoload 'cl-gensym "cl-macs.el")
(defvar ergoemacs-test-lorem-ipsum
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat
nulla pariatur. Excepteur sint occaecat cupidatat non proident,
sunt in culpa qui officia deserunt mollit anim id est laborum.")
(defun ergoemacs-test-fast ()
"Fast test of ergoemacs-mode (doesn't include keyboard startup issues)."
(interactive)
(elp-instrument-package "ergoemacs-")
(ert '(and "ergoemacs-" (not (tag :slow))))
(call-interactively 'elp-results))
(defun ergoemacs-test-search ()
"Test search functionality in ergoemacs-mode."
(interactive)
(elp-instrument-package "ergoemacs-")
(ert '(and "ergoemacs-" (tag :search)))
(call-interactively 'elp-results))
(defun ergoemacs-test-map-keymap ()
"Test search functionality in ergoemacs-mode."
(interactive)
(elp-instrument-package "ergoemacs-")
(ert '(and "ergoemacs-" (tag :map-keymap)))
(call-interactively 'elp-results))
(defun ergoemacs-test-calc ()
"Test for calc."
(interactive)
(elp-instrument-package "ergoemacs-")
(ert '(and "ergoemacs-" (tag :calc)))
(call-interactively 'elp-results))
(defun ergoemacs-test-no-calc ()
"Test for calc."
(interactive)
(elp-instrument-package "ergoemacs-")
(ert '(and "ergoemacs-" (not (tag :calc))))
(call-interactively 'elp-results))
(defun ergoemacs-test-shift-select ()
"Shift-selection test for ergoemacs-mode."
(interactive)
(elp-instrument-package "ergoemacs-")
(ert '(and "ergoemacs-" (tag :shift-select)))
(call-interactively 'elp-results))
(defun ergoemacs-test-translate ()
"Translation test for ergoemacs-mode."
(interactive)
(elp-instrument-package "ergoemacs-")
(ert '(and "ergoemacs-" (tag :translate)))
(call-interactively 'elp-results))
(defun ergoemacs-test-interactive ()
"Interactive test for ergoemacs-mode."
(interactive)
(elp-instrument-package "ergoemacs-")
(ert '(and "ergoemacs-" (tag :interactive)))
(call-interactively 'elp-results))
;;;###autoload
(defun ergoemacs-test ()
"Test ergoemacs issues."
(interactive)
(let (;; (ret t)
;; (test)
)
(elp-instrument-package "ergoemacs-")
(ert "^ergoemacs-test-")
(call-interactively 'elp-results)))
(ert-deftest ergoemacs-test-copy-paste-cut-line-or-region ()
"Issue #68.
kill-ring function name is used and such doesn't exist. It errs when
not using cua or cutting line. I think kill-region is what is meant."
(let ((old-c cua-mode)
(ret t))
(cua-mode -1)
(save-excursion
(switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
(delete-region (point-min) (point-max))
(insert ergoemacs-test-lorem-ipsum)
(condition-case _err
(ergoemacs-cut-line-or-region)
(error (setq ret nil)))
(kill-buffer (current-buffer)))
(when old-c
(cua-mode 1))
(should ret)
)
)
;;; Functionality Test
(ert-deftest ergoemacs-test-function-bol-or-what ()
"Test beginning of line functionality."
(let ((ergoemacs-end-of-comment-line t)
(ergoemacs-back-to-indentation t))
(with-temp-buffer
(emacs-lisp-mode) ; Turn on ergoemacs-mode
(insert "(progn\n (ergoemacs-mode 1)) ; Turn on ergoemacs-mode")
(goto-char (point-max))
(call-interactively 'ergoemacs-beginning-of-line-or-what)
(should (string= "Turn on ergoemacs-mode"
(buffer-substring (point) (line-end-position))))
(call-interactively 'ergoemacs-beginning-of-line-or-what)
(should (string= " ; Turn on ergoemacs-mode"
(buffer-substring (point) (line-end-position))))
(call-interactively 'ergoemacs-beginning-of-line-or-what)
(should (string= "(ergoemacs-mode 1)) ; Turn on ergoemacs-mode"
(buffer-substring (point) (line-end-position))))
(call-interactively 'ergoemacs-beginning-of-line-or-what)
(should (string= " (ergoemacs-mode 1)) ; Turn on ergoemacs-mode"
(buffer-substring (point) (line-end-position)))))))
(ert-deftest ergoemacs-test-function-eol-or-what ()
"Test beginning of line functionality."
(let ((ergoemacs-end-of-comment-line t)
(ergoemacs-back-to-indentation t))
(with-temp-buffer
(emacs-lisp-mode) ; Turn on ergoemacs-mode
(insert "(progn\n (ergoemacs-mode 1)) ; Turn on ergoemacs-mode")
(goto-char (point-max))
(beginning-of-line)
(call-interactively 'ergoemacs-end-of-line-or-what)
(should (string= " ; Turn on ergoemacs-mode"
(buffer-substring (point) (line-end-position))))
(call-interactively 'ergoemacs-end-of-line-or-what)
(should (= (point) (line-end-position))))))
(ert-deftest ergoemacs-test-function-unbind-commands-active ()
"Make sure the unbound keys work"
(should (eq 'undefined (key-binding (read-kbd-macro "C-x C-s")))))
;;; Org-mode
;;; Calc
;;; Command Loop
(ert-deftest ergoemacs-test-command-loop-C-x-8-! ()
"Test that unicode translations work.
See Issue #138."
(save-excursion
(switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
(delete-region (point-min) (point-max))
(execute-kbd-macro (kbd "C-x 8 !"))
(should (string= "¡" (buffer-string)))
(kill-buffer (current-buffer))))
(ert-deftest ergoemacs-test-command-loop-C-x-8-A ()
"Test that unicode translations work.
See Issue #138."
(save-excursion
(switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
(delete-region (point-min) (point-max))
(execute-kbd-macro (kbd "C-x 8 \" A"))
(should (string= "Ä" (buffer-string)))
(kill-buffer (current-buffer))))
;;; Global map tests.
(defun ergoemacs-test-global-key-set-before (&optional after key ergoemacs ignore-prev-global delete-def)
"Test the global key set before ergoemacs-mode is loaded."
:tags '(:slow)
(let* ((emacs-exe (ergoemacs-emacs-exe))
(ret nil)
(sk nil)
(test-key (or key "M-k"))
(w-file (expand-file-name "global-test" ergoemacs-dir))
(temp-file (make-temp-file "ergoemacs-test" nil ".el")))
(setq sk
(format "(%s (lambda() (interactive) (with-temp-file \"%s\" (insert \"Ok\"))))"
(cond
((eq ergoemacs 'define-key)
(format "define-key global-map (kbd \"%s\") " test-key))
(t
(format "global-set-key (kbd \"%s\") " test-key)))
w-file))
(with-temp-file temp-file
(if (boundp 'wait-for-me)
(insert "(setq debug-on-error t)")
(insert "(condition-case err (progn "))
(unless after
(when delete-def
(insert (format "(global-set-key (kbd \"%s\") nil)" delete-def)))
(insert sk))
(insert (format "(add-to-list 'load-path \"%s\")" ergoemacs-dir))
(insert "(setq ergoemacs-keyboard-layout \"us\")")
(unless ignore-prev-global
(insert "(setq ergoemacs-ignore-prev-global nil)"))
(insert "(require 'ergoemacs-mode)(setq ergoemacs-mode--start-p t)(ergoemacs-mode 1)")
(insert
(format
"(setq ergoemacs-test-macro (edmacro-parse-keys \"%s\" t))"
test-key))
(when after
(when delete-def
(insert (format "(global-set-key (kbd \"%s\") nil)" delete-def)))
(insert sk))
(insert "(execute-kbd-macro ergoemacs-test-macro)")
(insert (format "(if (file-exists-p \"%s\") (message \"Passed\") (message \"Failed\"))" w-file))
(unless (boundp 'wait-for-me)
(insert ") (error (message \"Error %s\" err)))")
(insert "(kill-emacs)")))
(message
"%s"
(shell-command-to-string
(format "%s %s -Q -l %s" emacs-exe (if (boundp 'wait-for-me) "" "--batch") temp-file)))
(delete-file temp-file)
(when (file-exists-p w-file)
(setq ret 't)
(delete-file w-file))
ret))
(ert-deftest ergoemacs-test-global-key-set-after-220 ()
"Test global C-c b"
:tags '(:slow)
(should (equal (ergoemacs-test-global-key-set-before 'after "C-c b") t)))
(defvar ergoemacs-component-hash)
(ert-deftest ergoemacs-test-global-key-set-apps-220-before ()
"Test global C-c b"
:tags '(:slow :interactive)
(should (equal (ergoemacs-test-global-key-set-before nil "C-c b") t)))
(ert-deftest ergoemacs-test-issue-243 ()
"Allow globally set keys like C-c C-c M-x to work globally while local commands like C-c C-c will work correctly. "
:tags '(:slow)
(let ((emacs-exe (ergoemacs-emacs-exe))
(w-file (expand-file-name "global-test" ergoemacs-dir))
(temp-file (make-temp-file "ergoemacs-test" nil ".el")))
(with-temp-file temp-file
(insert "(condition-case err (progn ")
(insert (format "(add-to-list 'load-path \"%s\")" ergoemacs-dir))
(insert "(setq ergoemacs-keyboard-layout \"us\")")
(insert "(setq ergoemacs-command-loop-type nil)")
(insert "(require 'ergoemacs-mode)(require 'ergoemacs-test)(setq ergoemacs-mode--start-p t)(ergoemacs-mode 1)")
(insert "(global-set-key (kbd \"C-c C-c M-x\") 'execute-extended-command)")
(insert (format "(define-key ergoemacs-test-major-mode-map (kbd \"C-c C-c\") #'(lambda() (interactive (with-temp-file \"%s\" (insert \"Ok\")))))" w-file))
(insert
"(setq ergoemacs-test-macro (edmacro-parse-keys \"C-c C-c\" t))(ergoemacs-test-major-mode)")
(insert "(with-timeout (0.5 nil) (execute-kbd-macro ergoemacs-test-macro))")
(insert (format "(if (file-exists-p \"%s\") (message \"Passed\") (message \"Failed\"))" w-file))
(insert ") (error (message \"Error %s\" err)))")
(unless (boundp 'wait-for-me)
(insert "(kill-emacs)")))
(message "%s"
(shell-command-to-string
(format "%s %s -Q -l %s"
emacs-exe (if (boundp 'wait-for-me) "" "--batch")
temp-file)))
(delete-file temp-file)
(should (file-exists-p w-file))
(when (file-exists-p w-file)
(delete-file w-file))))
;; Issue 437
;;
;; Can override an ergoemacs binding when loading the new mode. For
;; example, this code changes M-left to M-right.
;;
;; (add-hook 'org-mode-hook
;; (lambda ()
;; (define-key org-mode-map (kbd "<M-left>") 'org-metaright)
;; ))
;;; Not sure why this doesn't actually use `ergoemacs-test-major-mode-map'.
(define-derived-mode ergoemacs-test-major-mode fundamental-mode "ET"
"Major mode for testing some issues with `ergoemacs-mode'.
\\{ergoemacs-test-major-mode-map}")
(define-key ergoemacs-test-major-mode-map (kbd "C-s") #'search-forward)
(define-key ergoemacs-test-major-mode-map (kbd "<f6>") #'search-forward)
(define-key ergoemacs-test-major-mode-map (kbd "M-s a") #'isearch-forward)
(define-key ergoemacs-test-major-mode-map (kbd "M-s b") #'isearch-backward)
;; (let ((ergoemacs-is-user-defined-map-change-p t))
(add-hook 'ergoemacs-test-major-mode-hook
(lambda()
(define-key ergoemacs-test-major-mode-map (kbd "C-w") #'ergoemacs-close-current-buffer))) ;; )
(ert-deftest ergoemacs-test-issue-349 ()
"Unbind <f6>"
:tags '(:slow :interactive)
(let ((emacs-exe (ergoemacs-emacs-exe))
(w-file (expand-file-name "global-test" ergoemacs-dir))
(temp-file (make-temp-file "ergoemacs-test" nil ".el")))
(with-temp-file temp-file
(insert "(condition-case err (progn ")
(insert (format "(add-to-list 'load-path \"%s\")" ergoemacs-dir))
(insert "(setq ergoemacs-keyboard-layout \"us\")")
(insert "(setq ergoemacs-command-loop-type nil)")
(insert "(require 'ergoemacs-mode)(require 'ergoemacs-test)(setq ergoemacs-mode--start-p t)(ergoemacs-mode 1)")
(insert (format "(define-key ergoemacs-test-major-mode-map (kbd \"<f6>\") #'(lambda() (interactive (with-temp-file \"%s\" (insert \"Ok\")))))" w-file))
(insert "(global-unset-key (kbd \"<f6>\"))")
(insert
"(setq ergoemacs-test-macro (edmacro-parse-keys \"<f6>\" t))(ergoemacs-test-major-mode)(run-hooks 'post-command-hook)")
(insert "(with-timeout (0.5 nil) (execute-kbd-macro ergoemacs-test-macro))")
(insert (format "(if (file-exists-p \"%s\") (message \"Passed\") (message \"Failed\"))" w-file))
(insert ") (error (message \"Error %s\" err)))")
(unless (boundp 'wait-for-me)
(insert "(kill-emacs)")))
(message "%s"
(shell-command-to-string
(format "%s %s -Q -l %s"
emacs-exe (if (boundp 'wait-for-me) "" "--batch")
temp-file)))
(delete-file temp-file)
(should (file-exists-p w-file))
(when (file-exists-p w-file)
(delete-file w-file))))
(defvar ergoemacs-use-function-remapping)
(ert-deftest ergoemacs-test-ignore-ctl-w ()
"Keep user-defined C-w in major-mode `ergoemacs-test-major-mode'.
Part of addressing Issue #147."
(let (;; ret
(ergoemacs-use-function-remapping t))
(with-temp-buffer
(ergoemacs-test-major-mode)
(when (not (current-local-map))
(use-local-map ergoemacs-test-major-mode-map))
(should (eq (key-binding (kbd "C-w")) 'ergoemacs-close-current-buffer))
;; The user-defined C-w should not affect kill-region remaps.
(should (not (eq (key-binding [ergoemacs-remap kill-region]) 'ergoemacs-close-current-buffer))))))
(require 'dired)
(defvar ergoemacs-test--dired-sort-map
(let ((map (make-sparse-keymap)))
(define-key map "s"
(lambda () "sort by Size"
(interactive) (dired-sort-other (concat dired-listing-switches "-AlS --si --time-style long-iso"))))
(define-key map "."
(lambda () "sort by eXtension"
(interactive) (dired-sort-other (concat dired-listing-switches "X"))))
(define-key map "t"
(lambda () "sort by Time"
(interactive) (dired-sort-other (concat dired-listing-switches "t"))))
(define-key map "n"
(lambda () "sort by Name"
(interactive) (dired-sort-other (concat dired-listing-switches ""))))
map))
(defun ergoemacs-test--dired-hook ()
(define-key dired-mode-map "s" ergoemacs-test--dired-sort-map)
;; Use "|", not "r".
(define-key dired-mode-map "|" #'dired-sort-menu-toggle-reverse)
)
(ert-deftest ergoemacs-test-dired-sort-files ()
"Test Issue #340"
(add-hook 'dired-mode-hook #'ergoemacs-test--dired-hook)
(dired ergoemacs-dir)
(should (equal (key-binding (kbd "s s"))
(lookup-key ergoemacs-test--dired-sort-map "s")))
(should (equal (key-binding (kbd "s ."))
(lookup-key ergoemacs-test--dired-sort-map ".")))
(should (equal (key-binding (kbd "s t"))
(lookup-key ergoemacs-test--dired-sort-map "t")))
(should (equal (key-binding (kbd "s n"))
(lookup-key ergoemacs-test--dired-sort-map "n")))
(should (equal (key-binding (kbd "|")) #'dired-sort-menu-toggle-reverse))
(kill-buffer (current-buffer))
;; FIXME: This does not restore `dired-mode-map'!
(remove-hook 'dired-mode-hook #'ergoemacs-test--dired-hook))
(ert-deftest ergoemacs-test-quail-translations ()
"Test if quail to ergoemacs-mode translations work."
:tags '(:translate)
(should (equal ergoemacs-layout-us (ergoemacs-translate--quail-to-ergoemacs (ergoemacs-translate-layout 'us :quail)))))
(ert-deftest ergoemacs-test-translations ()
"Test ergoemacs-mode translations"
:tags '(:translate)
(should (string= "A" (key-description (vector (ergoemacs-translate--event-mods (elt (read-kbd-macro "A" t) 0))))))
(should (string= "M-A" (key-description (vector (ergoemacs-translate--event-mods (elt (read-kbd-macro "A" t) 0) :unchorded-alt)))))
(should (string= "C-S-a" (key-description (vector (ergoemacs-translate--event-mods (elt (read-kbd-macro "A" t) 0) :unchorded-ctl)))))
(should (string= "M-A" (key-description (vector (ergoemacs-translate--event-mods (elt (read-kbd-macro "C-S-a" t) 0) :ctl-to-alt)))))
;; DEL = ^?, doesn't seem to have the issues that RET, ESC, and TAB has.
(should (string= "DEL" (key-description (vector (ergoemacs-translate--event-mods (elt (read-kbd-macro "DEL" t) 0) :ctl-to-alt)))))
(should (string= "C-DEL" (key-description (vector (ergoemacs-translate--event-mods (elt (read-kbd-macro "M-DEL" t) 0) :ctl-to-alt)))))
(should (string= "M-DEL" (key-description (vector (ergoemacs-translate--event-mods (elt (read-kbd-macro "C-DEL" t) 0) :ctl-to-alt)))))
;; RET = ^M
(should (string= "RET" (key-description (vector (ergoemacs-translate--event-mods (elt (read-kbd-macro "RET" t) 0) :ctl-to-alt)))))
(should (string= "M-RET" (key-description (vector (ergoemacs-translate--event-mods (elt (read-kbd-macro "C-RET" t) 0) :ctl-to-alt)))))
(should (string= "C-RET" (key-description (vector (ergoemacs-translate--event-mods (elt (read-kbd-macro "M-RET" t) 0) :ctl-to-alt)))))
;; ESC = ^[
(should (string= "ESC" (key-description (vector (ergoemacs-translate--event-mods (elt (read-kbd-macro "ESC" t) 0) :ctl-to-alt)))))
(should (string= "C-ESC" (key-description (vector (ergoemacs-translate--event-mods (elt (read-kbd-macro "M-ESC" t) 0) :ctl-to-alt)))))
(should (string= "M-ESC" (key-description (vector (ergoemacs-translate--event-mods (elt (read-kbd-macro "C-ESC" t) 0) :ctl-to-alt)))))
;; TAB = ^i
(should (string= "TAB" (key-description (vector (ergoemacs-translate--event-mods (elt (read-kbd-macro "TAB" t) 0) :ctl-to-alt)))))
(should (string= "C-TAB" (key-description (vector (ergoemacs-translate--event-mods (elt (read-kbd-macro "M-TAB" t) 0) :ctl-to-alt)))))
(should (string= (key-description (kbd "M-TAB")) (key-description (vector (ergoemacs-translate--event-mods (elt (read-kbd-macro "C-TAB" t) 0) :ctl-to-alt)))))
(cl-letf (((symbol-function 'display-graphic-p) (lambda(&rest _ignore) t)))
;; Test M-i -> ^i -> TAB
(should (string= "<C-i>" (key-description (vector (ergoemacs-translate--event-mods (elt (read-kbd-macro "M-i" t) 0) :ctl-to-alt)))))
;; Test M-[ -> ^[ -> ESC
(should (string= "<C-[>" (key-description (vector (ergoemacs-translate--event-mods (elt (read-kbd-macro "M-[" t) 0) :ctl-to-alt)))))
;; Test M-m -> ^m -> RET
(should (string= "<C-m>" (key-description (vector (ergoemacs-translate--event-mods (elt (read-kbd-macro "M-m" t) 0) :ctl-to-alt))))))
(cl-letf (((symbol-function 'display-graphic-p) (lambda(&rest _ignore) nil)))
;; Test M-i -> ^i -> TAB
(should (string= "TAB" (key-description (vector (ergoemacs-translate--event-mods (elt (read-kbd-macro "M-i" t) 0) :ctl-to-alt)))))
;; Test M-[ -> ^[ -> ESC
(should (string= "ESC" (key-description (vector (ergoemacs-translate--event-mods (elt (read-kbd-macro "M-[" t) 0) :ctl-to-alt)))))
;; Test M-m -> ^m -> RET
(should (string= "RET" (key-description (vector (ergoemacs-translate--event-mods (elt (read-kbd-macro "M-m" t) 0) :ctl-to-alt)))))))
(ert-deftest ergoemacs-test-table-insert ()
"Tests that table can insert without hanging emacs."
:tags '(:table)
(save-excursion
(switch-to-buffer (get-buffer-create "*ergoemacs-test*"))
(delete-region (point-min) (point-max))
(table-insert 1 2)
(execute-kbd-macro (kbd "abc <tab> abc <tab>"))
(should (string= (buffer-string) "+-----+
|abc |
+-----+
|abc |
+-----+
"))
(kill-buffer (current-buffer))))
;; File variables
(ert-deftest ergoemacs-test-mouse-command-list-changes ()
"Part of test for Sub issue described in #351"
(should (equal '(&rest arg) (ergoemacs-command-loop--mouse-command-drop-first '(&rest arg) t)))
(should (equal '(arg) (ergoemacs-command-loop--mouse-command-drop-first '(&rest arg))))
(should (equal 'arg (ergoemacs-command-loop--mouse-command-drop-first '(&rest arg) :rest)))
(should (equal nil (ergoemacs-command-loop--mouse-command-drop-first '(&rest arg) :drop-rest)))
(should (equal nil (ergoemacs-command-loop--mouse-command-drop-first '(&optional arg) t)))
(should (equal nil (ergoemacs-command-loop--mouse-command-drop-first '(&optional arg))))
(should (equal nil (ergoemacs-command-loop--mouse-command-drop-first '(&optional arg) :rest)))
(should (equal nil (ergoemacs-command-loop--mouse-command-drop-first '(&optional arg) :drop-rest)))
(should (equal '(&optional arg2) (ergoemacs-command-loop--mouse-command-drop-first '(&optional arg1 arg2) t)))
(should (equal '(arg2) (ergoemacs-command-loop--mouse-command-drop-first '(&optional arg1 arg2))))
(should (equal nil (ergoemacs-command-loop--mouse-command-drop-first '(&optional arg1 arg2) :rest)))
(should (equal '(arg2) (ergoemacs-command-loop--mouse-command-drop-first '(&optional arg1 arg2) :drop-rest)))
(should (equal '(&rest arg2) (ergoemacs-command-loop--mouse-command-drop-first '(&optional arg1 &rest arg2) t)))
(should (equal '(arg2) (ergoemacs-command-loop--mouse-command-drop-first '(&optional arg1 &rest arg2))))
(should (equal 'arg2 (ergoemacs-command-loop--mouse-command-drop-first '(&optional arg1 &rest arg2) :rest)))
(should (equal nil (ergoemacs-command-loop--mouse-command-drop-first '(&optional arg1 &rest arg2) :drop-rest)))
(should (equal '(&optional arg2 &rest arg3) (ergoemacs-command-loop--mouse-command-drop-first '(&optional arg1 arg2 &rest arg3) t)))
(should (equal '(arg2 arg3) (ergoemacs-command-loop--mouse-command-drop-first '(&optional arg1 arg2 &rest arg3))))
(should (equal 'arg3 (ergoemacs-command-loop--mouse-command-drop-first '(&optional arg1 arg2 &rest arg3) :rest)))
(should (equal '(arg2) (ergoemacs-command-loop--mouse-command-drop-first '(&optional arg1 arg2 &rest arg3) :drop-rest))))
;;; minibuffer tests...
;;; Related to: http://emacs.stackexchange.com/questions/10393/how-can-i-answer-a-minibuffer-prompt-from-elisp
(defmacro ergoemacs-minibuffer-key-bindings (minibuffer-call &rest keys)
"Setup minibuffer with MINIBUFFER-CALL, and lookep KEYS."
`(catch 'found-key
(minibuffer-with-setup-hook
(lambda ()
(run-with-timer
0.05 nil
(lambda()
(throw 'found-key (mapcar (lambda(key) (if (consp key)
(key-binding (eval key t))
(key-binding key)))
',keys)))))
,minibuffer-call)
nil))
(provide 'ergoemacs-test)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; ergoemacs-test.el ends here
;; Local Variables:
;; coding: utf-8-emacs
;; End: