在scalatest中使用什么来代替符号?
在scalatest中,您应该能够使用如下符号测试布尔属性:在scalatest中使用什么来代替符号?,scala,symbols,scalatest,Scala,Symbols,Scalatest,在scalatest中,您应该能够使用如下符号测试布尔属性: iter shouldBe 'traversableAgain 但在最新版本的scala中,这种符号已经被弃用,因此现在您应该编写: iter shouldBe Symbol("traversableAgain") 这有点难看。有更好的选择吗?考虑提供类型安全谓词匹配语法的方法 iter should be (traversableAgain) 比如说 import org.scalatest.flatspe
iter shouldBe 'traversableAgain
但在最新版本的scala中,这种符号已经被弃用,因此现在您应该编写:
iter shouldBe Symbol("traversableAgain")
这有点难看。有更好的选择吗?考虑提供类型安全谓词匹配语法的方法
iter should be (traversableAgain)
比如说
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)
}
}
还有一个相关的问题