aboutsummaryrefslogtreecommitdiff
path: root/core/src/test/kotlin/pageMerger
diff options
context:
space:
mode:
authorSzymon Świstun <sswistun@virtuslab.com>2020-02-11 18:29:19 +0100
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-02-12 13:33:10 +0100
commit519bc7969930f191fb7d9155b1c07f7e226e219f (patch)
tree60a5ceccdf81f300e66bf13e35e304130f11a440 /core/src/test/kotlin/pageMerger
parent1e0271e4e2888022f2ac93366c397d7315008c45 (diff)
downloaddokka-519bc7969930f191fb7d9155b1c07f7e226e219f.tar.gz
dokka-519bc7969930f191fb7d9155b1c07f7e226e219f.tar.bz2
dokka-519bc7969930f191fb7d9155b1c07f7e226e219f.zip
page merger strategy with tests
Diffstat (limited to 'core/src/test/kotlin/pageMerger')
-rw-r--r--core/src/test/kotlin/pageMerger/DefaultPageNodeMergerTest.kt51
-rw-r--r--core/src/test/kotlin/pageMerger/PageNodeMergerTest.kt128
2 files changed, 128 insertions, 51 deletions
diff --git a/core/src/test/kotlin/pageMerger/DefaultPageNodeMergerTest.kt b/core/src/test/kotlin/pageMerger/DefaultPageNodeMergerTest.kt
deleted file mode 100644
index 432820af..00000000
--- a/core/src/test/kotlin/pageMerger/DefaultPageNodeMergerTest.kt
+++ /dev/null
@@ -1,51 +0,0 @@
-package pageMerger
-
-import org.jetbrains.dokka.pages.ContentPage
-import org.jetbrains.dokka.pages.PageNode
-import org.junit.Test
-import testApi.testRunner.AbstractCoreTest
-
-class DefaultPageNodeMergerTest : AbstractCoreTest() {
-
- @Test
- fun test1() {
- val configuration = dokkaConfiguration {
- passes {
- pass {
- sourceRoots = listOf("src/main/kotlin/pageMerger/Test.kt")
- }
- }
- }
-
- testInline(
- """
- |/src/main/kotlin/pageMerger/Test.kt
- |package pageMerger
- |
- |fun testT(): Int = 1
- |fun testT(i: Int): Int = i
- |
- |object Test {
- | fun test(): String = ""
- | fun test(str: String): String = str
- |}
- """.trimMargin(),
- configuration
- ) {
- pagesTransformationStage = {
- val allChildren = it.childrenRec().filterIsInstance<ContentPage>()
- val testT = allChildren.filter { it.name == "testT" }
- val test = allChildren.filter { it.name == "test" }
-
- assert(testT.size == 1) { "There can be only one testT page" }
- assert(testT.first().dri.size == 2) { "testT page should have 2 DRI" }
-
- assert(test.size == 1) { "There can be only one test page" }
- assert(test.first().dri.size == 2) { "test page should have 2 DRI" }
- }
- }
- }
-
- fun PageNode.childrenRec(): List<PageNode> = listOf(this) + children.flatMap { it.childrenRec() }
-
-} \ No newline at end of file
diff --git a/core/src/test/kotlin/pageMerger/PageNodeMergerTest.kt b/core/src/test/kotlin/pageMerger/PageNodeMergerTest.kt
new file mode 100644
index 00000000..e43e2348
--- /dev/null
+++ b/core/src/test/kotlin/pageMerger/PageNodeMergerTest.kt
@@ -0,0 +1,128 @@
+package pageMerger
+
+import org.jetbrains.dokka.CoreExtensions
+import org.jetbrains.dokka.pages.ContentPage
+import org.jetbrains.dokka.pages.PageNode
+import org.jetbrains.dokka.plugability.DokkaPlugin
+import org.jetbrains.dokka.transformers.pages.DefaultPageMergerStrategy
+import org.jetbrains.dokka.transformers.pages.PageMergerStrategy
+import org.jetbrains.dokka.transformers.pages.SameNamePageMergerStrategy
+import org.jetbrains.dokka.utilities.DokkaLogger
+import org.junit.Test
+import testApi.testRunner.AbstractCoreTest
+
+class PageNodeMergerTest : AbstractCoreTest() {
+
+ object SameNameStrategy : DokkaPlugin() {
+ val strategy by extending { CoreExtensions.pageMergerStrategy with SameNamePageMergerStrategy }
+ }
+
+ class DefaultStrategy(val strList: MutableList<String> = mutableListOf()) : DokkaPlugin(), DokkaLogger {
+ val strategy by extending { CoreExtensions.pageMergerStrategy with DefaultPageMergerStrategy(this@DefaultStrategy) }
+
+ override var warningsCount: Int = 0
+ override var errorsCount: Int = 0
+
+ override fun debug(message: String) = TODO()
+
+ override fun info(message: String) = TODO()
+
+ override fun progress(message: String) = TODO()
+
+ override fun warn(message: String) {
+ strList += message
+ }
+
+ override fun error(message: String) = TODO()
+
+ override fun report() = TODO()
+ }
+
+ @Test
+ fun sameNameStrategyTest() {
+
+ val configuration = dokkaConfiguration {
+ passes {
+ pass {
+ sourceRoots = listOf("src/main/kotlin/pageMerger/Test.kt")
+ }
+ }
+ }
+
+ testInline(
+ """
+ |/src/main/kotlin/pageMerger/Test.kt
+ |package pageMerger
+ |
+ |fun testT(): Int = 1
+ |fun testT(i: Int): Int = i
+ |
+ |object Test {
+ | fun test(): String = ""
+ | fun test(str: String): String = str
+ |}
+ """.trimMargin(),
+ configuration,
+ pluginOverrides = listOf(SameNameStrategy)
+ ) {
+ pagesTransformationStage = {
+ val allChildren = it.childrenRec().filterIsInstance<ContentPage>()
+ val testT = allChildren.filter { it.name == "testT" }
+ val test = allChildren.filter { it.name == "test" }
+
+ assert(testT.size == 1) { "There can be only one testT page" }
+ assert(testT.first().dri.size == 2) { "testT page should have 2 DRI, but has ${testT.first().dri.size}" }
+
+ assert(test.size == 1) { "There can be only one test page" }
+ assert(test.first().dri.size == 2) { "test page should have 2 DRI, but has ${test.first().dri.size}" }
+ }
+ }
+ }
+
+ @Test
+ fun defaultStrategyTest() {
+ val strList: MutableList<String> = mutableListOf()
+
+ val configuration = dokkaConfiguration {
+ passes {
+ pass {
+ sourceRoots = listOf("src/main/kotlin/pageMerger/Test.kt")
+ }
+ }
+ }
+
+ testInline(
+ """
+ |/src/main/kotlin/pageMerger/Test.kt
+ |package pageMerger
+ |
+ |fun testT(): Int = 1
+ |fun testT(i: Int): Int = i
+ |
+ |object Test {
+ | fun test(): String = ""
+ | fun test(str: String): String = str
+ |}
+ """.trimMargin(),
+ configuration,
+ pluginOverrides = listOf(DefaultStrategy(strList))
+ ) {
+ pagesTransformationStage = { root ->
+ val allChildren = root.childrenRec().filterIsInstance<ContentPage>()
+ val testT = allChildren.filter { it.name == "testT" }
+ val test = allChildren.filter { it.name == "test" }
+
+ assert(testT.size == 1) { "There can be only one testT page" }
+ assert(testT.first().dri.size == 1) { "testT page should have single DRI, but has ${testT.first().dri.size}" }
+
+ assert(test.size == 1) { "There can be only one test page" }
+ assert(test.first().dri.size == 1) { "test page should have single DRI, but has ${test.first().dri.size}" }
+
+ assert(strList.count() == 2) { "Expected 2 warnings, got ${strList.count()}" }
+ }
+ }
+ }
+
+ fun PageNode.childrenRec(): List<PageNode> = listOf(this) + children.flatMap { it.childrenRec() }
+
+} \ No newline at end of file