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

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

[nongnu] elpa/with-simulated-input 322dc7ed95 008/134: Add some more tes


From: ELPA Syncer
Subject: [nongnu] elpa/with-simulated-input 322dc7ed95 008/134: Add some more tests
Date: Mon, 10 Jan 2022 22:59:59 -0500 (EST)

branch: elpa/with-simulated-input
commit 322dc7ed95f5bc40707ebb1a0f9f8abf552a6e49
Author: Ryan C. Thompson <rct@thompsonclan.org>
Commit: Ryan C. Thompson <rct@thompsonclan.org>

    Add some more tests
---
 test/with-simulated-input-test.el | 51 +++++++++++++++++++++++++++++++++------
 1 file changed, 43 insertions(+), 8 deletions(-)

diff --git a/test/with-simulated-input-test.el 
b/test/with-simulated-input-test.el
index be9d7a22e3..43acc0979e 100644
--- a/test/with-simulated-input-test.el
+++ b/test/with-simulated-input-test.el
@@ -4,26 +4,61 @@
 (require 'ert)
 (require 'cl-lib)
 
-(ert-deftest simulate-input ()
+(ert-deftest read-simulated-input ()
+  :tags '(with-simulated-input)
   "Tests for the basic functionality of the `with-simulated-input' macro."
   ;; Basic string input
   (should
-   (string= "hello"
-            (with-simulated-input "hello RET"
-              (read-string "Enter a string: "))))
+   (string=
+    "hello"
+    (with-simulated-input "hello RET"
+      (read-string "Enter a string: "))))
   ;; Error if RET is not pressed to finish the input
   (should-error
    (with-simulated-input "hello"
      (read-string "Enter a string: ")))
   ;; Can throw an error manually
   (should-error
-   (with-simulated-input "(error SPC \"Manually SPC throwing SPC an SPC 
error\") RET"
+   (with-simulated-input
+       "(error SPC \"Manually SPC throwing SPC an SPC error\") RET"
      (command-execute 'eval-expression)))
   ;; Extra keys should not cause errors
   (should
-   (string= "hello"
-            (with-simulated-input "hello RET M-x eval-expression (error SPC 
\"Manually SPC throwing SPC an SPC error\") RET"
-              (read-string "Enter a string: ")))))
+   (string=
+    "hello"
+    (with-simulated-input
+        "hello RET M-x eval-expression (error SPC \"Manually SPC throwing SPC 
an SPC error\") RET"
+              (read-string "Enter a string: "))))
+  ;; A single input sequence can feed multiple functions
+  (should
+   (equal
+    '("hello" "world")
+    (with-simulated-input "hello RET world RET"
+      (list (read-string "First word: ")
+            (read-string "Second word: "))))))
+
+(ert-deftest complete-with-simulated-input ()
+  :tags '(with-simulated-input)
+  "Tests for `with-simulated-input' with `completing-read'."
+  (let ((collection '("bluebird" "blueberry" "bluebell" "bluegrass" 
"baseball"))
+        (completing-read-function #'completing-read-default))
+    ;; Unambiguous completion
+    (should
+     (string=
+      "bluebird"
+      ;; First TAB completes "blue", 2nd completes "bird"
+      (with-simulated-input "bl TAB bi TAB RET"
+        (completing-read "Choose: " collection))))
+    ;; Ambiguous completion
+    (should
+     (string=
+      "blue"
+      (with-simulated-input "bl TAB C-j"
+        (completing-read "Choose: " collection))))
+    ;; Ambiguous completion with require-match
+    (should-error
+     (with-simulated-input "bl TAB C-j"
+       (completing-read "Choose: " collection nil t)))))
 
 (provide 'with-simulated-input-test)
 



reply via email to

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