“规格”如何? BDD 框架适合 Scala 工作吗?

发布于 2024-07-14 14:39:17 字数 1127 浏览 4 评论 0原文

我刚刚开始使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如果没结果 2024-07-21 14:39:17

对我来说,它看起来像是隐式方法被添加到 String 类中。 这篇文章有一个演示。

It looks like implicit methods being added to the String class to me. This post has a demonstration.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文