diff options
author | Vadim Mishenev <vad-mishenev@yandex.ru> | 2022-04-28 15:20:43 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-28 15:20:43 +0300 |
commit | 4451b8e546584da389da60f73b56ce25d6ac2eaa (patch) | |
tree | fe9c2b8772bad7d8970c85c3144bad0803ca00f6 /plugins/base/src/test/kotlin | |
parent | 2e88c6f70feff1edb9f386110a071df897f3b319 (diff) | |
download | dokka-4451b8e546584da389da60f73b56ce25d6ac2eaa.tar.gz dokka-4451b8e546584da389da60f73b56ce25d6ac2eaa.tar.bz2 dokka-4451b8e546584da389da60f73b56ce25d6ac2eaa.zip |
Make a default value dependent on source set (#2449)
* Make a default value dependent on source set
* Get a default value from an expect source set
* Fix default value for expect properties
* Deprecate `DefaultValue.value`
* Add test
* Refactor
* Reformat
Diffstat (limited to 'plugins/base/src/test/kotlin')
-rw-r--r-- | plugins/base/src/test/kotlin/model/FunctionsTest.kt | 4 | ||||
-rw-r--r-- | plugins/base/src/test/kotlin/signatures/SignatureTest.kt | 95 |
2 files changed, 58 insertions, 41 deletions
diff --git a/plugins/base/src/test/kotlin/model/FunctionsTest.kt b/plugins/base/src/test/kotlin/model/FunctionsTest.kt index 29c81a65..fa65a477 100644 --- a/plugins/base/src/test/kotlin/model/FunctionsTest.kt +++ b/plugins/base/src/test/kotlin/model/FunctionsTest.kt @@ -344,7 +344,7 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun parameters.forEach { p -> p.name equals "x" p.type.name.assertNotNull("Parameter type: ") equals "String" - p.extra[DefaultValue]?.value equals StringConstant("") + p.extra[DefaultValue]?.expression?.get(sourceSets.single()) equals StringConstant("") } } } @@ -363,7 +363,7 @@ class FunctionTest : AbstractModelTest("/src/main/kotlin/function/Test.kt", "fun parameters.forEach { p -> p.name equals "x" p.type.name.assertNotNull("Parameter type: ") equals "Float" - p.extra[DefaultValue]?.value equals FloatConstant(3.14f) + p.extra[DefaultValue]?.expression?.get(sourceSets.single()) equals FloatConstant(3.14f) } } } diff --git a/plugins/base/src/test/kotlin/signatures/SignatureTest.kt b/plugins/base/src/test/kotlin/signatures/SignatureTest.kt index c290846e..3895eede 100644 --- a/plugins/base/src/test/kotlin/signatures/SignatureTest.kt +++ b/plugins/base/src/test/kotlin/signatures/SignatureTest.kt @@ -17,6 +17,25 @@ class SignatureTest : BaseAbstractTest() { } } + private val mppConfiguration = dokkaConfiguration { + moduleName = "test" + sourceSets { + sourceSet { + name = "common" + sourceRoots = listOf("src/main/kotlin/common/Test.kt") + classpath = listOf(commonStdlibPath!!) + externalDocumentationLinks = listOf(stdlibExternalDocumentationLink) + } + sourceSet { + name = "jvm" + dependentSourceSets = setOf(DokkaSourceSetID("test", "common")) + sourceRoots = listOf("src/main/kotlin/jvm/Test.kt") + classpath = listOf(commonStdlibPath!!) + externalDocumentationLinks = listOf(stdlibExternalDocumentationLink) + } + } + } + fun source(signature: String) = """ |/src/main/kotlin/test/Test.kt @@ -419,26 +438,6 @@ class SignatureTest : BaseAbstractTest() { @Test fun `actual fun`() { - - val configuration = dokkaConfiguration { - moduleName = "test" - sourceSets { - sourceSet { - name = "common" - sourceRoots = listOf("src/main/kotlin/common/Test.kt") - classpath = listOf(commonStdlibPath!!) - externalDocumentationLinks = listOf(stdlibExternalDocumentationLink) - } - sourceSet { - name = "jvm" - dependentSourceSets = setOf(DokkaSourceSetID("test", "common")) - sourceRoots = listOf("src/main/kotlin/jvm/Test.kt") - classpath = listOf(commonStdlibPath!!) - externalDocumentationLinks = listOf(stdlibExternalDocumentationLink) - } - } - } - val writerPlugin = TestOutputWriterPlugin() testInline( @@ -454,7 +453,7 @@ class SignatureTest : BaseAbstractTest() { |actual fun simpleFun(): String = "Celebrimbor" | """.trimMargin(), - configuration, + mppConfiguration, pluginOverrides = listOf(writerPlugin) ) { renderingStage = { _, _ -> @@ -475,27 +474,45 @@ class SignatureTest : BaseAbstractTest() { } @Test - fun `type with an actual typealias`() { + fun `actual property with a default value`() { + val writerPlugin = TestOutputWriterPlugin() - val configuration = dokkaConfiguration { - moduleName = "test" - sourceSets { - sourceSet { - name = "common" - sourceRoots = listOf("src/main/kotlin/common/Test.kt") - classpath = listOf(commonStdlibPath!!) - externalDocumentationLinks = listOf(stdlibExternalDocumentationLink) - } - sourceSet { - name = "jvm" - dependentSourceSets = setOf(DokkaSourceSetID("test", "common")) - sourceRoots = listOf("src/main/kotlin/jvm/Test.kt") - classpath = listOf(commonStdlibPath!!) - externalDocumentationLinks = listOf(stdlibExternalDocumentationLink) - } + testInline( + """ + |/src/main/kotlin/common/Test.kt + |package example + | + |expect val prop: Int + | + |/src/main/kotlin/jvm/Test.kt + |package example + | + |actual val prop: Int = 2 + | + """.trimMargin(), + mppConfiguration, + pluginOverrides = listOf(writerPlugin) + ) { + renderingStage = { _, _ -> + val signatures = writerPlugin.writer.renderedContent("test/example/prop.html").signature().toList() + + signatures[0].match( + "expect val ", A("prop"), + ": ", A("Int"), Span(), + ignoreSpanWithTokenStyle = true + ) + signatures[1].match( + "actual val ", A("prop"), + ": ", A("Int"), + " = 2", Span(), + ignoreSpanWithTokenStyle = true + ) } } + } + @Test + fun `type with an actual typealias`() { val writerPlugin = TestOutputWriterPlugin() testInline( @@ -512,7 +529,7 @@ class SignatureTest : BaseAbstractTest() { |actual typealias Foo = Bar | """.trimMargin(), - configuration, + mppConfiguration, pluginOverrides = listOf(writerPlugin) ) { renderingStage = { _, _ -> |