2015-06-09 10 views

Odpowiedz

9

Okazało się, że istnieje pewna normalizacja na wielkość liter ma znaczenie porównań w 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) 

stworzyłem następujące Normalizer

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" 
    } 

Test jest teraz

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) 
+0

dla multi-line ciągi, możesz użyć '' 'def znormalizowany (s: String): String = s.replaceAll (" (? s) \\ s + "," ") .trim''' – botkop

Powiązane problemy