Add testcase.

This commit is contained in:
takezoe
2013-10-05 03:39:46 +09:00
parent 17bc422e7a
commit dd8f440be0
2 changed files with 51 additions and 0 deletions

View File

@@ -18,4 +18,21 @@ class StringUtilSpec extends Specification {
} }
} }
"escapeHtml" should {
"escape &, <, > and \"" in {
StringUtil.escapeHtml("<a href=\"/test\">a & b</a>") mustEqual "&lt;a href=&quot;/test&quot;&gt;a &amp; b&lt;/a&gt;"
}
}
"md5" should {
"generate MD5 hash" in {
StringUtil.md5("abc") mustEqual "900150983cd24fb0d6963f7d28e17f72"
}
}
"sha1" should {
"generate SHA1 hash" in {
StringUtil.sha1("abc") mustEqual "a9993e364706816aba3e25717850c26c9cd0d89d"
}
}
} }

View File

@@ -0,0 +1,34 @@
package util
import org.specs2.mutable._
class ValidationsSpec extends Specification with Validations {
"identifier" should {
"validate id string " in {
identifier.validate("id", "aa_ZZ-01") mustEqual None
identifier.validate("id", "_aaaa") mustEqual Some("id starts with invalid character.")
identifier.validate("id", "-aaaa") mustEqual Some("id starts with invalid character.")
identifier.validate("id", "aa_ZZ#01") mustEqual Some("id contains invalid character.")
}
}
"color" should {
"validate color string " in {
color.validate("color", "#88aaff") mustEqual None
color.validate("color", "#gghhii") mustEqual Some("color must be '#[0-9a-fA-F]{6}'.")
}
}
"date" should {
// "validate date string " in {
// date().validate("date", "2013-10-05", Map[String, String]()) mustEqual Nil
// date().validate("date", "2013-10-5" , Map[String, String]()) mustEqual List(("date", "date must be '\\d{4}-\\d{2}-\\d{2}'."))
// }
"convert date string " in {
val result = date().convert("2013-10-05")
new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(result) mustEqual "2013-10-05 00:00:00"
}
}
}