mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-08 14:35:52 +01:00
Add testcase.
This commit is contained in:
@@ -18,4 +18,21 @@ class StringUtilSpec extends Specification {
|
||||
}
|
||||
}
|
||||
|
||||
"escapeHtml" should {
|
||||
"escape &, <, > and \"" in {
|
||||
StringUtil.escapeHtml("<a href=\"/test\">a & b</a>") mustEqual "<a href="/test">a & b</a>"
|
||||
}
|
||||
}
|
||||
|
||||
"md5" should {
|
||||
"generate MD5 hash" in {
|
||||
StringUtil.md5("abc") mustEqual "900150983cd24fb0d6963f7d28e17f72"
|
||||
}
|
||||
}
|
||||
|
||||
"sha1" should {
|
||||
"generate SHA1 hash" in {
|
||||
StringUtil.sha1("abc") mustEqual "a9993e364706816aba3e25717850c26c9cd0d89d"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
34
src/test/scala/util/ValidationsSpec.scala
Normal file
34
src/test/scala/util/ValidationsSpec.scala
Normal 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"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user