/*
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package renderers.html
import kotlinx.html.body
import kotlinx.html.html
import kotlinx.html.stream.createHTML
import org.jetbrains.dokka.base.renderers.html.buildBreakableText
import kotlin.test.Test
import kotlin.test.assertEquals
class FormattingUtilsTest {
@Test
fun `should build breakable text`(){
val testedText = "kotlinx.collections.immutable"
val expectedHtml = """
kotlinx.collections.immutable
""".trimIndent()
val html = createHTML(prettyPrint = true).html {
body {
buildBreakableText(testedText)
}
}
assertEquals(expectedHtml.trim(), html.trim())
}
@Test
fun `should build breakable text without empty spans`(){
val testedText = "Package org.jetbrains.dokka.it.moduleC"
val expectedHtml = """
Package org.jetbrains.dokka.it.moduleC
""".trimIndent()
val html = createHTML(prettyPrint = true).html {
body {
buildBreakableText(testedText)
}
}
assertEquals(expectedHtml.trim(), html.trim())
}
@Test
fun `should build breakable text for text with braces`(){
val testedText = "[Common]kotlinx.collections.immutable"
val expectedHtml = """
[Common]kotlinx.collections.immutable
""".trimIndent()
val html = createHTML(prettyPrint = true).html {
body {
buildBreakableText(testedText)
}
}
assertEquals(expectedHtml.trim(), html.trim())
}
@Test
fun `should build breakable text for camel case notation`(){
val testedText = "DokkkkkkkaIsTheBest"
val expectedHtml = """
DokkkkkkkaIsTheBest
""".trimIndent()
val html = createHTML(prettyPrint = true).html {
body {
buildBreakableText(testedText)
}
}
assertEquals(expectedHtml.trim(), html.trim())
}
}