aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/test/kotlin/renderers
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/base/src/test/kotlin/renderers')
-rw-r--r--plugins/base/src/test/kotlin/renderers/html/FormattingUtilsTest.kt82
-rw-r--r--plugins/base/src/test/kotlin/renderers/html/TextStylesTest.kt17
2 files changed, 95 insertions, 4 deletions
diff --git a/plugins/base/src/test/kotlin/renderers/html/FormattingUtilsTest.kt b/plugins/base/src/test/kotlin/renderers/html/FormattingUtilsTest.kt
new file mode 100644
index 00000000..c77a78fb
--- /dev/null
+++ b/plugins/base/src/test/kotlin/renderers/html/FormattingUtilsTest.kt
@@ -0,0 +1,82 @@
+package renderers.html
+
+import junit.framework.Assert.assertEquals
+import kotlinx.html.body
+import kotlinx.html.html
+import kotlinx.html.stream.createHTML
+import org.jetbrains.dokka.base.renderers.html.buildBreakableText
+import org.junit.jupiter.api.Test
+
+class FormattingUtilsTest {
+ @Test
+ fun `should build breakable text`(){
+ val testedText = "kotlinx.collections.immutable"
+ val expectedHtml = """
+ <html>
+ <body><span>kotlinx.</span><wbr></wbr><span>collections.</span><wbr></wbr><span>immutable</span></body>
+ </html>
+ """.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 = """
+ <html>
+ <body><span><span>Package</span></span> <span>org.</span><wbr></wbr><span>jetbrains.</span><wbr></wbr><span>dokka.</span><wbr></wbr><span>it.</span><wbr></wbr><span>moduleC</span></body>
+ </html>
+ """.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 = """
+ <html>
+ <body><span>[Common]kotlinx.</span><wbr></wbr><span>collections.</span><wbr></wbr><span>immutable</span></body>
+ </html>
+ """.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 = """
+ <html>
+ <body><span>Dokkkkkkka</span><wbr></wbr><span>Is</span><wbr></wbr><span>The</span><wbr></wbr><span><span>Best</span></span></body>
+ </html>
+ """.trimIndent()
+
+ val html = createHTML(prettyPrint = true).html {
+ body {
+ buildBreakableText(testedText)
+ }
+ }
+
+ assertEquals(expectedHtml.trim(), html.trim())
+ }
+} \ No newline at end of file
diff --git a/plugins/base/src/test/kotlin/renderers/html/TextStylesTest.kt b/plugins/base/src/test/kotlin/renderers/html/TextStylesTest.kt
index 3c38e68c..d65a4f6e 100644
--- a/plugins/base/src/test/kotlin/renderers/html/TextStylesTest.kt
+++ b/plugins/base/src/test/kotlin/renderers/html/TextStylesTest.kt
@@ -2,14 +2,13 @@ package renderers.html
import org.jetbrains.dokka.base.renderers.html.HtmlRenderer
import org.jetbrains.dokka.pages.TextStyle
+import org.jetbrains.dokka.pages.TokenStyle
import org.jsoup.Jsoup
import org.jsoup.nodes.Element
import org.junit.jupiter.api.Test
import renderers.testPage
-import utils.B
-import utils.I
-import utils.STRIKE
-import utils.match
+import utils.*
+import kotlin.test.assertEquals
class TextStylesTest : HtmlRenderingOnlyTestBase() {
@Test
@@ -40,6 +39,16 @@ class TextStylesTest : HtmlRenderingOnlyTestBase() {
}
@Test
+ fun `should include token styles`(){
+ val page = testPage {
+ text("keyword", styles = setOf(TokenStyle.Keyword))
+ }
+ HtmlRenderer(context).render(page)
+ renderedContent.match(Span("keyword"))
+ assertEquals(renderedContent.children().last().attr("class"), "token keyword")
+ }
+
+ @Test
fun `should include multiple styles at one`(){
val page = testPage {
text(