加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Scala的“规范”BDD框架如何工作?

发布时间:2020-12-16 19:17:24 所属栏目:安全 来源:网络整理
导读:我刚开始使用 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.totalI
我刚开始使用 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"
    }
  }
}

这是从unit tests for Kestrel.

这里发生了什么? “PersistentQueue”是否应该意味着Scala字符串类已经使用“should”方法扩展,或者是否在此处发生了其他事情?我快速浏览了Scala文档,但无法查看此代码示例使用的语言功能.

解决方法

它看起来像是向我添加到String类的隐式方法. This post有一个示范.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读