“规格”如何? BDD 框架适合 Scala 工作吗?
我刚刚开始使用 Scala,我想知道哪种语言功能允许您执行此操作:
"PersistentQueue" should {
"add and remove one item" in {
withTempFolder {
val q = new PersistentQueue(folderName, "work", Config.fromMap(Map.empty))
q.setup
q.length mustEqual 0
q.totalItems mustEqual 0
q.bytes mustEqual 0
q.journalSize mustEqual 0
q.add("hello kitty".getBytes)
q.length mustEqual 1
q.totalItems mustEqual 1
q.bytes mustEqual 11
q.journalSize mustEqual 32
new String(q.remove.get.data) mustEqual "hello kitty"
q.length mustEqual 0
q.totalItems mustEqual 1
q.bytes mustEqual 0
q.journalSize mustEqual 33
q.close
dumpJournal("work") mustEqual "add(11:0:hello kitty), remove"
}
}
}
来自 Kestrel 的单元测试。
这里发生了什么? “PersistentQueue”应该
是否意味着 Scala 字符串类已使用“应该”方法进行了扩展,还是这里发生了其他情况? 我快速浏览了 Scala 文档,但看不到此代码示例使用了哪些语言功能。
I'm just getting started with Scala, and I'm wondering which language feature allows you to do this:
"PersistentQueue" should {
"add and remove one item" in {
withTempFolder {
val q = new PersistentQueue(folderName, "work", Config.fromMap(Map.empty))
q.setup
q.length mustEqual 0
q.totalItems mustEqual 0
q.bytes mustEqual 0
q.journalSize mustEqual 0
q.add("hello kitty".getBytes)
q.length mustEqual 1
q.totalItems mustEqual 1
q.bytes mustEqual 11
q.journalSize mustEqual 32
new String(q.remove.get.data) mustEqual "hello kitty"
q.length mustEqual 0
q.totalItems mustEqual 1
q.bytes mustEqual 0
q.journalSize mustEqual 33
q.close
dumpJournal("work") mustEqual "add(11:0:hello kitty), remove"
}
}
}
That's from the unit tests for Kestrel.
What's going on here? Does "PersistentQueue" should
mean that the Scala string class has been extended with a "should" method, or is something else happening here? I had a quick look through the Scala documentation but couldn't see which language features are being used for this code sample.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对我来说,它看起来像是隐式方法被添加到 String 类中。 这篇文章有一个演示。
It looks like implicit methods being added to the String class to me. This post has a demonstration.