因此,在开始我不得不ScalaTest自己的匹配,使用word不
def parseB(string : String)(implicit context : Context) : Float = parseAll(gexp, string).get.eval(context).left.get
,然后在测试
implicit var context = Context()
parseB("False") should be(false)
parseB("False") should not be(true)
然后我写了一个自定义的匹配
case class ReflectBooleanMatcher(value : Boolean)(implicit context : Context) extends Matcher[String] with ExpressionParser{
def parseB(string : String) : Boolean = parseAll(gexp, string).get.eval(context).right.get
def apply (string : String) : MatchResult =
MatchResult(parseB(string) == value, "", "")
}
所以我测试转向
"False" should reflectBoolean(false)
但
"False" should not reflectBoolean(true)
当然Breaks-,我从来没有说过它可以匹配负。那我怎么说呢?
如果你测试它,你能确认它在你的机器上工作吗? –