From 46b4bbb68ce1285a1aea700cc0d0000c6b7ed97b Mon Sep 17 00:00:00 2001 From: Paweł Marks Date: Wed, 12 Feb 2020 18:05:24 +0100 Subject: Moves all core tests to base plugin --- .../commonMain/kotlin/Clock.kt | 15 ++++++++++ .../commonMain/kotlin/House.kt | 24 +++++++++++++++ .../basicMultiplatformTest/jsMain/kotlin/Clock.kt | 21 +++++++++++++ .../jvmAndJsSecondCommonMain/kotlin/Greeter.kt | 10 +++++++ .../jvmMain/kotlin/example/Clock.kt | 34 ++++++++++++++++++++++ .../jvmMain/kotlin/example/ClockDays.kt | 15 ++++++++++ .../jvmMain/kotlin/example/ParticularClock.kt | 32 ++++++++++++++++++++ 7 files changed, 151 insertions(+) create mode 100644 plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/commonMain/kotlin/Clock.kt create mode 100644 plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/commonMain/kotlin/House.kt create mode 100644 plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jsMain/kotlin/Clock.kt create mode 100644 plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmAndJsSecondCommonMain/kotlin/Greeter.kt create mode 100644 plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/Clock.kt create mode 100644 plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/ClockDays.kt create mode 100644 plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/ParticularClock.kt (limited to 'plugins/base/src/test/resources/multiplatform/basicMultiplatformTest') diff --git a/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/commonMain/kotlin/Clock.kt b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/commonMain/kotlin/Clock.kt new file mode 100644 index 00000000..4753cb32 --- /dev/null +++ b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/commonMain/kotlin/Clock.kt @@ -0,0 +1,15 @@ +package example + +/** + * Documentation for expected class Clock + * in common module + */ +expect open class Clock() { + fun getTime(): String + /** + * Time in minis + */ + fun getTimesInMillis(): String + fun getYear(): String +} + diff --git a/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/commonMain/kotlin/House.kt b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/commonMain/kotlin/House.kt new file mode 100644 index 00000000..c879dee7 --- /dev/null +++ b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/commonMain/kotlin/House.kt @@ -0,0 +1,24 @@ +package example + +class House(val street: String, val number: Int) { + + /** + * The owner of the house + */ + var owner: String = "" + + /** + * The owner of the house + */ + val differentOwner: String = "" + + fun addFloor() {} + + class Basement { + val pickles : List = mutableListOf() + } + + companion object { + val DEFAULT = House("",0) + } +} \ No newline at end of file diff --git a/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jsMain/kotlin/Clock.kt b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jsMain/kotlin/Clock.kt new file mode 100644 index 00000000..967cffcd --- /dev/null +++ b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jsMain/kotlin/Clock.kt @@ -0,0 +1,21 @@ +package example + +import greeteer.Greeter +import kotlin.js.Date + +/** + * Documentation for actual class Clock in JS + */ +actual open class Clock { + actual fun getTime() = Date.now().toString() + fun onlyJsFunction(): Int = 42 + actual fun getTimesInMillis(): String = Date.now().toString() + + actual fun getYear(): String { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } +} + +fun main() { + Greeter().greet().also { println(it) } +} \ No newline at end of file diff --git a/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmAndJsSecondCommonMain/kotlin/Greeter.kt b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmAndJsSecondCommonMain/kotlin/Greeter.kt new file mode 100644 index 00000000..8a52e2f3 --- /dev/null +++ b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmAndJsSecondCommonMain/kotlin/Greeter.kt @@ -0,0 +1,10 @@ +package greeteer + +import example.Clock + +class Greeter { + /** + * Some docs for the [greet] function + */ + fun greet() = Clock().let{ "Hello there! THe time is ${it.getTime()}" } +} \ No newline at end of file diff --git a/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/Clock.kt b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/Clock.kt new file mode 100644 index 00000000..9ec01fb6 --- /dev/null +++ b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/Clock.kt @@ -0,0 +1,34 @@ +package example + +import greeteer.Greeter + +actual open class Clock { + actual fun getTime(): String = System.currentTimeMillis().toString() + actual fun getTimesInMillis(): String = System.currentTimeMillis().toString() + + /** + * Documentation for onlyJVMFunction on... + * wait for it... + * ...JVM! + */ + fun onlyJVMFunction(): Double = 2.5 + /** + * Custom equals function + */ + override fun equals(other: Any?): Boolean { + return super.equals(other) + } + + open fun getDayOfTheWeek(): String { + TODO("not implemented") + } + actual fun getYear(): String { + TODO("not implemented") + } +} + +fun clockList() = listOf(Clock()) + +fun main() { + Greeter().greet().also { println(it) } +} \ No newline at end of file diff --git a/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/ClockDays.kt b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/ClockDays.kt new file mode 100644 index 00000000..136ae5c8 --- /dev/null +++ b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/ClockDays.kt @@ -0,0 +1,15 @@ +package example + +/** + * frgergergrthe + * */ +enum class ClockDays { + /** + * dfsdfsdfds + * */ + FIRST, + SECOND, // test2 + THIRD, // test3 + FOURTH, // test4 + FIFTH // test5 +} \ No newline at end of file diff --git a/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/ParticularClock.kt b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/ParticularClock.kt new file mode 100644 index 00000000..40813b50 --- /dev/null +++ b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/ParticularClock.kt @@ -0,0 +1,32 @@ +package example + +import greeteer.Greeter + +class ParticularClock(private val clockDay: ClockDays) : Clock() { + + /** + * Rings bell [times] + */ + fun ringBell(times: Int) {} + + /** + * Uses provider [greeter] + */ + fun useGreeter(greeter: Greeter) { + + } + + /** + * Day of the week + */ + override fun getDayOfTheWeek() = clockDay.name +} + +/** + * A sample extension function + * When $a \ne 0$, there are two solutions to \(ax^2 + bx + c = 0\) and they are $$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$ + * @usesMathJax + */ +fun Clock.extensionFun() { + +} \ No newline at end of file -- cgit From 2ab810271d2b2dba7448a8cb2b53f0031e6ef40e Mon Sep 17 00:00:00 2001 From: Andrzej Ratajczak Date: Fri, 3 Jul 2020 16:52:56 +0200 Subject: Add tests for signatures rendering --- .../test/kotlin/renderers/html/DivergentTest.kt | 3 + .../kotlin/renderers/html/GroupWrappingTest.kt | 3 + .../renderers/html/HtmlRenderingOnlyTestBase.kt | 5 - .../renderers/html/SourceSetDependentHintTest.kt | 3 + .../kotlin/signatures/DivergentSignatureTest.kt | 122 +++++++ .../src/test/kotlin/signatures/SignatureTest.kt | 379 +++++++++++++++++++++ plugins/base/src/test/kotlin/utils/JsoupUtils.kt | 29 ++ plugins/base/src/test/kotlin/utils/TestUtils.kt | 1 + .../jvmMain/kotlin/example/Clock.kt | 3 + 9 files changed, 543 insertions(+), 5 deletions(-) create mode 100644 plugins/base/src/test/kotlin/signatures/DivergentSignatureTest.kt create mode 100644 plugins/base/src/test/kotlin/signatures/SignatureTest.kt create mode 100644 plugins/base/src/test/kotlin/utils/JsoupUtils.kt (limited to 'plugins/base/src/test/resources/multiplatform/basicMultiplatformTest') diff --git a/plugins/base/src/test/kotlin/renderers/html/DivergentTest.kt b/plugins/base/src/test/kotlin/renderers/html/DivergentTest.kt index f5565b48..54d55721 100644 --- a/plugins/base/src/test/kotlin/renderers/html/DivergentTest.kt +++ b/plugins/base/src/test/kotlin/renderers/html/DivergentTest.kt @@ -7,6 +7,9 @@ import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.pages.ContentDivergentGroup import org.junit.jupiter.api.Test import renderers.* +import utils.Div +import utils.Span +import utils.match class DivergentTest : HtmlRenderingOnlyTestBase() { private val js = defaultSourceSet.copy( diff --git a/plugins/base/src/test/kotlin/renderers/html/GroupWrappingTest.kt b/plugins/base/src/test/kotlin/renderers/html/GroupWrappingTest.kt index 59150e18..c0c03998 100644 --- a/plugins/base/src/test/kotlin/renderers/html/GroupWrappingTest.kt +++ b/plugins/base/src/test/kotlin/renderers/html/GroupWrappingTest.kt @@ -4,6 +4,9 @@ import org.jetbrains.dokka.base.renderers.html.HtmlRenderer import org.jetbrains.dokka.pages.TextStyle import org.junit.jupiter.api.Test import renderers.* +import utils.Div +import utils.P +import utils.match class GroupWrappingTest : HtmlRenderingOnlyTestBase() { diff --git a/plugins/base/src/test/kotlin/renderers/html/HtmlRenderingOnlyTestBase.kt b/plugins/base/src/test/kotlin/renderers/html/HtmlRenderingOnlyTestBase.kt index f93eccb5..5ac5aafa 100644 --- a/plugins/base/src/test/kotlin/renderers/html/HtmlRenderingOnlyTestBase.kt +++ b/plugins/base/src/test/kotlin/renderers/html/HtmlRenderingOnlyTestBase.kt @@ -1,16 +1,11 @@ package renderers.html -import org.jetbrains.dokka.DokkaConfiguration import org.jetbrains.dokka.DokkaConfigurationImpl 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 org.jetbrains.dokka.base.resolvers.local.DefaultLocationProviderFactory -import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter -import org.jetbrains.dokka.model.doc.DocTag -import org.jetbrains.dokka.model.properties.PropertyContainer -import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.testApi.context.MockContext import org.jsoup.Jsoup import org.jsoup.nodes.Element diff --git a/plugins/base/src/test/kotlin/renderers/html/SourceSetDependentHintTest.kt b/plugins/base/src/test/kotlin/renderers/html/SourceSetDependentHintTest.kt index 87c67842..cf7f47e6 100644 --- a/plugins/base/src/test/kotlin/renderers/html/SourceSetDependentHintTest.kt +++ b/plugins/base/src/test/kotlin/renderers/html/SourceSetDependentHintTest.kt @@ -7,6 +7,9 @@ import org.jetbrains.dokka.pages.TextStyle import org.junit.jupiter.api.Test import renderers.TestPage import renderers.defaultSourceSet +import renderers.RenderingOnlyTestBase +import utils.Div +import utils.match class SourceSetDependentHintTest : HtmlRenderingOnlyTestBase() { diff --git a/plugins/base/src/test/kotlin/signatures/DivergentSignatureTest.kt b/plugins/base/src/test/kotlin/signatures/DivergentSignatureTest.kt new file mode 100644 index 00000000..6ed17110 --- /dev/null +++ b/plugins/base/src/test/kotlin/signatures/DivergentSignatureTest.kt @@ -0,0 +1,122 @@ +package signatures + +import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest +import org.jsoup.Jsoup +import org.junit.jupiter.api.Test +import utils.* +import java.nio.file.Paths + +class DivergentSignatureTest : AbstractCoreTest() { + + @Test + fun `three divergent signatures for class`() { + + val testDataDir = getTestDataDir("multiplatform/basicMultiplatformTest").toAbsolutePath() + + + val configuration = dokkaConfiguration { + passes { + pass { + moduleName = "example" + analysisPlatform = "js" + sourceRoots = listOf("jsMain", "commonMain", "jvmAndJsSecondCommonMain").map { + Paths.get("$testDataDir/$it/kotlin").toString() + } + sourceSetID = "js" + } + pass { + moduleName = "example" + analysisPlatform = "jvm" + sourceRoots = listOf("jvmMain", "commonMain", "jvmAndJsSecondCommonMain").map { + Paths.get("$testDataDir/$it/kotlin").toString() + } + sourceSetID = "jvm" + } + pass { + moduleName = "example" + analysisPlatform = "common" + sourceRoots = listOf("jvmMain", "commonMain", "jvmAndJsSecondCommonMain").map { + Paths.get("$testDataDir/$it/kotlin").toString() + } + sourceSetID = "jvm" + } + } + } + + val writerPlugin = TestOutputWriterPlugin() + + testFromData( + configuration, + pluginOverrides = listOf(writerPlugin) + ) { + renderingStage = { _, _ -> + assert(writerPlugin.writer.contents.getValue("example/example/-clock/index.html") + .let { Jsoup.parse(it) }.select("#content").single() + .select("div.sourceset-depenent-content") + .fold(0) { acc, elem -> + acc + if (elem.child(0).html().contains( + Regex("Documentation for (expected|actual) class Clock .*") + ) + ) 1 else 0 + } == 3 + ) + } + } + } + + @Test + fun `three divergent signatures for class`() { + + val testDataDir = getTestDataDir("multiplatform/basicMultiplatformTest").toAbsolutePath() + + + val configuration = dokkaConfiguration { + passes { + pass { + moduleName = "example" + analysisPlatform = "js" + sourceRoots = listOf("jsMain", "commonMain", "jvmAndJsSecondCommonMain").map { + Paths.get("$testDataDir/$it/kotlin").toString() + } + sourceSetID = "js" + } + pass { + moduleName = "example" + analysisPlatform = "jvm" + sourceRoots = listOf("jvmMain", "commonMain", "jvmAndJsSecondCommonMain").map { + Paths.get("$testDataDir/$it/kotlin").toString() + } + sourceSetID = "jvm" + } + pass { + moduleName = "example" + analysisPlatform = "common" + sourceRoots = listOf("jvmMain", "commonMain", "jvmAndJsSecondCommonMain").map { + Paths.get("$testDataDir/$it/kotlin").toString() + } + sourceSetID = "jvm" + } + } + } + + val writerPlugin = TestOutputWriterPlugin() + + testFromData( + configuration, + pluginOverrides = listOf(writerPlugin) + ) { + renderingStage = { _, _ -> + assert(writerPlugin.writer.contents.getValue("example/example/-clock/index.html") + .let { Jsoup.parse(it) }.select("#content").single() + .select("div.sourceset-depenent-content") + .fold(0) { acc, elem -> + acc + if (elem.child(0).html().contains( + Regex("Documentation for (expected|actual) class Clock .*") + ) + ) 1 else 0 + } == 3 + ) + } + } + } +} \ No newline at end of file diff --git a/plugins/base/src/test/kotlin/signatures/SignatureTest.kt b/plugins/base/src/test/kotlin/signatures/SignatureTest.kt new file mode 100644 index 00000000..fbdebfa2 --- /dev/null +++ b/plugins/base/src/test/kotlin/signatures/SignatureTest.kt @@ -0,0 +1,379 @@ +package signatures + +import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest +import org.jsoup.Jsoup +import org.junit.jupiter.api.Test +import utils.* + +class SignatureTest : AbstractCoreTest() { + + fun source(signature: String) = + """ + |/src/main/kotlin/test/Test.kt + |package example + | + | $signature + """.trimIndent() + + @Test + fun `fun`() { + + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/main/kotlin/test/Test.kt") + } + } + } + + val source = source("fun simpleFun(): String = \"Celebrimbor\"") + val writerPlugin = TestOutputWriterPlugin() + + testInline( + source, + configuration, + pluginOverrides = listOf(writerPlugin) + ) { + renderingStage = { _, _ -> + writerPlugin.writer.renderedContent("root/example/simple-fun.html").match( + "fun ", A("simpleFun"), "(): ", A("String"), Span() + ) + } + } + } + + @Test + fun `open fun`() { + + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/main/kotlin/test/Test.kt") + } + } + } + + val source = source("open fun simpleFun(): String = \"Celebrimbor\"") + val writerPlugin = TestOutputWriterPlugin() + + testInline( + source, + configuration, + pluginOverrides = listOf(writerPlugin) + ) { + renderingStage = { _, _ -> + writerPlugin.writer.renderedContent("root/example/simple-fun.html").match( + "open fun ", A("simpleFun"), "(): ", A("String"), Span() + ) + } + } + } + + @Test + fun `open suspend fun`() { + + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/main/kotlin/test/Test.kt") + } + } + } + + val source = source("open suspend fun simpleFun(): String = \"Celebrimbor\"") + val writerPlugin = TestOutputWriterPlugin() + + testInline( + source, + configuration, + pluginOverrides = listOf(writerPlugin) + ) { + renderingStage = { _, _ -> + writerPlugin.writer.renderedContent("root/example/simple-fun.html").match( + "open suspend fun ", A("simpleFun"), "(): ", A("String"), Span() + ) + } + } + } + + @Test + fun `fun with params`() { + + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/main/kotlin/test/Test.kt") + } + } + } + + val source = source("fun simpleFun(a: Int, b: Boolean, c: Any): String = \"Celebrimbor\"") + val writerPlugin = TestOutputWriterPlugin() + + testInline( + source, + configuration, + pluginOverrides = listOf(writerPlugin) + ) { + renderingStage = { _, _ -> + writerPlugin.writer.renderedContent("root/example/simple-fun.html").match( + "fun ", A("simpleFun"), "(a: ", A("Int"), + ", b: ", A("Boolean"), ", c: ", A("Any"), + "): ", A("String"), Span() + ) + } + } + } + + @Test + fun `fun with function param`() { + + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/main/kotlin/test/Test.kt") + } + } + } + + val source = source("fun simpleFun(a: (Int) -> String): String = \"Celebrimbor\"") + val writerPlugin = TestOutputWriterPlugin() + + testInline( + source, + configuration, + pluginOverrides = listOf(writerPlugin) + ) { + renderingStage = { _, _ -> + writerPlugin.writer.renderedContent("root/example/simple-fun.html").match( + "fun ", A("simpleFun"), "(a: (", A("Int"), + ") -> ", A("String"), "): ", A("String"), Span() + ) + } + } + } + + @Test + fun `fun with generic param`() { + + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/main/kotlin/test/Test.kt") + } + } + } + + val source = source("fun simpleFun(): T = \"Celebrimbor\" as T") + val writerPlugin = TestOutputWriterPlugin() + + testInline( + source, + configuration, + pluginOverrides = listOf(writerPlugin) + ) { + renderingStage = { _, _ -> + writerPlugin.writer.renderedContent("root/example/simple-fun.html").match( + "fun <", A("T"), " : ", A("Any"), "?> ", A("simpleFun"), "(): ", + A("T"), Span() + ) + } + } + } + + @Test + fun `fun with generic bounded param`() { + + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/main/kotlin/test/Test.kt") + } + } + } + + val source = source("fun simpleFun(): T = \"Celebrimbor\" as T") + val writerPlugin = TestOutputWriterPlugin() + + testInline( + source, + configuration, + pluginOverrides = listOf(writerPlugin) + ) { + renderingStage = { _, _ -> + writerPlugin.writer.renderedContent("root/example/simple-fun.html").match( + "fun <", A("T"), " : ", A("String"), "> ", A("simpleFun"), + "(): ", A("T"), Span() + ) + } + } + } + + @Test + fun `fun with keywords, params and generic bound`() { + + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/main/kotlin/test/Test.kt") + } + } + } + + val source = source("inline suspend fun simpleFun(a: Int, b: String): T = \"Celebrimbor\" as T") + val writerPlugin = TestOutputWriterPlugin() + + testInline( + source, + configuration, + pluginOverrides = listOf(writerPlugin) + ) { + renderingStage = { _, _ -> + writerPlugin.writer.renderedContent("root/example/simple-fun.html").match( + "inline suspend fun <", A("T"), " : ", A("String"), "> ", A("simpleFun"), + "(a: ", A("Int"), ", b: ", A("String"), "): ", A("T"), Span() + ) + } + } + } + + + @Test + fun `fun with annotation`() { + + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/main/kotlin/test/Test.kt") + } + } + } + + val source = """ + |/src/main/kotlin/test/Test.kt + |package example + | + | @MustBeDocumented() + | @Target(AnnotationTarget.FUNCTION) + | annotation class Marking + | + | @Marking() + | fun simpleFun(): String = "Celebrimbor" + """.trimIndent() + val writerPlugin = TestOutputWriterPlugin() + + testInline( + source, + configuration, + pluginOverrides = listOf(writerPlugin) + ) { + renderingStage = { _, _ -> + writerPlugin.writer.renderedContent("root/example/simple-fun.html").match( + Div( + Div("@", A("Marking"), "()") + ), + "fun ", A("simpleFun"), + "(): ", A("String"), Span() + ) + } + } + } + + @Test + fun `fun with two annotations`() { + + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/main/kotlin/test/Test.kt") + } + } + } + + val source = """ + |/src/main/kotlin/test/Test.kt + |package example + | + | @MustBeDocumented() + | @Target(AnnotationTarget.FUNCTION) + | annotation class Marking(val msg: String) + | + | @MustBeDocumented() + | @Target(AnnotationTarget.FUNCTION) + | annotation class Marking2(val int: Int) + | + | @Marking("Nenya") + | @Marking2(1) + | fun simpleFun(): String = "Celebrimbor" + """.trimIndent() + val writerPlugin = TestOutputWriterPlugin() + + testInline( + source, + configuration, + pluginOverrides = listOf(writerPlugin) + ) { + renderingStage = { _, _ -> + writerPlugin.writer.renderedContent("root/example/simple-fun.html") + .match( + Div( + Div("@", A("Marking"), "(", Span("msg = ", Span("\"Nenya\"")), Wbr, ")"), + Div("@", A("Marking2"), "(", Span("int = ", Span("1")), Wbr, ")") + ), + "fun ", A("simpleFun"), + "(): ", A("String"), Span() + ) + } + } + } + + @Test + fun `fun with annotation with array`() { + + val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/main/kotlin/test/Test.kt") + } + } + } + + val source = """ + |/src/main/kotlin/test/Test.kt + |package example + | + | @MustBeDocumented() + | @Target(AnnotationTarget.FUNCTION) + | annotation class Marking(val msg: Array) + | + | @Marking(["Nenya", "Vilya", "Narya"]) + | @Marking2(1) + | fun simpleFun(): String = "Celebrimbor" + """.trimIndent() + val writerPlugin = TestOutputWriterPlugin() + + testInline( + source, + configuration, + pluginOverrides = listOf(writerPlugin) + ) { + renderingStage = { _, _ -> + writerPlugin.writer.renderedContent("root/example/simple-fun.html").match( + Div( + Div("@", A("Marking"), "(", Span("msg = [", + Span(Span("\"Nenya\""), ", "), Wbr, + Span(Span("\"Vilya\""), ", "), Wbr, + Span(Span("\"Narya\"")), Wbr, "]"), Wbr, ")" + ) + ), + "fun ", A("simpleFun"), + "(): ", A("String"), Span() + ) + } + } + } + + private fun TestOutputWriter.renderedContent(path: String = "root/example.html") = + contents.getValue(path).let { Jsoup.parse(it) }.select("#content") + .single().select("div.symbol div.monospace").first() +} \ No newline at end of file diff --git a/plugins/base/src/test/kotlin/utils/JsoupUtils.kt b/plugins/base/src/test/kotlin/utils/JsoupUtils.kt new file mode 100644 index 00000000..e8c7838d --- /dev/null +++ b/plugins/base/src/test/kotlin/utils/JsoupUtils.kt @@ -0,0 +1,29 @@ +package utils + +import org.jsoup.nodes.Element +import org.jsoup.nodes.Node +import org.jsoup.nodes.TextNode + +fun Element.match(vararg matchers: Any): Unit = + childNodes() + .filter { it !is TextNode || it.text().isNotBlank() } + .let { it.drop(it.size - matchers.size) } + .zip(matchers) + .forEach { (n, m) -> m.accepts(n) } + +open class Tag(val name: String, vararg val matchers: Any) +class Div(vararg matchers: Any) : Tag("div", *matchers) +class P(vararg matchers: Any) : Tag("p", *matchers) +class Span(vararg matchers: Any) : Tag("span", *matchers) +class A(vararg matchers: Any) : Tag("a", *matchers) +object Wbr : Tag("wbr") +private fun Any.accepts(n: Node) { + when (this) { + is String -> assert(n is TextNode && n.text().trim() == this.trim()) { "\"$this\" expected but found: $n" } + is Tag -> { + assert(n is Element && n.tagName() == name) { "Tag $name expected but found: $n" } + if (n is Element && matchers.isNotEmpty()) n.match(*matchers) + } + else -> throw IllegalArgumentException("$this is not proper matcher") + } +} \ No newline at end of file diff --git a/plugins/base/src/test/kotlin/utils/TestUtils.kt b/plugins/base/src/test/kotlin/utils/TestUtils.kt index 44c23e96..bd0e1fe2 100644 --- a/plugins/base/src/test/kotlin/utils/TestUtils.kt +++ b/plugins/base/src/test/kotlin/utils/TestUtils.kt @@ -2,6 +2,7 @@ package utils import org.jetbrains.dokka.model.* import org.jetbrains.dokka.model.doc.* +import org.jetbrains.dokka.model.doc.P import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest import org.junit.jupiter.api.Assertions.assertTrue import kotlin.collections.orEmpty diff --git a/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/Clock.kt b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/Clock.kt index 9ec01fb6..4d27d0a3 100644 --- a/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/Clock.kt +++ b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/Clock.kt @@ -2,6 +2,9 @@ package example import greeteer.Greeter +/** + * Documentation for actual class Clock in JVM + */ actual open class Clock { actual fun getTime(): String = System.currentTimeMillis().toString() actual fun getTimesInMillis(): String = System.currentTimeMillis().toString() -- cgit From 36c4d0d3f815539517ce422e2192d9a5d2970b78 Mon Sep 17 00:00:00 2001 From: Andrzej Ratajczak Date: Tue, 7 Jul 2020 12:27:56 +0200 Subject: Add rendering signatures tests --- plugins/base/src/test/kotlin/markdown/LinkTest.kt | 1 + plugins/base/src/test/kotlin/model/PackagesTest.kt | 10 ++- .../kotlin/signatures/DivergentSignatureTest.kt | 96 ++++++++++++++++------ .../basicMultiplatformTest/jsMain/kotlin/Clock.kt | 7 ++ .../jvmMain/kotlin/example/Clock.kt | 4 + 5 files changed, 91 insertions(+), 27 deletions(-) (limited to 'plugins/base/src/test/resources/multiplatform/basicMultiplatformTest') diff --git a/plugins/base/src/test/kotlin/markdown/LinkTest.kt b/plugins/base/src/test/kotlin/markdown/LinkTest.kt index 8e4e588e..a6333c5a 100644 --- a/plugins/base/src/test/kotlin/markdown/LinkTest.kt +++ b/plugins/base/src/test/kotlin/markdown/LinkTest.kt @@ -49,6 +49,7 @@ class LinkTest : AbstractCoreTest() { sourceSets { sourceSet { sourceRoots = listOf("src/main/kotlin") + displayName = "JVM" } } } diff --git a/plugins/base/src/test/kotlin/model/PackagesTest.kt b/plugins/base/src/test/kotlin/model/PackagesTest.kt index c777ad05..4fc4d785 100644 --- a/plugins/base/src/test/kotlin/model/PackagesTest.kt +++ b/plugins/base/src/test/kotlin/model/PackagesTest.kt @@ -12,7 +12,15 @@ class PackagesTest : AbstractModelTest("/src/main/kotlin/packages/Test.kt", "pac """ | """.trimIndent(), - prependPackage = false + prependPackage = false, + configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/main/kotlin") + displayName = "JVM" + } + } + } ) { with((this / "[JVM root]").cast()) { name equals "[JVM root]" diff --git a/plugins/base/src/test/kotlin/signatures/DivergentSignatureTest.kt b/plugins/base/src/test/kotlin/signatures/DivergentSignatureTest.kt index 6ed17110..67a43725 100644 --- a/plugins/base/src/test/kotlin/signatures/DivergentSignatureTest.kt +++ b/plugins/base/src/test/kotlin/signatures/DivergentSignatureTest.kt @@ -2,6 +2,8 @@ package signatures import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest import org.jsoup.Jsoup +import org.jsoup.nodes.Element +import org.jsoup.select.Elements import org.junit.jupiter.api.Test import utils.* import java.nio.file.Paths @@ -9,11 +11,10 @@ import java.nio.file.Paths class DivergentSignatureTest : AbstractCoreTest() { @Test - fun `three divergent signatures for class`() { + fun `group { common + jvm + js }`() { val testDataDir = getTestDataDir("multiplatform/basicMultiplatformTest").toAbsolutePath() - val configuration = dokkaConfiguration { passes { pass { @@ -35,10 +36,10 @@ class DivergentSignatureTest : AbstractCoreTest() { pass { moduleName = "example" analysisPlatform = "common" - sourceRoots = listOf("jvmMain", "commonMain", "jvmAndJsSecondCommonMain").map { + sourceRoots = listOf("commonMain").map { Paths.get("$testDataDir/$it/kotlin").toString() } - sourceSetID = "jvm" + sourceSetID = "common" } } } @@ -50,26 +51,19 @@ class DivergentSignatureTest : AbstractCoreTest() { pluginOverrides = listOf(writerPlugin) ) { renderingStage = { _, _ -> - assert(writerPlugin.writer.contents.getValue("example/example/-clock/index.html") - .let { Jsoup.parse(it) }.select("#content").single() - .select("div.sourceset-depenent-content") - .fold(0) { acc, elem -> - acc + if (elem.child(0).html().contains( - Regex("Documentation for (expected|actual) class Clock .*") - ) - ) 1 else 0 - } == 3 - ) + val content = writerPlugin.renderedContent("example/example/-clock/get-time.html") + + assert(content.count() == 1) + assert(content.select("[data-filterable-current=js jvm common]").single().brief == "") } } } @Test - fun `three divergent signatures for class`() { + fun `group { common + jvm }, group { js }`() { val testDataDir = getTestDataDir("multiplatform/basicMultiplatformTest").toAbsolutePath() - val configuration = dokkaConfiguration { passes { pass { @@ -91,11 +85,60 @@ class DivergentSignatureTest : AbstractCoreTest() { pass { moduleName = "example" analysisPlatform = "common" + sourceRoots = listOf("commonMain").map { + Paths.get("$testDataDir/$it/kotlin").toString() + } + sourceSetID = "common" + } + } + } + + val writerPlugin = TestOutputWriterPlugin() + + testFromData( + configuration, + pluginOverrides = listOf(writerPlugin) + ) { + renderingStage = { _, _ -> + val content = writerPlugin.renderedContent("example/example/-clock/get-times-in-millis.html") + assert(content.count() == 2) + assert(content.select("[data-filterable-current=jvm common]").single().brief == "Time in minis") + assert(content.select("[data-filterable-current=js]").single().brief == "JS implementation of getTimeInMillis example/js" ) + } + } + } + + @Test + fun `group { js }, group { jvm }, group { js }`() { + + val testDataDir = getTestDataDir("multiplatform/basicMultiplatformTest").toAbsolutePath() + + val configuration = dokkaConfiguration { + passes { + pass { + moduleName = "example" + analysisPlatform = "js" + sourceRoots = listOf("jsMain", "commonMain", "jvmAndJsSecondCommonMain").map { + Paths.get("$testDataDir/$it/kotlin").toString() + } + sourceSetID = "js" + } + pass { + moduleName = "example" + analysisPlatform = "jvm" sourceRoots = listOf("jvmMain", "commonMain", "jvmAndJsSecondCommonMain").map { Paths.get("$testDataDir/$it/kotlin").toString() } sourceSetID = "jvm" } + pass { + moduleName = "example" + analysisPlatform = "common" + sourceRoots = listOf("commonMain").map { + Paths.get("$testDataDir/$it/kotlin").toString() + } + sourceSetID = "common" + } } } @@ -106,17 +149,18 @@ class DivergentSignatureTest : AbstractCoreTest() { pluginOverrides = listOf(writerPlugin) ) { renderingStage = { _, _ -> - assert(writerPlugin.writer.contents.getValue("example/example/-clock/index.html") - .let { Jsoup.parse(it) }.select("#content").single() - .select("div.sourceset-depenent-content") - .fold(0) { acc, elem -> - acc + if (elem.child(0).html().contains( - Regex("Documentation for (expected|actual) class Clock .*") - ) - ) 1 else 0 - } == 3 - ) + val content = writerPlugin.renderedContent("example/example/-clock/get-year.html") + assert(content.count() == 3) + assert(content.select("[data-filterable-current=jvm]").single().brief == "JVM custom kdoc example/jvm") + assert(content.select("[data-filterable-current=js]").single().brief == "JS custom kdoc example/js") + assert(content.select("[data-filterable-current=common]").single().brief == "example/common") } } } + + private fun TestOutputWriterPlugin.renderedContent(path: String) = writer.contents.getValue(path) + .let { Jsoup.parse(it) }.select("#content").single().select("div.divergent-group") + + private val Element.brief: String + get() = children().select(".brief-with-platform-tags").text() } \ No newline at end of file diff --git a/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jsMain/kotlin/Clock.kt b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jsMain/kotlin/Clock.kt index 967cffcd..51b8fdc6 100644 --- a/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jsMain/kotlin/Clock.kt +++ b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jsMain/kotlin/Clock.kt @@ -9,8 +9,15 @@ import kotlin.js.Date actual open class Clock { actual fun getTime() = Date.now().toString() fun onlyJsFunction(): Int = 42 + + /** + * JS implementation of getTimeInMillis + */ actual fun getTimesInMillis(): String = Date.now().toString() + /** + * JS custom kdoc + */ actual fun getYear(): String { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } diff --git a/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/Clock.kt b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/Clock.kt index 4d27d0a3..fec06207 100644 --- a/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/Clock.kt +++ b/plugins/base/src/test/resources/multiplatform/basicMultiplatformTest/jvmMain/kotlin/example/Clock.kt @@ -25,6 +25,10 @@ actual open class Clock { open fun getDayOfTheWeek(): String { TODO("not implemented") } + + /** + * JVM custom kdoc + */ actual fun getYear(): String { TODO("not implemented") } -- cgit