aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/base/src')
-rw-r--r--plugins/base/src/test/kotlin/signatures/SignatureTest.kt7
-rw-r--r--plugins/base/src/test/kotlin/signatures/SignatureUtils.kt12
-rw-r--r--plugins/base/src/test/kotlin/signatures/VarianceSignatureTest.kt101
3 files changed, 113 insertions, 7 deletions
diff --git a/plugins/base/src/test/kotlin/signatures/SignatureTest.kt b/plugins/base/src/test/kotlin/signatures/SignatureTest.kt
index 52211998..1c3842c4 100644
--- a/plugins/base/src/test/kotlin/signatures/SignatureTest.kt
+++ b/plugins/base/src/test/kotlin/signatures/SignatureTest.kt
@@ -494,11 +494,4 @@ class SignatureTest : AbstractCoreTest() {
}
}
}
-
- private fun TestOutputWriter.renderedContent(path: String = "root/example.html") =
- contents.getValue(path).let { Jsoup.parse(it) }.select("#content")
- .single()
-
- private fun Element.signature() = select("div.symbol.monospace")
- private fun Element.firstSignature() = signature().first()
}
diff --git a/plugins/base/src/test/kotlin/signatures/SignatureUtils.kt b/plugins/base/src/test/kotlin/signatures/SignatureUtils.kt
new file mode 100644
index 00000000..e77b8757
--- /dev/null
+++ b/plugins/base/src/test/kotlin/signatures/SignatureUtils.kt
@@ -0,0 +1,12 @@
+package signatures
+
+import org.jsoup.Jsoup
+import org.jsoup.nodes.Element
+import utils.TestOutputWriter
+
+fun TestOutputWriter.renderedContent(path: String = "root/example.html") =
+ contents.getValue(path).let { Jsoup.parse(it) }.select("#content")
+ .single()
+
+fun Element.signature() = select("div.symbol.monospace")
+fun Element.firstSignature() = signature().first() \ No newline at end of file
diff --git a/plugins/base/src/test/kotlin/signatures/VarianceSignatureTest.kt b/plugins/base/src/test/kotlin/signatures/VarianceSignatureTest.kt
new file mode 100644
index 00000000..c58e6e85
--- /dev/null
+++ b/plugins/base/src/test/kotlin/signatures/VarianceSignatureTest.kt
@@ -0,0 +1,101 @@
+package signatures
+
+import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest
+import org.junit.jupiter.api.Test
+import utils.A
+import utils.Span
+import utils.TestOutputWriterPlugin
+import utils.match
+
+class VarianceSignatureTest : AbstractCoreTest() {
+ private val configuration = dokkaConfiguration {
+ sourceSets {
+ sourceSet {
+ sourceRoots = listOf("src/")
+ classpath = listOf(commonStdlibPath!!)
+ externalDocumentationLinks = listOf(stdlibExternalDocumentationLink)
+ }
+ }
+ }
+
+ fun source(signature: String) =
+ """
+ |/src/main/kotlin/test/Test.kt
+ |package example
+ |
+ | $signature
+ """.trimIndent()
+
+ @Test
+ fun `simple contravariance`() {
+ val source = source("class Generic<in T>")
+ val writerPlugin = TestOutputWriterPlugin()
+
+ testInline(
+ source,
+ configuration,
+ pluginOverrides = listOf(writerPlugin)
+ ) {
+ renderingStage = { _, _ ->
+ writerPlugin.writer.renderedContent("root/example/-generic/index.html").firstSignature().match(
+ "class ", A("Generic"), "<in ", A("T"), ">", Span()
+ )
+ }
+ }
+ }
+
+ @Test
+ fun `simple covariance`() {
+ val source = source("class Generic<out T>")
+ val writerPlugin = TestOutputWriterPlugin()
+
+ testInline(
+ source,
+ configuration,
+ pluginOverrides = listOf(writerPlugin)
+ ) {
+ renderingStage = { _, _ ->
+ writerPlugin.writer.renderedContent("root/example/-generic/index.html").firstSignature().match(
+ "class ", A("Generic"), "<out ", A("T"), ">", Span()
+ )
+ }
+ }
+ }
+
+ @Test
+ fun `simple invariance`() {
+ val source = source("class Generic<T>")
+ val writerPlugin = TestOutputWriterPlugin()
+
+ testInline(
+ source,
+ configuration,
+ pluginOverrides = listOf(writerPlugin)
+ ) {
+ renderingStage = { _, _ ->
+ writerPlugin.writer.renderedContent("root/example/-generic/index.html").firstSignature().match(
+ "class ", A("Generic"), "<", A("T"), ">", Span()
+ )
+ }
+ }
+ }
+
+ @Test
+ fun `covariance and bound`() {
+ val source = source("class Generic<out T : List<CharSequence>>")
+ val writerPlugin = TestOutputWriterPlugin()
+
+ testInline(
+ source,
+ configuration,
+ pluginOverrides = listOf(writerPlugin)
+ ) {
+ renderingStage = { _, _ ->
+ writerPlugin.writer.renderedContent("root/example/-generic/index.html").firstSignature().match(
+ "class ", A("Generic"), "<out ", A("T"), ":", A("List"), "<", A("CharSequence"), ">>", Span()
+ )
+ }
+ }
+ }
+}
+