Wil*_*lQu 5 symbols scala scalatest
在 scalatest 中,您\xe2\x80\x99应该能够使用如下符号测试布尔属性:
\niter shouldBe 'traversableAgain\nRun Code Online (Sandbox Code Playgroud)\n但这个表示法在最新版本的 scala 中已被弃用,所以现在你\xe2\x80\x99应该写:
\niter shouldBe Symbol("traversableAgain")\nRun Code Online (Sandbox Code Playgroud)\n这有点难看。还有更好的选择吗?
\n考虑BePropertyMatcher哪个提供类型安全谓词匹配语法
iter should be (traversableAgain)
Run Code Online (Sandbox Code Playgroud)
例如
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.{BePropertyMatchResult, BePropertyMatcher}
import org.scalatest.matchers.should.Matchers
trait CustomMatchers {
val traversableAgain = new BePropertyMatcher[Iterator[_]] {
def apply(left: Iterator[_]): BePropertyMatchResult =
BePropertyMatchResult(left.isTraversableAgain, "isTraversableAgain")
}
}
class BePropertyMatcherExampleSpec extends AnyFlatSpec with Matchers with CustomMatchers {
"BePropertyMatcher" should "provide type-safe checking of predicates" in {
Iterator(42, 11) should be (traversableAgain)
}
}
Run Code Online (Sandbox Code Playgroud)
还有一个相关问题Replacement for using Symbols as property matchers for 2.13+ #1679
| 归档时间: |
|
| 查看次数: |
390 次 |
| 最近记录: |