aboutsummaryrefslogtreecommitdiff
path: root/plugins/gfm/src
diff options
context:
space:
mode:
authorAndrzej Ratajczak <andrzej.ratajczak98@gmail.com>2020-07-02 11:33:52 +0200
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-07-08 11:48:29 +0200
commitf80d5938ccafcf5bd41d73f98bebe2d9699faa95 (patch)
tree8d0df46b4f806bdcc092c2f38af5face44e026bb /plugins/gfm/src
parent5647b4221604a9084194949d9c582a57da920220 (diff)
downloaddokka-f80d5938ccafcf5bd41d73f98bebe2d9699faa95.tar.gz
dokka-f80d5938ccafcf5bd41d73f98bebe2d9699faa95.tar.bz2
dokka-f80d5938ccafcf5bd41d73f98bebe2d9699faa95.zip
Add GFM renderer tests
Diffstat (limited to 'plugins/gfm/src')
-rw-r--r--plugins/gfm/src/main/kotlin/GfmPlugin.kt70
-rw-r--r--plugins/gfm/src/test/kotlin/renderers/gfm/DivergentTest.kt375
-rw-r--r--plugins/gfm/src/test/kotlin/renderers/gfm/GfmRenderingOnlyTestBase.kt32
-rw-r--r--plugins/gfm/src/test/kotlin/renderers/gfm/GroupWrappingTest.kt77
-rw-r--r--plugins/gfm/src/test/kotlin/renderers/gfm/SourceSetDependentHintTest.kt137
5 files changed, 676 insertions, 15 deletions
diff --git a/plugins/gfm/src/main/kotlin/GfmPlugin.kt b/plugins/gfm/src/main/kotlin/GfmPlugin.kt
index 32c0b7b7..7db06bb2 100644
--- a/plugins/gfm/src/main/kotlin/GfmPlugin.kt
+++ b/plugins/gfm/src/main/kotlin/GfmPlugin.kt
@@ -62,6 +62,11 @@ open class CommonmarkRenderer(
childrenCallback()
buildNewLine()
}
+ node.hasStyle(TextStyle.Paragraph) -> {
+ buildParagraph()
+ childrenCallback()
+ buildParagraph()
+ }
else -> childrenCallback()
}
}
@@ -74,9 +79,9 @@ open class CommonmarkRenderer(
}
override fun StringBuilder.buildLink(address: String, content: StringBuilder.() -> Unit) {
- append("""<a href="$address">""")
+ append("[")
content()
- append("</a>")
+ append("]($address)")
}
override fun StringBuilder.buildList(
@@ -136,7 +141,7 @@ open class CommonmarkRenderer(
buildContentNode(content, pageContext)
} else {
val distinct = sourceSets.map {
- it to StringBuilder().apply { buildContentNode(content, pageContext, setOf(it)) }.toString()
+ it to buildString { buildContentNode(content, pageContext, setOf(it)) }
}.groupBy(Pair<DokkaSourceSet, String>::second, Pair<DokkaSourceSet, String>::first)
distinct.filter { it.key.isNotBlank() }.forEach { (text, platforms) ->
@@ -222,28 +227,61 @@ open class CommonmarkRenderer(
}
override fun buildPage(page: ContentPage, content: (StringBuilder, ContentPage) -> Unit): String =
- StringBuilder().apply {
+ buildString {
content(this, page)
- }.toString()
+ }
override fun buildError(node: ContentNode) {
context.logger.warn("Markdown renderer has encountered problem. The unmatched node is $node")
}
- override fun StringBuilder.buildDivergentInstance(node: ContentDivergentInstance, pageContext: ContentPage) {
- node.before?.let {
- buildPlatformDependentItem(it, it.sourceSets, pageContext)
+ override fun StringBuilder.buildDivergent(node: ContentDivergentGroup, pageContext: ContentPage) {
+
+ val distinct =
+ node.groupDivergentInstances(pageContext, { instance, contentPage, sourceSet ->
+ instance.before?.let { before ->
+ buildString { buildContentNode(before, pageContext, setOf(sourceSet)) }
+ } ?: ""
+ }, { instance, contentPage, sourceSet ->
+ instance.after?.let { after ->
+ buildString { buildContentNode(after, pageContext, setOf(sourceSet)) }
+ } ?: ""
+ })
+
+ distinct.values.forEach { entry ->
+ val (instance, sourceSets) = entry.getInstanceAndSourceSets()
+
+ append(sourceSets.joinToString(prefix = "#### [", postfix = "]") { "${it.moduleName}/${it.sourceSetID}" })
buildNewLine()
- }
- node.divergent.build(this, pageContext)
- buildNewLine()
- node.after?.let {
- buildPlatformDependentItem(it, it.sourceSets, pageContext)
+ instance.before?.let {
+ append("##### Brief description")
+ buildNewLine()
+ buildContentNode(it, pageContext)
+ buildNewLine()
+ }
+
+ append("##### Content")
buildNewLine()
+ entry.groupBy { buildString { buildContentNode(it.first.divergent, pageContext, setOf(it.second)) } }
+ .values.forEach { innerEntry ->
+ val (innerInstance, innerSourceSets) = innerEntry.getInstanceAndSourceSets()
+ if(sourceSets.size > 1) {
+ append(innerSourceSets.joinToString(prefix = "###### [", postfix = "]") { "${it.moduleName}/${it.sourceSetID}" })
+ buildNewLine()
+ }
+ innerInstance.divergent.build(this@buildDivergent, pageContext)
+ buildNewLine()
+ }
+ instance.after?.let {
+ append("##### More info")
+ buildNewLine()
+ buildContentNode(it, pageContext)
+ buildNewLine()
+ }
}
}
- private fun decorators(styles: Set<Style>) = StringBuilder().apply {
+ private fun decorators(styles: Set<Style>) = buildString {
styles.forEach {
when (it) {
TextStyle.Bold -> append("**")
@@ -253,7 +291,7 @@ open class CommonmarkRenderer(
else -> Unit
}
}
- }.toString()
+ }
private val PageNode.isNavigable: Boolean
get() = this !is RendererSpecificPage || strategy != RenderingStrategy.DoNothing
@@ -280,6 +318,8 @@ open class CommonmarkRenderer(
}
private fun String.withEntersAsHtml(): String = replace("\n", "<br>")
+
+ private fun List<Pair<ContentDivergentInstance, DokkaSourceSet>>.getInstanceAndSourceSets() = this.let { Pair(it.first().first, it.map { it.second }.toSet()) }
}
class MarkdownLocationProviderFactory(val context: DokkaContext) : LocationProviderFactory {
diff --git a/plugins/gfm/src/test/kotlin/renderers/gfm/DivergentTest.kt b/plugins/gfm/src/test/kotlin/renderers/gfm/DivergentTest.kt
new file mode 100644
index 00000000..13231c43
--- /dev/null
+++ b/plugins/gfm/src/test/kotlin/renderers/gfm/DivergentTest.kt
@@ -0,0 +1,375 @@
+package renderers.gfm
+
+import org.jetbrains.dokka.Platform
+import org.jetbrains.dokka.SourceRootImpl
+import org.jetbrains.dokka.gfm.CommonmarkRenderer
+import org.jetbrains.dokka.links.DRI
+import org.jetbrains.dokka.pages.ContentDivergentGroup
+import org.junit.jupiter.api.Test
+import renderers.gfm.GfmRenderingOnlyTestBase
+import renderers.defaultSourceSet
+import renderers.TestPage
+
+class DivergentTest : GfmRenderingOnlyTestBase() {
+ private val js = defaultSourceSet.copy(
+ "root",
+ "JS",
+ "js",
+ analysisPlatform = Platform.js,
+ sourceRoots = listOf(SourceRootImpl("pl1"))
+ )
+ private val jvm = defaultSourceSet.copy(
+ "root",
+ "JVM",
+ "jvm",
+
+ analysisPlatform = Platform.jvm,
+ sourceRoots = listOf(SourceRootImpl("pl1"))
+ )
+ private val native = defaultSourceSet.copy(
+ "root",
+ "NATIVE",
+ "native",
+ analysisPlatform = Platform.native,
+ sourceRoots = listOf(SourceRootImpl("pl1"))
+ )
+
+ @Test
+ fun simpleWrappingCase() {
+ val page = TestPage {
+ divergentGroup(ContentDivergentGroup.GroupID("test")) {
+ instance(setOf(DRI("test", "Test")), setOf(js)) {
+ divergent {
+ text("a")
+ }
+ }
+ }
+ }
+ val expect = "//[testPage](test-page.md)\n\n#### [root/js] \n##### Content \na \n"
+ CommonmarkRenderer(context).render(page)
+ assert(renderedContent == expect)
+ }
+
+ @Test
+ fun noPlatformHintCase() {
+ val page = TestPage {
+ divergentGroup(ContentDivergentGroup.GroupID("test"), implicitlySourceSetHinted = false) {
+ instance(setOf(DRI("test", "Test")), setOf(js)) {
+ divergent {
+ text("a")
+ }
+ }
+ }
+ }
+ val expect = "//[testPage](test-page.md)\n\n#### [root/js] \n##### Content \na \n"
+ CommonmarkRenderer(context).render(page)
+ assert(renderedContent == expect)
+ }
+
+ @Test
+ fun divergentBetweenSourceSets() {
+ val page = TestPage {
+ divergentGroup(ContentDivergentGroup.GroupID("test")) {
+ instance(setOf(DRI("test", "Test")), setOf(js)) {
+ divergent {
+ text("a")
+ }
+ }
+ instance(setOf(DRI("test", "Test")), setOf(jvm)) {
+ divergent {
+ text("b")
+ }
+ }
+ instance(setOf(DRI("test", "Test")), setOf(native)) {
+ divergent {
+ text("c")
+ }
+ }
+ }
+ }
+ val expect = "//[testPage](test-page.md)\n\n#### [root/js, root/jvm, root/native] \n##### Content \n###### [root/js] \na \n###### [root/jvm] \nb \n###### [root/native] \nc \n"
+ CommonmarkRenderer(context).render(page)
+ assert(renderedContent == expect)
+ }
+
+ @Test
+ fun divergentInOneSourceSet() {
+ val page = TestPage {
+ divergentGroup(ContentDivergentGroup.GroupID("test")) {
+ instance(setOf(DRI("test", "Test")), setOf(js)) {
+ divergent {
+ text("a")
+ }
+ }
+ instance(setOf(DRI("test", "Test2")), setOf(js)) {
+ divergent {
+ text("b")
+ }
+ }
+ instance(setOf(DRI("test", "Test3")), setOf(js)) {
+ divergent {
+ text("c")
+ }
+ }
+ }
+ }
+ val expect = "//[testPage](test-page.md)\n\n#### [root/js] \n##### Content \na \nb \nc \n"
+ CommonmarkRenderer(context).render(page)
+ assert(renderedContent == expect)
+ }
+
+ @Test
+ fun divergentInAndBetweenSourceSets() {
+ val page = TestPage {
+ divergentGroup(ContentDivergentGroup.GroupID("test")) {
+ instance(setOf(DRI("test", "Test")), setOf(native)) {
+ divergent {
+ text("a")
+ }
+ }
+ instance(setOf(DRI("test", "Test")), setOf(js)) {
+ divergent {
+ text("b")
+ }
+ }
+ instance(setOf(DRI("test", "Test")), setOf(jvm)) {
+ divergent {
+ text("c")
+ }
+ }
+ instance(setOf(DRI("test", "Test2")), setOf(js)) {
+ divergent {
+ text("d")
+ }
+ }
+ instance(setOf(DRI("test", "Test3")), setOf(native)) {
+ divergent {
+ text("e")
+ }
+ }
+ }
+ }
+ val expect = "//[testPage](test-page.md)\n\n#### [root/native, root/js, root/jvm] \n##### Content \n###### [root/native] \na \n###### [root/js] \nb \n###### [root/jvm] \nc \n###### [root/js] \nd \n###### [root/native] \ne \n"
+ CommonmarkRenderer(context).render(page)
+ assert(renderedContent == expect)
+ }
+
+ @Test
+ fun divergentInAndBetweenSourceSetsWithGrouping() {
+ val page = TestPage {
+ divergentGroup(ContentDivergentGroup.GroupID("test")) {
+ instance(setOf(DRI("test", "Test")), setOf(native)) {
+ divergent {
+ text("a")
+ }
+ after {
+ text("a+")
+ }
+ }
+ instance(setOf(DRI("test", "Test")), setOf(js)) {
+ divergent {
+ text("b")
+ }
+ after {
+ text("bd+")
+ }
+ }
+ instance(setOf(DRI("test", "Test")), setOf(jvm)) {
+ divergent {
+ text("c")
+ }
+ }
+ instance(setOf(DRI("test", "Test2")), setOf(js)) {
+ divergent {
+ text("d")
+ }
+ after {
+ text("bd+")
+ }
+ }
+ instance(setOf(DRI("test", "Test3")), setOf(native)) {
+ divergent {
+ text("e")
+ }
+ after {
+ text("e+")
+ }
+ }
+ }
+ }
+ val expect = "//[testPage](test-page.md)\n\n#### [root/native] \n##### Content \na \n##### More info \na+ \n#### [root/js] \n##### Content \nb \nd \n##### More info \nbd+ \n#### [root/jvm] \n##### Content \nc \n#### [root/native] \n##### Content \ne \n##### More info \ne+ \n"
+ CommonmarkRenderer(context).render(page)
+ assert(renderedContent == expect)
+ }
+
+ @Test
+ fun divergentSameBefore() {
+ val page = TestPage {
+ divergentGroup(ContentDivergentGroup.GroupID("test")) {
+ instance(setOf(DRI("test", "Test")), setOf(native)) {
+ before {
+ text("ab-")
+ }
+ divergent {
+ text("a")
+ }
+ }
+ instance(setOf(DRI("test", "Test2")), setOf(native)) {
+ before {
+ text("ab-")
+ }
+ divergent {
+ text("b")
+ }
+ }
+ }
+ }
+ val expect = "//[testPage](test-page.md)\n\n#### [root/native] \n##### Brief description \nab- \n##### Content \na \nb \n"
+ CommonmarkRenderer(context).render(page)
+ assert(renderedContent == expect)
+ }
+
+ @Test
+ fun divergentSameAfter() {
+ val page = TestPage {
+ divergentGroup(ContentDivergentGroup.GroupID("test")) {
+ instance(setOf(DRI("test", "Test")), setOf(native)) {
+ divergent {
+ text("a")
+ }
+ after {
+ text("ab+")
+ }
+ }
+ instance(setOf(DRI("test", "Test2")), setOf(native)) {
+ divergent {
+ text("b")
+ }
+ after {
+ text("ab+")
+ }
+ }
+ }
+ }
+ val expect = "//[testPage](test-page.md)\n\n#### [root/native] \n##### Content \na \nb \n##### More info \nab+ \n"
+ CommonmarkRenderer(context).render(page)
+ assert(renderedContent == expect)
+ }
+
+ @Test
+ fun divergentGroupedByBeforeAndAfter() {
+ val page = TestPage {
+ divergentGroup(ContentDivergentGroup.GroupID("test")) {
+ instance(setOf(DRI("test", "Test")), setOf(native)) {
+ before {
+ text("ab-")
+ }
+ divergent {
+ text("a")
+ }
+ after {
+ text("ab+")
+ }
+ }
+ instance(setOf(DRI("test", "Test2")), setOf(native)) {
+ before {
+ text("ab-")
+ }
+ divergent {
+ text("b")
+ }
+ after {
+ text("ab+")
+ }
+ }
+ }
+ }
+ val expect = "//[testPage](test-page.md)\n\n#### [root/native] \n##### Brief description \nab- \n##### Content \na \nb \n##### More info \nab+ \n"
+ CommonmarkRenderer(context).render(page)
+ assert(renderedContent == expect)
+ }
+
+ @Test
+ fun divergentDifferentBeforeAndAfter() {
+ val page = TestPage {
+ divergentGroup(ContentDivergentGroup.GroupID("test")) {
+ instance(setOf(DRI("test", "Test")), setOf(native)) {
+ before {
+ text("a-")
+ }
+ divergent {
+ text("a")
+ }
+ after {
+ text("ab+")
+ }
+ }
+ instance(setOf(DRI("test", "Test2")), setOf(native)) {
+ before {
+ text("b-")
+ }
+ divergent {
+ text("b")
+ }
+ after {
+ text("ab+")
+ }
+ }
+ }
+ }
+ val expect = "//[testPage](test-page.md)\n\n#### [root/native] \n##### Brief description \na- \n##### Content \na \n##### More info \nab+ \n#### [root/native] \n##### Brief description \nb- \n##### Content \nb \n##### More info \nab+ \n"
+ CommonmarkRenderer(context).render(page)
+ assert(renderedContent == expect)
+ }
+
+ @Test
+ fun divergentInAndBetweenSourceSetsWithGroupingAncCommonParts() {
+ val page = TestPage {
+ divergentGroup(ContentDivergentGroup.GroupID("test")) {
+ instance(setOf(DRI("test", "Test")), setOf(native)) {
+ divergent {
+ text("a")
+ }
+ after {
+ text("a+")
+ }
+ }
+ instance(setOf(DRI("test", "Test")), setOf(js)) {
+ divergent {
+ text("b")
+ }
+ after {
+ text("bd+")
+ }
+ }
+ instance(setOf(DRI("test", "Test")), setOf(jvm)) {
+ divergent {
+ text("c")
+ }
+ after {
+ text("bd+")
+ }
+ }
+ instance(setOf(DRI("test", "Test2")), setOf(js)) {
+ divergent {
+ text("d")
+ }
+ after {
+ text("bd+")
+ }
+ }
+ instance(setOf(DRI("test", "Test3")), setOf(native)) {
+ divergent {
+ text("e")
+ }
+ after {
+ text("e+")
+ }
+ }
+ }
+ }
+ val expect = "//[testPage](test-page.md)\n\n#### [root/native] \n##### Content \na \n##### More info \na+ \n#### [root/js, root/jvm] \n##### Content \n###### [root/js] \nb \n###### [root/jvm] \nc \n###### [root/js] \nd \n##### More info \nbd+ \n#### [root/native] \n##### Content \ne \n##### More info \ne+ \n"
+ CommonmarkRenderer(context).render(page)
+ assert(renderedContent == expect)
+ }
+} \ No newline at end of file
diff --git a/plugins/gfm/src/test/kotlin/renderers/gfm/GfmRenderingOnlyTestBase.kt b/plugins/gfm/src/test/kotlin/renderers/gfm/GfmRenderingOnlyTestBase.kt
new file mode 100644
index 00000000..3636bf26
--- /dev/null
+++ b/plugins/gfm/src/test/kotlin/renderers/gfm/GfmRenderingOnlyTestBase.kt
@@ -0,0 +1,32 @@
+package renderers.gfm
+
+import org.jetbrains.dokka.DokkaConfigurationImpl
+import org.jetbrains.dokka.gfm.GfmPlugin
+import org.jetbrains.dokka.gfm.MarkdownLocationProviderFactory
+import org.jetbrains.dokka.testApi.context.MockContext
+import org.jetbrains.dokka.base.DokkaBase
+import org.jetbrains.dokka.base.renderers.RootCreator
+import org.jetbrains.dokka.base.resolvers.external.DokkaExternalLocationProviderFactory
+import org.jetbrains.dokka.base.resolvers.external.JavadocExternalLocationProviderFactory
+import renderers.RenderingOnlyTestBase
+import utils.TestOutputWriter
+
+abstract class GfmRenderingOnlyTestBase : RenderingOnlyTestBase() {
+
+ val files = TestOutputWriter()
+ override val context = MockContext(
+ DokkaBase().outputWriter to { _ -> files },
+ DokkaBase().locationProviderFactory to ::MarkdownLocationProviderFactory,
+ DokkaBase().externalLocationProviderFactory to { ::JavadocExternalLocationProviderFactory },
+ DokkaBase().externalLocationProviderFactory to { ::DokkaExternalLocationProviderFactory },
+ GfmPlugin().gfmPreprocessors to { _ -> RootCreator },
+
+ testConfiguration = DokkaConfigurationImpl(
+ "", "", null, false, emptyList(), emptyList(), emptyMap(), emptyList(), false
+ )
+ )
+
+ protected val renderedContent: String by lazy {
+ files.contents.getValue("test-page.md")
+ }
+} \ No newline at end of file
diff --git a/plugins/gfm/src/test/kotlin/renderers/gfm/GroupWrappingTest.kt b/plugins/gfm/src/test/kotlin/renderers/gfm/GroupWrappingTest.kt
new file mode 100644
index 00000000..2e1dc83a
--- /dev/null
+++ b/plugins/gfm/src/test/kotlin/renderers/gfm/GroupWrappingTest.kt
@@ -0,0 +1,77 @@
+package renderers.gfm
+
+import org.jetbrains.dokka.gfm.CommonmarkRenderer
+import renderers.gfm.GfmRenderingOnlyTestBase
+import org.jetbrains.dokka.pages.TextStyle
+import org.junit.jupiter.api.Test
+import renderers.*
+
+class GroupWrappingTest : GfmRenderingOnlyTestBase() {
+
+ @Test
+ fun notWrapped() {
+ val page = TestPage {
+ group {
+ text("a")
+ text("b")
+ }
+ text("c")
+ }
+
+ CommonmarkRenderer(context).render(page)
+
+ assert(renderedContent == "//[testPage](test-page.md)\n\nabc")
+ }
+
+ @Test
+ fun paragraphWrapped() {
+ val page = TestPage {
+ group(styles = setOf(TextStyle.Paragraph)) {
+ text("a")
+ text("b")
+ }
+ text("c")
+ }
+
+ CommonmarkRenderer(context).render(page)
+
+ assert(renderedContent == "//[testPage](test-page.md)\n\n\n\nab\n\nc")
+ }
+
+ @Test
+ fun blockWrapped() {
+ val page = TestPage {
+ group(styles = setOf(TextStyle.Block)) {
+ text("a")
+ text("b")
+ }
+ text("c")
+ }
+
+ CommonmarkRenderer(context).render(page)
+
+ assert(renderedContent == "//[testPage](test-page.md)\n\nab \nc")
+ }
+
+ @Test
+ fun nested() {
+ val page = TestPage {
+ group(styles = setOf(TextStyle.Block)) {
+ text("a")
+ group(styles = setOf(TextStyle.Block)) {
+ group(styles = setOf(TextStyle.Block)) {
+ text("b")
+ text("c")
+ }
+ }
+ text("d")
+ }
+ }
+
+ CommonmarkRenderer(context).render(page)
+
+// renderedContent.match(Div("a", Div(Div("bc")), "d"))
+ assert(renderedContent == "//[testPage](test-page.md)\n\nabc \n \nd \n")
+ }
+
+}
diff --git a/plugins/gfm/src/test/kotlin/renderers/gfm/SourceSetDependentHintTest.kt b/plugins/gfm/src/test/kotlin/renderers/gfm/SourceSetDependentHintTest.kt
new file mode 100644
index 00000000..64664d4a
--- /dev/null
+++ b/plugins/gfm/src/test/kotlin/renderers/gfm/SourceSetDependentHintTest.kt
@@ -0,0 +1,137 @@
+package renderers.gfm
+
+import org.jetbrains.dokka.Platform
+import org.jetbrains.dokka.SourceRootImpl
+import org.jetbrains.dokka.gfm.CommonmarkRenderer
+import renderers.gfm.GfmRenderingOnlyTestBase
+import org.jetbrains.dokka.pages.TextStyle
+import org.junit.jupiter.api.Test
+import renderers.TestPage
+import renderers.defaultSourceSet
+
+class SourceSetDependentHintTest : GfmRenderingOnlyTestBase() {
+
+ private val pl1 = defaultSourceSet.copy(
+ "root",
+ "pl1",
+ "pl1",
+ analysisPlatform = Platform.js,
+ sourceRoots = listOf(SourceRootImpl("pl1"))
+ )
+ private val pl2 = defaultSourceSet.copy(
+ "root",
+ "pl2",
+ "pl2",
+ analysisPlatform = Platform.jvm,
+ sourceRoots = listOf(SourceRootImpl("pl1"))
+ )
+ private val pl3 = defaultSourceSet.copy(
+ "root",
+ "pl3",
+ "pl3",
+ analysisPlatform = Platform.native,
+ sourceRoots = listOf(SourceRootImpl("pl1"))
+ )
+
+ @Test
+ fun platformIndependentCase() {
+ val page = TestPage {
+ sourceSetDependentHint(sourceSets = setOf(pl1, pl2, pl3), styles = setOf(TextStyle.Block)) {
+ text("a")
+ text("b")
+ text("c")
+ }
+ }
+
+ CommonmarkRenderer(context).render(page)
+ assert(renderedContent == "//[testPage](test-page.md)\n\n [root/pl1, root/pl2, root/pl3] abc \n ")
+ }
+
+ @Test
+ fun completelyDivergentCase() {
+ val page = TestPage {
+ sourceSetDependentHint(sourceSets = setOf(pl1, pl2, pl3), styles = setOf(TextStyle.Block)) {
+ text("a", sourceSets = setOf(pl1))
+ text("b", sourceSets = setOf(pl2))
+ text("c", sourceSets = setOf(pl3))
+ }
+ }
+
+ CommonmarkRenderer(context).render(page)
+ assert(renderedContent == "//[testPage](test-page.md)\n\n [root/pl1] a \n [root/pl2] b \n [root/pl3] c \n ")
+ }
+
+ @Test
+ fun overlappingCase() {
+ val page = TestPage {
+ sourceSetDependentHint(sourceSets = setOf(pl1, pl2), styles = setOf(TextStyle.Block)) {
+ text("a", sourceSets = setOf(pl1))
+ text("b", sourceSets = setOf(pl1, pl2))
+ text("c", sourceSets = setOf(pl2))
+ }
+ }
+
+ CommonmarkRenderer(context).render(page)
+ assert(renderedContent == "//[testPage](test-page.md)\n\n [root/pl1] ab \n [root/pl2] bc \n ")
+ }
+
+ @Test
+ fun caseThatCanBeSimplified() {
+ val page = TestPage {
+ sourceSetDependentHint(sourceSets = setOf(pl1, pl2), styles = setOf(TextStyle.Block)) {
+ text("a", sourceSets = setOf(pl1, pl2))
+ text("b", sourceSets = setOf(pl1))
+ text("b", sourceSets = setOf(pl2))
+ }
+ }
+
+ CommonmarkRenderer(context).render(page)
+ assert(renderedContent == "//[testPage](test-page.md)\n\n [root/pl1, root/pl2] ab \n ")
+ }
+
+ @Test
+ fun caseWithGroupBreakingSimplification() {
+ val page = TestPage {
+ sourceSetDependentHint(sourceSets = setOf(pl1, pl2), styles = setOf(TextStyle.Block)) {
+ group(styles = setOf(TextStyle.Block)) {
+ text("a", sourceSets = setOf(pl1, pl2))
+ text("b", sourceSets = setOf(pl1))
+ }
+ text("b", sourceSets = setOf(pl2))
+ }
+ }
+
+ CommonmarkRenderer(context).render(page)
+ assert(renderedContent == "//[testPage](test-page.md)\n\n [root/pl1] ab \n \n [root/pl2] a \nb \n ")
+ }
+
+ @Test
+ fun caseWithGroupNotBreakingSimplification() {
+ val page = TestPage {
+ sourceSetDependentHint(sourceSets = setOf(pl1, pl2)) {
+ group {
+ text("a", sourceSets = setOf(pl1, pl2))
+ text("b", sourceSets = setOf(pl1))
+ }
+ text("b", sourceSets = setOf(pl2))
+ }
+ }
+
+ CommonmarkRenderer(context).render(page)
+ assert(renderedContent == "//[testPage](test-page.md)\n\n [root/pl1, root/pl2] ab ")
+ }
+
+ @Test
+ fun partiallyUnifiedCase() {
+ val page = TestPage {
+ sourceSetDependentHint(sourceSets = setOf(pl1, pl2, pl3), styles = setOf(TextStyle.Block)) {
+ text("a", sourceSets = setOf(pl1))
+ text("a", sourceSets = setOf(pl2))
+ text("b", sourceSets = setOf(pl3))
+ }
+ }
+
+ CommonmarkRenderer(context).render(page)
+ assert(renderedContent == "//[testPage](test-page.md)\n\n [root/pl1, root/pl2] a \n [root/pl3] b \n ")
+ }
+} \ No newline at end of file