mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-08 22:45:51 +01:00
Change package name
This commit is contained in:
56
src/test/scala/gitbucket/core/util/StringUtilSpec.scala
Normal file
56
src/test/scala/gitbucket/core/util/StringUtilSpec.scala
Normal file
@@ -0,0 +1,56 @@
|
||||
package gitbucket.core.util
|
||||
|
||||
import org.specs2.mutable._
|
||||
|
||||
class StringUtilSpec extends Specification {
|
||||
|
||||
"urlDecode" should {
|
||||
"decode encoded string to original string" in {
|
||||
val encoded = StringUtil.urlEncode("あいうえお")
|
||||
StringUtil.urlDecode(encoded) mustEqual "あいうえお"
|
||||
}
|
||||
}
|
||||
|
||||
"splitWords" should {
|
||||
"split string by whitespaces" in {
|
||||
val split = StringUtil.splitWords("aa bb\tcc dd \t ee")
|
||||
split mustEqual Array("aa", "bb", "cc", "dd", "ee")
|
||||
}
|
||||
}
|
||||
|
||||
"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"
|
||||
}
|
||||
}
|
||||
|
||||
"extractIssueId" should {
|
||||
"extract '#xxx' and return extracted id" in {
|
||||
StringUtil.extractIssueId("(refs #123)").toSeq mustEqual Seq("123")
|
||||
}
|
||||
"returns Nil from message which does not contain #xxx" in {
|
||||
StringUtil.extractIssueId("this is test!").toSeq mustEqual Nil
|
||||
}
|
||||
}
|
||||
|
||||
"extractCloseId" should {
|
||||
"extract 'close #xxx' and return extracted id" in {
|
||||
StringUtil.extractCloseId("(close #123)").toSeq mustEqual Seq("123")
|
||||
}
|
||||
"returns Nil from message which does not contain close command" in {
|
||||
StringUtil.extractCloseId("(refs #123)").toSeq mustEqual Nil
|
||||
}
|
||||
}
|
||||
}
|
||||
36
src/test/scala/gitbucket/core/util/ValidationsSpec.scala
Normal file
36
src/test/scala/gitbucket/core/util/ValidationsSpec.scala
Normal file
@@ -0,0 +1,36 @@
|
||||
package gitbucket.core.util
|
||||
|
||||
import org.specs2.mutable._
|
||||
import org.scalatra.i18n.Messages
|
||||
|
||||
class ValidationsSpec extends Specification with Validations {
|
||||
|
||||
"identifier" should {
|
||||
"validate id string " in {
|
||||
identifier.validate("id", "aa_ZZ-00.01", null) mustEqual None
|
||||
identifier.validate("id", "_aaaa", null) mustEqual Some("id starts with invalid character.")
|
||||
identifier.validate("id", "-aaaa", null) mustEqual Some("id starts with invalid character.")
|
||||
identifier.validate("id", "aa_ZZ#01", null) mustEqual Some("id contains invalid character.")
|
||||
}
|
||||
}
|
||||
|
||||
"color" should {
|
||||
"validate color string " in {
|
||||
val messages = Messages()
|
||||
color.validate("color", "#88aaff", messages) mustEqual None
|
||||
color.validate("color", "#gghhii", messages) 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", null)
|
||||
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