branch: elpa/with-simulated-input
commit c5b3f7ac702e7b8a11382b0a1243b0c458a9bbb0
Author: Ryan C. Thompson <[email protected]>
Commit: Ryan C. Thompson <[email protected]>
Add tests for nil input
---
tests/test-with-simulated-input.el | 46 ++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/tests/test-with-simulated-input.el
b/tests/test-with-simulated-input.el
index b3a9655bb1..fc999af8e7 100644
--- a/tests/test-with-simulated-input.el
+++ b/tests/test-with-simulated-input.el
@@ -184,6 +184,52 @@
(read-string "Enter a string: "))
:to-throw))
+ (it "should throw an error if the input is empty and BODY reads input"
+ (expect
+ (with-simulated-input nil
+ (read-string "Enter a string: "))
+ :to-throw 'error '("Reached end of simulated input while evaluating
body"))
+ (expect
+ (with-simulated-input '()
+ (read-string "Enter a string: "))
+ :to-throw 'error '("Reached end of simulated input while evaluating
body"))
+ (expect
+ (with-simulated-input ()
+ (read-string "Enter a string: "))
+ :to-throw 'error '("Reached end of simulated input while evaluating
body"))
+ (expect
+ (with-simulated-input '(nil)
+ (read-string "Enter a string: "))
+ :to-throw 'error '("Reached end of simulated input while evaluating
body"))
+ (let ((my-input nil))
+ (expect
+ (with-simulated-input my-input
+ (read-string "Enter a string: "))
+ :to-throw 'error '("Reached end of simulated input while evaluating
body"))))
+
+ (it "should not throw an error if the input is empty unless BODY reads input"
+ (expect
+ (with-simulated-input nil
+ (+ 1 2))
+ :not :to-throw)
+ (expect
+ (with-simulated-input '()
+ (+ 1 2))
+ :not :to-throw)
+ (expect
+ (with-simulated-input ()
+ (+ 1 2))
+ :not :to-throw)
+ (expect
+ (with-simulated-input '(nil)
+ (+ 1 2))
+ :not :to-throw)
+ (let ((my-input nil))
+ (expect
+ (with-simulated-input my-input
+ (+ 1 2))
+ :not :to-throw)))
+
(it "should discard any extra input after BODY has completed"
(expect
(with-simulated-input