所以一开始我有
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-当然,我从来没有说过它可以匹配负数。那我怎么说呢?