我有以下测试
"Matchers" should "ignore whitespace if configured so" in {
" aaa \n \n\r bbb".replaceAll("\\s+", " ") shouldBe "\naaa bbb".replaceAll("\\s+", " ")
}
Run Code Online (Sandbox Code Playgroud)
有一种最神奇的惯用方法吗?
rai*_*tin 11
我发现在http://www.scalatest.org/user_guide/using_matchers中对不区分大小写的比较进行了一些规范化
import org.scalatest.Matchers._
import org.scalactic.Explicitly._
import org.scalactic.StringNormalizations._
"Hi" should equal ("hi") (after being lowerCased)
Run Code Online (Sandbox Code Playgroud)
我创建了以下规范化器
import org.scalactic._
val whiteSpaceNormalised: Uniformity[String] =
new AbstractStringUniformity {
/**Returns the string with all consecutive white spaces reduced to a single space.*/
def normalized(s: String): String = s.replaceAll("\\s+", " ")
override def toString: String = "whiteSpaceNormalised"
}
Run Code Online (Sandbox Code Playgroud)
现在测试了
import org.scalatest.Matchers._
import org.scalactic.Explicitly._
import org.scalactic.StringNormalizations._
" aaa \n \n\r bbb " should equal("\naaa bbb \t")(after being whiteSpaceNormalised)
Run Code Online (Sandbox Code Playgroud)