aboutsummaryrefslogtreecommitdiff
path: root/core/src/test/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/test/kotlin')
-rw-r--r--core/src/test/kotlin/TestAPI.kt61
-rw-r--r--core/src/test/kotlin/format/GFMFormatTest.kt2
-rw-r--r--core/src/test/kotlin/format/HtmlFormatTest.kt6
-rw-r--r--core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt2
-rw-r--r--core/src/test/kotlin/format/KotlinWebSiteRunnableSamplesFormatTest.kt2
-rw-r--r--core/src/test/kotlin/format/MarkdownFormatTest.kt74
-rw-r--r--core/src/test/kotlin/model/ClassTest.kt12
-rw-r--r--core/src/test/kotlin/model/FunctionTest.kt12
-rw-r--r--core/src/test/kotlin/model/PropertyTest.kt12
-rw-r--r--core/src/test/kotlin/model/TypeAliasTest.kt9
10 files changed, 159 insertions, 33 deletions
diff --git a/core/src/test/kotlin/TestAPI.kt b/core/src/test/kotlin/TestAPI.kt
index 7197d2c4..09a346cf 100644
--- a/core/src/test/kotlin/TestAPI.kt
+++ b/core/src/test/kotlin/TestAPI.kt
@@ -5,13 +5,14 @@ import com.intellij.openapi.application.PathManager
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.util.io.FileUtil
import org.jetbrains.dokka.*
-import org.jetbrains.dokka.Utilities.DokkaModule
+import org.jetbrains.dokka.Utilities.DokkaAnalysisModule
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot
import org.jetbrains.kotlin.config.ContentRoot
import org.jetbrains.kotlin.config.KotlinSourceRoot
+import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.junit.Assert
import org.junit.Assert.fail
import java.io.File
@@ -22,6 +23,30 @@ fun verifyModel(vararg roots: ContentRoot,
format: String = "html",
includeNonPublic: Boolean = true,
verifier: (DocumentationModule) -> Unit) {
+ val documentation = DocumentationModule("test")
+
+ val options = DocumentationOptions("", format,
+ includeNonPublic = includeNonPublic,
+ skipEmptyPackages = false,
+ includeRootPackage = true,
+ sourceLinks = listOf<SourceLinkDefinition>(),
+ generateIndexPages = false)
+
+ appendDocumentation(documentation, *roots,
+ withJdk = withJdk,
+ withKotlinRuntime = withKotlinRuntime,
+ options = options)
+ documentation.prepareForGeneration(options)
+
+ verifier(documentation)
+}
+
+fun appendDocumentation(documentation: DocumentationModule,
+ vararg roots: ContentRoot,
+ withJdk: Boolean = false,
+ withKotlinRuntime: Boolean = false,
+ options: DocumentationOptions,
+ defaultPlatforms: List<String> = emptyList()) {
val messageCollector = object : MessageCollector {
override fun clear() {
@@ -60,14 +85,12 @@ fun verifyModel(vararg roots: ContentRoot,
}
addRoots(roots.toList())
}
- val options = DocumentationOptions("", format,
- includeNonPublic = includeNonPublic,
- skipEmptyPackages = false,
- sourceLinks = listOf<SourceLinkDefinition>(),
- generateIndexPages = false)
- val injector = Guice.createInjector(DokkaModule(environment, options, DokkaConsoleLogger))
- val documentation = buildDocumentationModule(injector, "test")
- verifier(documentation)
+ val defaultPlatformsProvider = object : DefaultPlatformsProvider {
+ override fun getDefaultPlatforms(descriptor: DeclarationDescriptor) = defaultPlatforms
+ }
+ val injector = Guice.createInjector(
+ DokkaAnalysisModule(environment, options, defaultPlatformsProvider, documentation.nodeRefGraph, DokkaConsoleLogger))
+ buildDocumentationModule(injector, documentation)
Disposer.dispose(environment)
}
@@ -128,19 +151,23 @@ fun verifyOutput(roots: Array<ContentRoot>,
format: String = "html",
outputGenerator: (DocumentationModule, StringBuilder) -> Unit) {
verifyModel(*roots, withJdk = withJdk, withKotlinRuntime = withKotlinRuntime, format = format) {
- verifyModelOutput(it, outputExtension, outputGenerator, roots.first().path)
+ verifyModelOutput(it, outputExtension, roots.first().path, outputGenerator)
}
}
-private fun verifyModelOutput(it: DocumentationModule,
- outputExtension: String,
- outputGenerator: (DocumentationModule, StringBuilder) -> Unit,
- sourcePath: String) {
+fun verifyModelOutput(it: DocumentationModule,
+ outputExtension: String,
+ sourcePath: String,
+ outputGenerator: (DocumentationModule, StringBuilder) -> Unit) {
val output = StringBuilder()
outputGenerator(it, output)
val ext = outputExtension.removePrefix(".")
- val path = sourcePath
- val expectedOutput = File(path.replaceAfterLast(".", ext, path + "." + ext)).readText()
+ val expectedFileContent = File(sourcePath.replaceAfterLast(".", ext, sourcePath + "." + ext)).readText()
+ val expectedOutput =
+ if (ext.equals("html", true))
+ expectedFileContent.lines().joinToString(separator = "\n", transform = String::trim)
+ else
+ expectedFileContent
assertEqualsIgnoringSeparators(expectedOutput, output.toString())
}
@@ -158,7 +185,7 @@ fun verifyJavaOutput(path: String,
withKotlinRuntime: Boolean = false,
outputGenerator: (DocumentationModule, StringBuilder) -> Unit) {
verifyJavaModel(path, withKotlinRuntime) { model ->
- verifyModelOutput(model, outputExtension, outputGenerator, path)
+ verifyModelOutput(model, outputExtension, path, outputGenerator)
}
}
diff --git a/core/src/test/kotlin/format/GFMFormatTest.kt b/core/src/test/kotlin/format/GFMFormatTest.kt
index 5327c9dc..c097c5c8 100644
--- a/core/src/test/kotlin/format/GFMFormatTest.kt
+++ b/core/src/test/kotlin/format/GFMFormatTest.kt
@@ -5,7 +5,7 @@ import org.jetbrains.dokka.KotlinLanguageService
import org.junit.Test
class GFMFormatTest {
- private val gfmService = GFMFormatService(InMemoryLocationService, KotlinLanguageService())
+ private val gfmService = GFMFormatService(InMemoryLocationService, KotlinLanguageService(), listOf())
@Test fun sample() {
verifyGFMNodeByName("sample", "Foo")
diff --git a/core/src/test/kotlin/format/HtmlFormatTest.kt b/core/src/test/kotlin/format/HtmlFormatTest.kt
index 4b4eff59..221ee811 100644
--- a/core/src/test/kotlin/format/HtmlFormatTest.kt
+++ b/core/src/test/kotlin/format/HtmlFormatTest.kt
@@ -7,7 +7,7 @@ import org.junit.Test
import java.io.File
class HtmlFormatTest {
- private val htmlService = HtmlFormatService(InMemoryLocationService, KotlinLanguageService(), HtmlTemplateService.default())
+ private val htmlService = HtmlFormatService(InMemoryLocationService, KotlinLanguageService(), HtmlTemplateService.default(), listOf())
@Test fun classWithCompanionObject() {
verifyHtmlNode("classWithCompanionObject")
@@ -138,6 +138,10 @@ class HtmlFormatTest {
verifyHtmlNode("functionalTypeWithNamedParameters")
}
+ @Test fun sinceKotlin() {
+ verifyHtmlNode("sinceKotlin")
+ }
+
private fun verifyHtmlNode(fileName: String, withKotlinRuntime: Boolean = false) {
verifyHtmlNodes(fileName, withKotlinRuntime) { model -> model.members.single().members }
}
diff --git a/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt
index 3363b0a3..27c84aca 100644
--- a/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt
+++ b/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt
@@ -5,7 +5,7 @@ import org.jetbrains.dokka.KotlinWebsiteFormatService
import org.junit.Test
class KotlinWebSiteFormatTest {
- private val kwsService = KotlinWebsiteFormatService(InMemoryLocationService, KotlinLanguageService())
+ private val kwsService = KotlinWebsiteFormatService(InMemoryLocationService, KotlinLanguageService(), listOf())
@Test fun sample() {
verifyKWSNodeByName("sample", "foo")
diff --git a/core/src/test/kotlin/format/KotlinWebSiteRunnableSamplesFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteRunnableSamplesFormatTest.kt
index 2a9900af..3e46ead7 100644
--- a/core/src/test/kotlin/format/KotlinWebSiteRunnableSamplesFormatTest.kt
+++ b/core/src/test/kotlin/format/KotlinWebSiteRunnableSamplesFormatTest.kt
@@ -5,7 +5,7 @@ import org.jetbrains.dokka.KotlinWebsiteRunnableSamplesFormatService
import org.junit.Test
class KotlinWebSiteRunnableSamplesFormatTest {
- private val kwsService = KotlinWebsiteRunnableSamplesFormatService(InMemoryLocationService, KotlinLanguageService())
+ private val kwsService = KotlinWebsiteRunnableSamplesFormatService(InMemoryLocationService, KotlinLanguageService(), listOf())
@Test fun dropImport() {
diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt
index c425e3f6..34870ce7 100644
--- a/core/src/test/kotlin/format/MarkdownFormatTest.kt
+++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt
@@ -1,14 +1,10 @@
package org.jetbrains.dokka.tests
-import org.jetbrains.dokka.DocumentationModule
-import org.jetbrains.dokka.DocumentationNode
-import org.jetbrains.dokka.KotlinLanguageService
-import org.jetbrains.dokka.MarkdownFormatService
-import org.junit.Ignore
+import org.jetbrains.dokka.*
import org.junit.Test
class MarkdownFormatTest {
- private val markdownService = MarkdownFormatService(InMemoryLocationService, KotlinLanguageService())
+ private val markdownService = MarkdownFormatService(InMemoryLocationService, KotlinLanguageService(), listOf())
@Test fun emptyDescription() {
verifyMarkdownNode("emptyDescription")
@@ -236,6 +232,72 @@ class MarkdownFormatTest {
verifyMarkdownPackage("typeAliases")
}
+ @Test fun suspendParam() {
+ verifyMarkdownNode("suspendParam")
+ verifyMarkdownPackage("suspendParam")
+ }
+
+ @Test fun sinceKotlin() {
+ verifyMarkdownNode("sinceKotlin")
+ verifyMarkdownPackage("sinceKotlin")
+ }
+
+ @Test fun dynamicType() {
+ verifyMarkdownNode("dynamicType")
+ }
+
+ @Test fun dynamicExtension() {
+ verifyMarkdownNodes("dynamicExtension") { model -> model.members.single().members.filter { it.name == "Foo" } }
+ }
+
+ @Test fun memberExtension() {
+ verifyMarkdownNodes("memberExtension") { model -> model.members.single().members.filter { it.name == "Foo" } }
+ }
+
+ @Test fun multiplePlatforms() {
+ verifyMultiplatformPackage(buildMultiplePlatforms("multiplatform"), "multiplatform")
+ }
+
+ @Test fun multiplePlatformsMerge() {
+ verifyMultiplatformPackage(buildMultiplePlatforms("multiplatformMerge"), "multiplatformMerge")
+ }
+
+ @Test fun multiplePlatformsMergeMembers() {
+ val module = buildMultiplePlatforms("multiplatformMergeMembers")
+ verifyModelOutput(module, ".md", "testdata/format/multiplatformMergeMembers/foo.kt") { model, output ->
+ markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members)
+ }
+ }
+
+ @Test fun multiplePlatformsOmitRedundant() {
+ val module = buildMultiplePlatforms("multiplatformOmitRedundant")
+ verifyModelOutput(module, ".md", "testdata/format/multiplatformOmitRedundant/foo.kt") { model, output ->
+ markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members)
+ }
+ }
+
+ @Test fun multiplePlatformsImplied() {
+ val module = buildMultiplePlatforms("multiplatformImplied")
+ verifyModelOutput(module, ".md", "testdata/format/multiplatformImplied/foo.kt") { model, output ->
+ MarkdownFormatService(InMemoryLocationService, KotlinLanguageService(), listOf("JVM", "JS"))
+ .createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members)
+ }
+ }
+
+ private fun buildMultiplePlatforms(path: String): DocumentationModule {
+ val module = DocumentationModule("test")
+ val options = DocumentationOptions("", "html", generateIndexPages = false)
+ appendDocumentation(module, contentRootFromPath("testdata/format/$path/jvm.kt"), defaultPlatforms = listOf("JVM"), options = options)
+ appendDocumentation(module, contentRootFromPath("testdata/format/$path/js.kt"), defaultPlatforms = listOf("JS"), options = options)
+ return module
+ }
+
+ private fun verifyMultiplatformPackage(module: DocumentationModule, path: String) {
+ verifyModelOutput(module, ".package.md", "testdata/format/$path/multiplatform.kt") { model, output ->
+ markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members)
+ }
+ }
+
private fun verifyMarkdownPackage(fileName: String, withKotlinRuntime: Boolean = false) {
verifyOutput("testdata/format/$fileName.kt", ".package.md", withKotlinRuntime = withKotlinRuntime) { model, output ->
markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members)
diff --git a/core/src/test/kotlin/model/ClassTest.kt b/core/src/test/kotlin/model/ClassTest.kt
index d50a3624..fb225728 100644
--- a/core/src/test/kotlin/model/ClassTest.kt
+++ b/core/src/test/kotlin/model/ClassTest.kt
@@ -3,11 +3,11 @@ package org.jetbrains.dokka.tests
import org.jetbrains.dokka.Content
import org.jetbrains.dokka.NodeKind
import org.jetbrains.dokka.RefKind
-import org.junit.Test
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
+import org.junit.Test
-public class ClassTest {
+class ClassTest {
@Test fun emptyClass() {
verifyModel("testdata/classes/emptyClass.kt") { model ->
with(model.members.single().members.single()) {
@@ -272,4 +272,12 @@ public class ClassTest {
}
}
}
+
+ @Test fun sinceKotlin() {
+ verifyModel("testdata/classes/sinceKotlin.kt") { model ->
+ with(model.members.single().members.single()) {
+ assertEquals(listOf("Kotlin 1.1"), platforms)
+ }
+ }
+ }
}
diff --git a/core/src/test/kotlin/model/FunctionTest.kt b/core/src/test/kotlin/model/FunctionTest.kt
index 4cced562..ddd33941 100644
--- a/core/src/test/kotlin/model/FunctionTest.kt
+++ b/core/src/test/kotlin/model/FunctionTest.kt
@@ -2,11 +2,11 @@ package org.jetbrains.dokka.tests
import org.jetbrains.dokka.Content
import org.jetbrains.dokka.NodeKind
-import org.junit.Test
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
+import org.junit.Test
-public class FunctionTest {
+class FunctionTest {
@Test fun function() {
verifyModel("testdata/functions/function.kt") { model ->
with(model.members.single().members.single()) {
@@ -224,4 +224,12 @@ Documentation""", content.description.toTestString())
}
}
}
+
+ @Test fun sinceKotlin() {
+ verifyModel("testdata/functions/sinceKotlin.kt") { model ->
+ with(model.members.single().members.single()) {
+ assertEquals(listOf("Kotlin 1.1"), platforms)
+ }
+ }
+ }
}
diff --git a/core/src/test/kotlin/model/PropertyTest.kt b/core/src/test/kotlin/model/PropertyTest.kt
index cdf44c03..0ee0e0f5 100644
--- a/core/src/test/kotlin/model/PropertyTest.kt
+++ b/core/src/test/kotlin/model/PropertyTest.kt
@@ -3,11 +3,11 @@ package org.jetbrains.dokka.tests
import org.jetbrains.dokka.Content
import org.jetbrains.dokka.NodeKind
import org.jetbrains.dokka.RefKind
-import org.junit.Test
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
+import org.junit.Test
-public class PropertyTest {
+class PropertyTest {
@Test fun valueProperty() {
verifyModel("testdata/properties/valueProperty.kt") { model ->
with(model.members.single().members.single()) {
@@ -100,4 +100,12 @@ public class PropertyTest {
}
}
}
+
+ @Test fun sinceKotlin() {
+ verifyModel("testdata/properties/sinceKotlin.kt") { model ->
+ with(model.members.single().members.single()) {
+ assertEquals(listOf("Kotlin 1.1"), platforms)
+ }
+ }
+ }
}
diff --git a/core/src/test/kotlin/model/TypeAliasTest.kt b/core/src/test/kotlin/model/TypeAliasTest.kt
index 812fd9dc..c653ac83 100644
--- a/core/src/test/kotlin/model/TypeAliasTest.kt
+++ b/core/src/test/kotlin/model/TypeAliasTest.kt
@@ -120,4 +120,13 @@ class TypeAliasTest {
}
}
}
+
+ @Test
+ fun sinceKotlin() {
+ verifyModel("testdata/typealias/sinceKotlin.kt") { model ->
+ with(model.members.single().members.single()) {
+ assertEquals(listOf("Kotlin 1.1"), platforms)
+ }
+ }
+ }
} \ No newline at end of file