mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-10 07:25:50 +01:00
Migrating testcase to ScalaTest
This commit is contained in:
@@ -1,59 +1,59 @@
|
||||
package gitbucket.core.view
|
||||
|
||||
import org.specs2.mutable._
|
||||
import org.scalatest.FunSpec
|
||||
|
||||
class HelpersSpec extends Specification {
|
||||
class HelpersSpec extends FunSpec {
|
||||
|
||||
import helpers._
|
||||
|
||||
"detect and render links" should {
|
||||
describe("detect and render links") {
|
||||
|
||||
"pass identical string when no link is present" in {
|
||||
it("should pass identical string when no link is present") {
|
||||
val before = "Description"
|
||||
val after = detectAndRenderLinks(before).toString()
|
||||
after mustEqual before
|
||||
assert(after == before)
|
||||
}
|
||||
|
||||
"convert a single link" in {
|
||||
it("should convert a single link") {
|
||||
val before = "http://example.com"
|
||||
val after = detectAndRenderLinks(before).toString()
|
||||
after mustEqual """<a href="http://example.com">http://example.com</a>"""
|
||||
assert(after == """<a href="http://example.com">http://example.com</a>""")
|
||||
}
|
||||
|
||||
"convert a single link within trailing text" in {
|
||||
it("should convert a single link within trailing text") {
|
||||
val before = "Example Project. http://example.com"
|
||||
val after = detectAndRenderLinks(before).toString()
|
||||
after mustEqual """Example Project. <a href="http://example.com">http://example.com</a>"""
|
||||
assert(after == """Example Project. <a href="http://example.com">http://example.com</a>""")
|
||||
}
|
||||
|
||||
"convert a mulitple links within text" in {
|
||||
it("should convert a mulitple links within text") {
|
||||
val before = "Example Project. http://example.com. (See also https://github.com/)"
|
||||
val after = detectAndRenderLinks(before).toString()
|
||||
after mustEqual """Example Project. <a href="http://example.com">http://example.com</a>. (See also <a href="https://github.com/">https://github.com/</a>)"""
|
||||
assert(after == """Example Project. <a href="http://example.com">http://example.com</a>. (See also <a href="https://github.com/">https://github.com/</a>)""")
|
||||
}
|
||||
|
||||
"properly escape html metacharacters" in {
|
||||
it("should properly escape html metacharacters") {
|
||||
val before = "<>&"
|
||||
val after = detectAndRenderLinks(before).toString()
|
||||
after mustEqual """<>&"""
|
||||
assert(after == """<>&""")
|
||||
}
|
||||
|
||||
"escape html metacharacters adjacent to a link" in {
|
||||
it("should escape html metacharacters adjacent to a link") {
|
||||
val before = "<http://example.com>"
|
||||
val after = detectAndRenderLinks(before).toString()
|
||||
after mustEqual """<<a href="http://example.com">http://example.com</a>>"""
|
||||
assert(after == """<<a href="http://example.com">http://example.com</a>>""")
|
||||
}
|
||||
|
||||
"stop link recognition at a metacharacter" in {
|
||||
it("should stop link recognition at a metacharacter") {
|
||||
val before = "http://exa<mple.com"
|
||||
val after = detectAndRenderLinks(before).toString()
|
||||
after mustEqual """<a href="http://exa">http://exa</a><mple.com"""
|
||||
assert(after == """<a href="http://exa">http://exa</a><mple.com""")
|
||||
}
|
||||
|
||||
"make sure there are no double quotes in the href attribute" in {
|
||||
it("should make sure there are no double quotes in the href attribute") {
|
||||
val before = "http://exa\"mple.com"
|
||||
val after = detectAndRenderLinks(before).toString()
|
||||
after mustEqual """<a href="http://exa"mple.com">http://exa"mple.com</a>"""
|
||||
assert(after == """<a href="http://exa"mple.com">http://exa"mple.com</a>""")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,92 +1,92 @@
|
||||
package gitbucket.core.view
|
||||
|
||||
import org.specs2.mutable._
|
||||
import org.scalatest.FunSpec
|
||||
|
||||
class MarkdownSpec extends Specification {
|
||||
class MarkdownSpec extends FunSpec {
|
||||
|
||||
import Markdown._
|
||||
|
||||
"generateAnchorName" should {
|
||||
"convert whitespace characters to hyphens" in {
|
||||
describe("generateAnchorName") {
|
||||
it("should convert whitespace characters to hyphens") {
|
||||
val before = "foo bar baz"
|
||||
val after = generateAnchorName(before)
|
||||
after mustEqual "foo-bar-baz"
|
||||
assert(after == "foo-bar-baz")
|
||||
}
|
||||
|
||||
"normalize characters with diacritics" in {
|
||||
it("should normalize characters with diacritics") {
|
||||
val before = "Dónde estará mi vida"
|
||||
val after = generateAnchorName(before)
|
||||
after mustEqual "do%cc%81nde-estara%cc%81-mi-vida"
|
||||
assert(after == "do%cc%81nde-estara%cc%81-mi-vida")
|
||||
}
|
||||
|
||||
"omit special characters" in {
|
||||
it("should omit special characters") {
|
||||
val before = "foo!bar@baz>9000"
|
||||
val after = generateAnchorName(before)
|
||||
after mustEqual "foo%21bar%40baz%3e9000"
|
||||
assert(after == "foo%21bar%40baz%3e9000")
|
||||
}
|
||||
}
|
||||
|
||||
"escapeTaskList" should {
|
||||
"convert '- [ ] ' to '* task: :'" in {
|
||||
describe("escapeTaskList") {
|
||||
it("should convert '- [ ] ' to '* task: :'") {
|
||||
val before = "- [ ] aaaa"
|
||||
val after = escapeTaskList(before)
|
||||
after mustEqual "* task: : aaaa"
|
||||
assert(after == "* task: : aaaa")
|
||||
}
|
||||
|
||||
"convert ' - [ ] ' to ' * task: :'" in {
|
||||
it("should convert ' - [ ] ' to ' * task: :'") {
|
||||
val before = " - [ ] aaaa"
|
||||
val after = escapeTaskList(before)
|
||||
after mustEqual " * task: : aaaa"
|
||||
assert(after == " * task: : aaaa")
|
||||
}
|
||||
|
||||
"convert only first '- [ ] '" in {
|
||||
it("should convert only first '- [ ] '") {
|
||||
val before = " - [ ] aaaa - [ ] bbb"
|
||||
val after = escapeTaskList(before)
|
||||
after mustEqual " * task: : aaaa - [ ] bbb"
|
||||
assert(after == " * task: : aaaa - [ ] bbb")
|
||||
}
|
||||
|
||||
"convert '- [x] ' to '* task:x:'" in {
|
||||
it("should convert '- [x] ' to '* task:x:'") {
|
||||
val before = " - [x] aaaa"
|
||||
val after = escapeTaskList(before)
|
||||
after mustEqual " * task:x: aaaa"
|
||||
assert(after == " * task:x: aaaa")
|
||||
}
|
||||
|
||||
"convert multi lines" in {
|
||||
it("should convert multi lines") {
|
||||
val before = """
|
||||
tasks
|
||||
- [x] aaaa
|
||||
- [ ] bbb
|
||||
"""
|
||||
val after = escapeTaskList(before)
|
||||
after mustEqual """
|
||||
assert(after == """
|
||||
tasks
|
||||
* task:x: aaaa
|
||||
* task: : bbb
|
||||
"""
|
||||
""")
|
||||
}
|
||||
|
||||
"no convert if inserted before '- [ ] '" in {
|
||||
it("should not convert if inserted before '- [ ] '") {
|
||||
val before = " a - [ ] aaaa"
|
||||
val after = escapeTaskList(before)
|
||||
after mustEqual " a - [ ] aaaa"
|
||||
assert(after == " a - [ ] aaaa")
|
||||
}
|
||||
|
||||
"no convert '- [] '" in {
|
||||
it("should not convert '- [] '") {
|
||||
val before = " - [] aaaa"
|
||||
val after = escapeTaskList(before)
|
||||
after mustEqual " - [] aaaa"
|
||||
assert(after == " - [] aaaa")
|
||||
}
|
||||
|
||||
"no convert '- [ ]a'" in {
|
||||
it("should not convert '- [ ]a'") {
|
||||
val before = " - [ ]a aaaa"
|
||||
val after = escapeTaskList(before)
|
||||
after mustEqual " - [ ]a aaaa"
|
||||
assert(after == " - [ ]a aaaa")
|
||||
}
|
||||
|
||||
"no convert '-[ ] '" in {
|
||||
it("should not convert '-[ ] '") {
|
||||
val before = " -[ ] aaaa"
|
||||
val after = escapeTaskList(before)
|
||||
after mustEqual " -[ ] aaaa"
|
||||
assert(after == " -[ ] aaaa")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user