ido-ubiquitous-test.el 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. ;;; ido-ubiquitous-test.el --- -*- lexical-binding: t -*-
  2. ;; Copyright (C) 2015 Ryan C. Thompson
  3. ;; Filename: ido-ubiquitous-test.el
  4. ;; Author: Ryan C. Thompson
  5. ;; Created: Tue Oct 6 20:52:45 2015 (-0700)
  6. ;; This file is NOT part of GNU Emacs.
  7. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8. ;;
  9. ;; This program 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 (at
  12. ;; your option) any later version.
  13. ;;
  14. ;; This program is distributed in the hope that it will be useful, but
  15. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. ;; 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. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  23. ;;
  24. ;;; Code:
  25. (require 'ido-completing-read+)
  26. (require 'ido-ubiquitous)
  27. (require 'ert)
  28. (require 'cl-lib)
  29. ;; This is a series of macros to facilitate the testing of completion
  30. ;; non-interactively by simulating input.
  31. (defmacro keyboard-quit-to-error (&rest body)
  32. "Evaluate BODY but signal an error on `keyboard-quit'."
  33. `(condition-case nil
  34. (progn ,@body)
  35. (quit
  36. (error "Caught `keyboard-quit'"))))
  37. (defmacro with-simulated-input (keys &rest body)
  38. "Eval body with KEYS as simulated input.
  39. This macro is intended for testing normally interactive functions
  40. by simulating input. If BODY tries to read more input events than
  41. KEYS provides, `keyboard-quit' is invoked (by means of appending
  42. multple C-g keys to KEYS). This is to ensure that BODY will never
  43. block waiting for input, since this macro is intended for
  44. noninteractive use. As such, BODY should not invoke
  45. `keyboard-quit' under normal operation, and KEYS should not
  46. include C-g, or this macro will interpret it as reading past the
  47. end of input."
  48. ;; It would be better to detect end-of-input by overriding
  49. ;; `read-event' to throw an error, since theoretically C-g could be
  50. ;; rebound to something other than `keyboard-quit'. But apparently
  51. ;; some functions read input directly in C code, and redefining
  52. ;; `read-event' has no effect on those. So the suboptimal solution
  53. ;; is to rely on C-g.
  54. (declare (indent 1))
  55. `(let* ((key-sequence (listify-key-sequence (kbd ,keys)))
  56. (C-g-key-sequence
  57. (listify-key-sequence
  58. ;; We *really* want to trigger `keyboard-quit' if we reach
  59. ;; the end of the input.
  60. (kbd "C-g C-g C-g C-g C-g C-g C-g")))
  61. (unread-command-events
  62. (append key-sequence C-g-key-sequence)))
  63. (when (member (car C-g-key-sequence) key-sequence)
  64. (error "KEYS must not include C-g"))
  65. (condition-case nil
  66. (progn ,@body)
  67. (quit
  68. (error "Reached end of simulated input while evaluating body")))))
  69. (defmacro with-mode (mode arg &rest body)
  70. "Eval (MODE ARG), then body, then restore previous status of MODE.
  71. This will only work on modes that respect the normal conventions
  72. for activation and deactivation."
  73. (declare (indent 2))
  74. `(let* ((orig-status ,mode)
  75. (restore-arg (if orig-status 1 0)))
  76. (unwind-protect
  77. (progn
  78. (,mode ,arg)
  79. ,@body)
  80. (message "Restoring mode %s to %s" ',mode restore-arg)
  81. (,mode restore-arg))))
  82. (defmacro with-ido-ubiquitous-standard-env (&rest body)
  83. "Execute BODY with standard ido-ubiquitous settings.\n\nAll ido-ubiquitous and ido-cr+ options will be let-bound to their\ndefault values, and `ido-ubiquitous-mode' will be enabled."
  84. (declare (indent 0))
  85. (let*
  86. ((ido-ubiquitous-options
  87. '(ido-ubiquitous-allow-on-functional-collection
  88. ido-ubiquitous-command-overrides
  89. ido-ubiquitous-debug-mode
  90. ido-ubiquitous-default-state
  91. ido-ubiquitous-function-overrides
  92. ido-cr+-fallback-function
  93. ido-cr+-max-items
  94. ido-cr+-replace-completely
  95. ido-confirm-unique-completion))
  96. (idu-bindings
  97. (cl-loop for var in ido-ubiquitous-options collect
  98. (list var
  99. (list 'quote
  100. (eval (car (get var 'standard-value))))))))
  101. `(with-mode ido-ubiquitous-mode 1
  102. (let ,idu-bindings ,@body))))
  103. (defmacro collection-as-function (collection)
  104. "Return a function equivalent to COLLECTION.
  105. The returned function will work equivalently to COLLECTION when
  106. passed to `all-completions' and `try-completion'."
  107. `(completion-table-dynamic (lambda (string) (all-completions string ,collection))))
  108. (cl-defmacro should-with-tag (form &key tag)
  109. "Equivalent to `(should FORM)' but with a TAG on the output.
  110. This is useful if the same `should' form will be called multiple
  111. times in different contexts. Each test can pass a different tag
  112. so it's clear in the ERT output which context is causing the
  113. failure.
  114. Note that although this is a macro, the TAG argument is evaluated normally."
  115. `(let ((tagvalue ,tag))
  116. (condition-case err
  117. (should ,form)
  118. (ert-test-failed
  119. (message "Error symbol: %S" (car err))
  120. (message "Error data: %S" (cdr err))
  121. (when tagvalue
  122. (setf (cadr err) (append (cadr err) (list :tag tagvalue))))
  123. (message "New error data: %S" (cdr err))
  124. (signal (car err) (cdr err))))))
  125. (defun plist-delete (plist property)
  126. "Delete PROPERTY from PLIST.
  127. This is in contrast to merely setting it to 0."
  128. (let (p)
  129. (while plist
  130. (if (not (eq property (car plist)))
  131. (setq p (plist-put p (car plist) (nth 1 plist))))
  132. (setq plist (cddr plist)))
  133. p))
  134. (cl-defmacro should-error-with-tag (form &rest other-keys &key tag &allow-other-keys)
  135. "Equivalent to `(should FORM)' but with a TAG on the output.
  136. See `should-with-tag'.
  137. Note that although this is a macro, the TAG argument is evaluated normally."
  138. (setq other-keys (plist-delete other-keys :tag))
  139. `(let ((tagvalue ,tag))
  140. (condition-case err
  141. (should-error ,form ,@other-keys)
  142. (ert-test-failed
  143. (message "Error symbol: %S" (car err))
  144. (message "Error data: %S" (cdr err))
  145. (when tagvalue
  146. (setf (cadr err) (append (cadr err) (list :tag tagvalue))))
  147. (message "New error data: %S" (cdr err))
  148. (signal (car err) (cdr err))))))
  149. (defun test-ido-ubiquitous-expected-mode (override &optional tag)
  150. "Test whether observed ido-ubiquitous behavior matches OVERRIDE."
  151. (declare (indent 1))
  152. (if (eq override 'disable)
  153. (progn
  154. (should-with-tag
  155. ;; Verify that we get standard completion
  156. (string=
  157. "g"
  158. (with-simulated-input "g RET"
  159. (completing-read "Prompt: " '("blue" "yellow" "green"))))
  160. :tag tag)
  161. (should-with-tag
  162. (string=
  163. "green"
  164. (with-simulated-input "g RET"
  165. (completing-read "Prompt: " '("blue" "yellow" "green") nil t)))
  166. :tag tag)
  167. ;; Standard completion should refuse to finish with incomplete
  168. ;; input if match is required
  169. (should-error-with-tag
  170. (with-simulated-input "b RET"
  171. (completing-read "Prompt: " '("brown" "blue" "yellow" "green") nil t))
  172. :type 'error
  173. :tag tag))
  174. ;; Common tests whenever ido-ubiquitous is enabled in any way
  175. (should-with-tag
  176. ;; Verify that ido completion is active
  177. (string=
  178. "green"
  179. (with-simulated-input "g RET"
  180. (completing-read "Prompt: " '("blue" "yellow" "green"))))
  181. :tag tag)
  182. ;; Verify that C-j is working correctly
  183. (should-with-tag
  184. (string=
  185. "g"
  186. (with-simulated-input "g C-j"
  187. (completing-read "Prompt: " '("blue" "yellow" "green"))))
  188. :tag tag)
  189. (let ((collection '("brown" "blue" "yellow" "green")))
  190. (should-with-tag
  191. (member
  192. (with-simulated-input "b RET"
  193. (completing-read "Prompt: " collection))
  194. (all-completions "b" collection))
  195. :tag tag))
  196. (cl-case override
  197. (enable
  198. ;; Test for new style
  199. (should-with-tag
  200. (string=
  201. "blue"
  202. (with-simulated-input "RET"
  203. (completing-read "Prompt: " '("blue" "yellow" "green") nil t)))
  204. :tag tag)
  205. (should-with-tag
  206. (string=
  207. ""
  208. (with-simulated-input "C-j"
  209. (completing-read "Prompt: " '("blue" "yellow" "green") nil t)))
  210. :tag tag))
  211. (enable-old
  212. (should-with-tag
  213. (string=
  214. ""
  215. (with-simulated-input "RET"
  216. (completing-read "Prompt: " '("blue" "yellow" "green") nil t)))
  217. :tag tag)
  218. (should-with-tag
  219. (string=
  220. "blue"
  221. (with-simulated-input "C-j"
  222. (completing-read "Prompt: " '("blue" "yellow" "green") nil t)))
  223. :tag tag)
  224. ;; Verify that doing other stuff reverts RET and C-j to standard
  225. ;; meanings
  226. (should-with-tag
  227. (string=
  228. "blue"
  229. (with-simulated-input "g DEL RET"
  230. (completing-read "Prompt: " '("blue" "yellow" "green") nil t)))
  231. :tag tag)
  232. (should-with-tag
  233. (string=
  234. "blue"
  235. (with-simulated-input "<right> <left> RET"
  236. (completing-read "Prompt: " '("blue" "yellow" "green") nil t)))
  237. :tag tag)
  238. (should-with-tag
  239. (string=
  240. ""
  241. (with-simulated-input "g DEL C-j"
  242. (completing-read "Prompt: " '("blue" "yellow" "green") nil t)))
  243. :tag tag)
  244. (should-with-tag
  245. (string=
  246. ""
  247. (with-simulated-input "<right> <left> C-j"
  248. (completing-read "Prompt: " '("blue" "yellow" "green") nil t)))
  249. :tag tag))
  250. (otherwise (error "Unknown override %S" override)))))
  251. (defvar original-completing-read (symbol-function #'completing-read))
  252. (defun test-ido-ubiquitous-expected-mode-on-functional-collection (override &optional tag)
  253. "Test whether observed ido-ubiquitous behavior on functional collection matches OVERRIDE."
  254. (declare (indent 1))
  255. ;; This just temporarily replaces `completing-read' with a wrapper
  256. ;; that always converts the collection argument to an equivalent
  257. ;; function. That way, any use of `completing-read' will always see
  258. ;; a functional collection.
  259. (cl-letf (((symbol-function 'completing-read)
  260. (lambda (prompt collection &rest args)
  261. (apply original-completing-read prompt
  262. (collection-as-function collection)
  263. args))))
  264. (test-ido-ubiquitous-expected-mode override tag)))
  265. (ert-deftest ido-ubiquitous-test-simple ()
  266. :tags '(ido ido-ubiquitous)
  267. "Test that basic ido-ubiquitous functionality is working."
  268. (with-ido-ubiquitous-standard-env
  269. (ido-ubiquitous-mode 1)
  270. (test-ido-ubiquitous-expected-mode 'enable
  271. :simple-enable)
  272. (ido-ubiquitous-mode 0)
  273. (test-ido-ubiquitous-expected-mode 'disable
  274. :simple-disable)))
  275. (ert-deftest ido-ubiquitous-test-oldstyle ()
  276. :tags '(ido ido-ubiquitous)
  277. "Test whether old-style completion works as expected."
  278. (with-ido-ubiquitous-standard-env
  279. (let ((ido-ubiquitous-default-state 'enable-old))
  280. (test-ido-ubiquitous-expected-mode 'enable-old
  281. :simple-oldstyle))))
  282. (ert-deftest ido-ubiquitous-test-maxitems ()
  283. :tags '(ido ido-ubiquitous)
  284. "Test whether the large-collection fallback works."
  285. (with-ido-ubiquitous-standard-env
  286. (let ((ido-cr+-max-items -1))
  287. (test-ido-ubiquitous-expected-mode 'disable
  288. :maxitems))))
  289. (ert-deftest ido-ubiquitous-test-override ()
  290. :tags '(ido ido-ubiquitous)
  291. "Test whether ido-ubiquitous overrides work."
  292. (with-ido-ubiquitous-standard-env
  293. (ido-ubiquitous-with-override 'enable
  294. (test-ido-ubiquitous-expected-mode 'enable
  295. :override-enable))
  296. (ido-ubiquitous-with-override 'enable-old
  297. (test-ido-ubiquitous-expected-mode 'enable-old
  298. :override-enable-old))
  299. (ido-ubiquitous-with-override 'disable
  300. (test-ido-ubiquitous-expected-mode 'disable
  301. :override-disable))))
  302. (ert-deftest ido-ubiquitous-test-functional-collection ()
  303. :tags '(ido ido-ubiquitous)
  304. "Test whether ido-ubiquitous overrides work when collection is a function."
  305. (with-ido-ubiquitous-standard-env
  306. (test-ido-ubiquitous-expected-mode-on-functional-collection 'disable
  307. :collfunc)
  308. (ido-ubiquitous-with-override 'enable
  309. (test-ido-ubiquitous-expected-mode-on-functional-collection 'enable
  310. :override-enable-collfunc))
  311. (ido-ubiquitous-with-override 'enable-old
  312. (test-ido-ubiquitous-expected-mode-on-functional-collection 'enable-old
  313. :override-enable-old-collfunc))))
  314. (ert-deftest ido-cr+-require-match ()
  315. :tags '(ido ido-cr+)
  316. "Test whether require-match works."
  317. (with-ido-ubiquitous-standard-env
  318. ;; "C-j" should be allowed to return an empty string even if
  319. ;; require-match is non-nil, as long as default is nil
  320. (should
  321. (string=
  322. ""
  323. (with-simulated-input "C-j"
  324. (ido-completing-read+
  325. "Prompt: "
  326. '("bluebird" "blues" "bluegrass" "blueberry" "yellow ""green") nil t))))
  327. ;; "C-j" should NOT be allowed to return an empty string if
  328. ;; require-match and default are both non-nil.
  329. (should-error
  330. (with-simulated-input "C-j"
  331. (ido-completing-read+
  332. "Prompt: "
  333. '("bluebird" "blues" "bluegrass" "blueberry" "yellow ""green") nil t nil nil "yellow")))
  334. ;; Multiple presses of C-j won't just select the first match
  335. (should-error
  336. (with-simulated-input "b C-j C-j C-j"
  337. (ido-completing-read+
  338. "Prompt: "
  339. '("bluebird" "blues" "bluegrass" "blueberry" "yellow ""green") nil t)))
  340. ;; First press of C-j should complete unique common prefix after the
  341. ;; first b, but then get stuck on the choice for the second b.
  342. (should-error
  343. (with-simulated-input "b C-j b C-j C-j"
  344. (ido-completing-read+
  345. "Prompt: "
  346. '("bluebird" "blues" "bluegrass" "blueberry" "yellow ""green") nil t)))
  347. ;; This should complete to "blueberry" via 2 rounds of unique common
  348. ;; prefix completion, and then return on the 3rd "C-j"
  349. (should
  350. (string=
  351. "blueberry"
  352. (with-simulated-input "b C-j b C-j e C-j C-j"
  353. (ido-completing-read+
  354. "Prompt: "
  355. '("bluebird" "blues" "bluegrass" "blueberry" "yellow ""green") nil t))))
  356. ;; The "C-j" should complete to "bluegrass" and return, because
  357. ;; `ido-confirm-unique-completion is nil.
  358. (should
  359. (string=
  360. "bluegrass"
  361. (with-simulated-input "b l u e g C-j"
  362. (ido-completing-read+
  363. "Prompt: "
  364. '("bluebird" "blues" "bluegrass" "blueberry" "yellow ""green") nil t))))
  365. (let ((ido-confirm-unique-completion t))
  366. ;; Now the first "C-j" should complete to "bluegrass" but should
  367. ;; not return.
  368. (should-error
  369. (with-simulated-input "b l u e g C-j"
  370. (ido-completing-read+
  371. "Prompt: "
  372. '("bluebird" "blues" "bluegrass" "blueberry" "yellow ""green") nil t)))
  373. ;; The first "C-j" should complete to "bluegrass", and the second
  374. ;; should return.
  375. (should
  376. (string=
  377. "bluegrass"
  378. (with-simulated-input "b l u e g C-j C-j"
  379. (ido-completing-read+
  380. "Prompt: "
  381. '("bluebird" "blues" "bluegrass" "blueberry" "yellow ""green") nil t)))))
  382. ;; Finally, a few tests for the expected wrong behavior without
  383. ;; ido-cr+. If ido.el ever fixes this bug, it will cause this test
  384. ;; to fail as a signal that the workaround can be phased out.
  385. (should
  386. (string=
  387. ""
  388. (with-simulated-input "C-j"
  389. (ido-completing-read
  390. "Prompt: "
  391. '("bluebird" "blues" "bluegrass" "blueberry" "yellow ""green") nil t))))
  392. (should
  393. (string=
  394. "b"
  395. (with-simulated-input "b C-j"
  396. (ido-completing-read
  397. "Prompt: "
  398. '("bluebird" "blues" "bluegrass" "blueberry" "yellow ""green") nil t))))))
  399. ;; Functions to define overrides on for testing
  400. (defun idu-no-override-testfunc ()
  401. (test-ido-ubiquitous-expected-mode 'enable
  402. :func-override-none)
  403. (test-ido-ubiquitous-expected-mode-on-functional-collection 'disable
  404. :func-override-none-collfunc))
  405. (defun idu-enabled-testfunc (&rest args)
  406. (test-ido-ubiquitous-expected-mode 'enable
  407. :func-override-enable)
  408. (test-ido-ubiquitous-expected-mode-on-functional-collection 'enable
  409. :func-override-enable-collfunc))
  410. (defun idu-disabled-testfunc (&rest args)
  411. (test-ido-ubiquitous-expected-mode 'disable
  412. :func-override-disable)
  413. (test-ido-ubiquitous-expected-mode-on-functional-collection 'disable
  414. :func-override-disable-collfunc))
  415. (defun idu-enabled-oldstyle-testfunc (&rest args)
  416. (test-ido-ubiquitous-expected-mode 'enable-old
  417. :func-override-enable-old)
  418. (test-ido-ubiquitous-expected-mode-on-functional-collection 'enable-old
  419. :func-override-enable-old-collfunc))
  420. ;; commands to define overrides on for testing
  421. (defun idu-no-override-testcmd (&rest args)
  422. (interactive
  423. (list
  424. (test-ido-ubiquitous-expected-mode 'enable
  425. :cmd-override-none)
  426. (test-ido-ubiquitous-expected-mode-on-functional-collection 'disable
  427. :cmd-override-none-collfunc)))
  428. (test-ido-ubiquitous-expected-mode 'enable
  429. :cmd-override-none)
  430. (test-ido-ubiquitous-expected-mode-on-functional-collection 'disable
  431. :cmd-override-non-collfunc))
  432. (defun idu-enabled-testcmd (&rest args)
  433. (interactive
  434. (list
  435. (test-ido-ubiquitous-expected-mode 'enable
  436. :cmd-override-enable)
  437. (test-ido-ubiquitous-expected-mode-on-functional-collection 'enable
  438. :cmd-override-enable-collfunc)))
  439. (test-ido-ubiquitous-expected-mode 'enable
  440. :cmd-override-enable)
  441. (test-ido-ubiquitous-expected-mode-on-functional-collection 'enable
  442. :cmd-override-enable-collfunc))
  443. (defun idu-disabled-testcmd (&rest args)
  444. (interactive
  445. (list
  446. (test-ido-ubiquitous-expected-mode 'disable
  447. :cmd-override-disable)
  448. (test-ido-ubiquitous-expected-mode-on-functional-collection 'disable
  449. :cmd-override-disable-collfunc)))
  450. (test-ido-ubiquitous-expected-mode 'disable
  451. :cmd-override-disable)
  452. (test-ido-ubiquitous-expected-mode-on-functional-collection 'disable
  453. :cmd-override-disable-collfunc))
  454. (defun idu-enabled-oldstyle-testcmd (&rest args)
  455. (interactive
  456. (list
  457. (test-ido-ubiquitous-expected-mode 'enable-old
  458. :cmd-override-enable-old)
  459. (test-ido-ubiquitous-expected-mode-on-functional-collection 'enable-old
  460. :cmd-override-enable-old-collfunc)))
  461. (test-ido-ubiquitous-expected-mode 'enable-old
  462. :cmd-override-enable-old)
  463. (test-ido-ubiquitous-expected-mode-on-functional-collection 'enable-old
  464. :cmd-override-enable-old-collfunc))
  465. (ert-deftest ido-ubiquitous-test-command-and-function-overrides ()
  466. :tags '(ido ido-ubiquitous)
  467. "Test whether command- and function-specific overrides work."
  468. (let ((orig-func-overrides ido-ubiquitous-function-overrides)
  469. (orig-cmd-overrides ido-ubiquitous-command-overrides))
  470. (unwind-protect
  471. (with-ido-ubiquitous-standard-env
  472. (customize-set-variable
  473. 'ido-ubiquitous-function-overrides
  474. (append ido-ubiquitous-function-overrides
  475. '((enable exact "idu-enabled-testfunc")
  476. (disable exact "idu-disabled-testfunc")
  477. (enable-old exact "idu-enabled-oldstyle-testfunc"))))
  478. (cl-loop for func in
  479. '(idu-no-override-testfunc
  480. idu-enabled-testfunc
  481. idu-disabled-testfunc
  482. idu-enabled-oldstyle-testfunc)
  483. do (funcall func))
  484. (customize-set-variable
  485. 'ido-ubiquitous-command-overrides
  486. (append ido-ubiquitous-command-overrides
  487. '((enable exact "idu-enabled-testcmd")
  488. (disable exact "idu-disabled-testcmd")
  489. (enable-old exact "idu-enabled-oldstyle-testcmd"))))
  490. (cl-loop for cmd in
  491. '(idu-no-override-testcmd
  492. idu-enabled-testcmd
  493. idu-disabled-testcmd
  494. idu-enabled-oldstyle-testcmd)
  495. do (call-interactively cmd)))
  496. (customize-set-variable 'ido-ubiquitous-function-overrides orig-func-overrides)
  497. (customize-set-variable 'ido-ubiquitous-command-overrides orig-cmd-overrides))))
  498. (ert-deftest ido-ubiquitous-test-fallback ()
  499. :tags '(ido ido-ubiquitous)
  500. "Test whether manually invoking fallback works."
  501. (with-ido-ubiquitous-standard-env
  502. (should
  503. ;; C-b/f not at beginning/end of input should not fall back
  504. (string=
  505. "green"
  506. (with-simulated-input "g C-b C-f RET"
  507. (completing-read "Prompt: " '("blue" "yellow" "green")))))
  508. (should
  509. ;; C-f at end of input should fall back
  510. (string=
  511. "g"
  512. (with-simulated-input "g C-f RET"
  513. (completing-read "Prompt: " '("blue" "yellow" "green")))))
  514. (should
  515. ;; Repeated C-b should not fall back
  516. (string=
  517. "green"
  518. (with-simulated-input "g C-b C-b C-b C-b RET"
  519. (completing-read "Prompt: " '("blue" "yellow" "green")))))
  520. (should
  521. ;; C-b at beginning of line should fall back (if previous action
  522. ;; was not also C-b)
  523. (string=
  524. "g"
  525. (with-simulated-input "g C-b x DEL C-b RET"
  526. (completing-read "Prompt: " '("blue" "yellow" "green")))))))
  527. (ert-deftest ido-ubiquitous-dot-prefix-empty-string ()
  528. :tags '(ido ido-ubiquitous)
  529. "Test whether ido-ubiquitous successfully works around a bug in ido.
  530. See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=26997 for more
  531. information on this bug."
  532. (with-ido-ubiquitous-standard-env
  533. (let ((ido-enable-dot-prefix t))
  534. (should
  535. (string=
  536. ""
  537. (with-simulated-input "RET"
  538. (completing-read "Pick: " '("" "aaa" "aab" "aac")))))
  539. (should
  540. (string=
  541. "aab"
  542. (with-simulated-input "a a b RET"
  543. (completing-read "Pick: " '("" "aaa" "aab" "aac"))))))))
  544. (defun ido-ubiquitous-run-all-tests ()
  545. (interactive)
  546. (ert "^ido-\\(ubiquitous\\|cr\\+\\)-"))
  547. (provide 'ido-ubiquitous-test)
  548. ;;; ido-ubiquitous-test.el ends here