blob: 0d6a18cc9c8afe16c9b37e4d40253b928527bfd7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
/*
* Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package renderers.gfm
import org.jetbrains.dokka.gfm.renderer.CommonmarkRenderer
import renderers.testPage
import kotlin.test.Test
import kotlin.test.assertEquals
class CodeWrappingTest : GfmRenderingOnlyTestBase() {
@Test
fun wrappedCodeBlock() {
val page = testPage {
codeBlock {
text("fun myCode(): String")
}
}
val expect = """|//[testPage](test-page.md)
|
|```kotlin
|fun myCode(): String
|```""".trimMargin()
CommonmarkRenderer(context).render(page)
assertEquals(expect, renderedContent)
}
@Test
fun `should preserve original text without escaping`() {
val page = testPage {
codeBlock {
text("<----> **text** & ~~this~~ and \"that\"")
}
}
val expect = """|//[testPage](test-page.md)
|
|```kotlin
|<----> **text** & ~~this~~ and "that"
|```""".trimMargin()
CommonmarkRenderer(context).render(page)
assertEquals(expect, renderedContent)
}
@Test
fun wrappedInlineCode() {
val page = testPage {
text("This function adds the values of ")
codeInline {
text("left")
}
text(" and ")
codeInline {
text("right")
}
text(".\nBoth numbers must be finite, or an exception occurs.\n")
}
val expect = """|//[testPage](test-page.md)
|
|This function adds the values of `left` and `right`.
|Both numbers must be finite, or an exception occurs.""".trimMargin()
CommonmarkRenderer(context).render(page)
assertEquals(expect, renderedContent)
}
@Test
fun `should not add trailing backslash to newline elements for code inline code`() {
val page = testPage {
text("This adds some symbols (")
codeInline {
text("<----> **text** & ~~this~~ and \"that\"")
}
text(") to the test")
}
val expect = """|//[testPage](test-page.md)
|
|This adds some symbols (`<----> **text** & ~~this~~ and "that"`) to the test""".trimMargin()
CommonmarkRenderer(context).render(page)
assertEquals(expect, renderedContent)
}
}
|