如何创建从字符串而不是文件或 url 读取的输入流
我想将 *in* 绑定到从字符串而不是“真实”输入流读取的流。我该怎么做?
I want to bind *in*
to stream that's reading from a string instead of the "real" input stream. How do I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看
with-in-str
:http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/with-in-str
ClojureDocs 有一个使用示例:
Check out
with-in-str
:http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/with-in-str
ClojureDocs has an example of its use:
这是我最终所做的示例代码。这个想法是一个简单的服务器读取/打印循环函数,它接受输入和输出流。我的问题是如何为这样的函数生成测试流,我认为字符串函数就可以了。相反,这就是我所需要的:
Here's sample code for what I ended up doing. The idea is a simple server read/print loop function which takes an in and out stream. My issue was how to generate testing streams for such a function, and I thought a string function would do. Instead this is what I needed: