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.kt35
-rw-r--r--core/src/test/kotlin/format/HtmlFormatTest.kt4
-rw-r--r--core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt9
-rw-r--r--core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt9
-rw-r--r--core/src/test/kotlin/format/MarkdownFormatTest.kt69
-rw-r--r--core/src/test/kotlin/javadoc/JavadocTest.kt10
-rw-r--r--core/src/test/kotlin/model/FunctionTest.kt14
-rw-r--r--core/src/test/kotlin/model/PackageTest.kt35
8 files changed, 163 insertions, 22 deletions
diff --git a/core/src/test/kotlin/TestAPI.kt b/core/src/test/kotlin/TestAPI.kt
index a1a98ec7..ff8a5260 100644
--- a/core/src/test/kotlin/TestAPI.kt
+++ b/core/src/test/kotlin/TestAPI.kt
@@ -24,17 +24,24 @@ fun verifyModel(vararg roots: ContentRoot,
withKotlinRuntime: Boolean = false,
format: String = "html",
includeNonPublic: Boolean = true,
+ perPackageOptions: List<DokkaConfiguration.PackageOptions> = emptyList(),
verifier: (DocumentationModule) -> Unit) {
val documentation = DocumentationModule("test")
- val options = DocumentationOptions("", format,
+ val options = DocumentationOptions(
+ "",
+ format,
includeNonPublic = includeNonPublic,
skipEmptyPackages = false,
includeRootPackage = true,
- sourceLinks = listOf<SourceLinkDefinition>(),
+ sourceLinks = listOf(),
+ perPackageOptions = perPackageOptions,
generateIndexPages = false,
noStdlibLink = true,
- cacheRoot = "default")
+ cacheRoot = "default",
+ languageVersion = null,
+ apiVersion = null
+ )
appendDocumentation(documentation, *roots,
withJdk = withJdk,
@@ -86,6 +93,8 @@ fun appendDocumentation(documentation: DocumentationModule,
addClasspath(File(kotlinStrictfpRoot))
}
addRoots(roots.toList())
+
+ loadLanguageVersionSettings(options.languageVersion, options.apiVersion)
}
val defaultPlatformsProvider = object : DefaultPlatformsProvider {
override fun getDefaultPlatforms(descriptor: DeclarationDescriptor) = defaultPlatforms
@@ -151,8 +160,15 @@ fun verifyOutput(roots: Array<ContentRoot>,
withJdk: Boolean = false,
withKotlinRuntime: Boolean = false,
format: String = "html",
+ includeNonPublic: Boolean = true,
outputGenerator: (DocumentationModule, StringBuilder) -> Unit) {
- verifyModel(*roots, withJdk = withJdk, withKotlinRuntime = withKotlinRuntime, format = format) {
+ verifyModel(
+ *roots,
+ withJdk = withJdk,
+ withKotlinRuntime = withKotlinRuntime,
+ format = format,
+ includeNonPublic = includeNonPublic
+ ) {
verifyModelOutput(it, outputExtension, roots.first().path, outputGenerator)
}
}
@@ -173,8 +189,17 @@ fun verifyOutput(path: String,
withJdk: Boolean = false,
withKotlinRuntime: Boolean = false,
format: String = "html",
+ includeNonPublic: Boolean = true,
outputGenerator: (DocumentationModule, StringBuilder) -> Unit) {
- verifyOutput(arrayOf(contentRootFromPath(path)), outputExtension, withJdk, withKotlinRuntime, format, outputGenerator)
+ verifyOutput(
+ arrayOf(contentRootFromPath(path)),
+ outputExtension,
+ withJdk,
+ withKotlinRuntime,
+ format,
+ includeNonPublic,
+ outputGenerator
+ )
}
fun verifyJavaOutput(path: String,
diff --git a/core/src/test/kotlin/format/HtmlFormatTest.kt b/core/src/test/kotlin/format/HtmlFormatTest.kt
index 4fe4f6ab..01e4559e 100644
--- a/core/src/test/kotlin/format/HtmlFormatTest.kt
+++ b/core/src/test/kotlin/format/HtmlFormatTest.kt
@@ -146,6 +146,10 @@ class HtmlFormatTest {
verifyHtmlNode("blankLineInsideCodeBlock")
}
+ @Test fun indentedCodeBlock() {
+ verifyHtmlNode("indentedCodeBlock")
+ }
+
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 f4ca2982..af44b048 100644
--- a/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt
+++ b/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt
@@ -42,7 +42,14 @@ class KotlinWebSiteFormatTest {
private fun buildMultiplePlatforms(path: String): DocumentationModule {
val module = DocumentationModule("test")
- val options = DocumentationOptions("", "html", generateIndexPages = false, noStdlibLink = true)
+ val options = DocumentationOptions(
+ outputDir = "",
+ outputFormat = "html",
+ generateIndexPages = false,
+ noStdlibLink = true,
+ languageVersion = null,
+ apiVersion = null
+ )
appendDocumentation(module, contentRootFromPath("testdata/format/website/$path/jvm.kt"), defaultPlatforms = listOf("JVM"), options = options)
appendDocumentation(module, contentRootFromPath("testdata/format/website/$path/jre7.kt"), defaultPlatforms = listOf("JVM", "JRE7"), options = options)
appendDocumentation(module, contentRootFromPath("testdata/format/website/$path/js.kt"), defaultPlatforms = listOf("JS"), options = options)
diff --git a/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt
index b4b133f4..433c9c13 100644
--- a/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt
+++ b/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt
@@ -57,7 +57,14 @@ class KotlinWebSiteHtmlFormatTest {
private fun buildMultiplePlatforms(path: String): DocumentationModule {
val module = DocumentationModule("test")
- val options = DocumentationOptions("", "html", generateIndexPages = false, noStdlibLink = true)
+ val options = DocumentationOptions(
+ outputDir = "",
+ outputFormat = "kotlin-website-html",
+ generateIndexPages = false,
+ noStdlibLink = true,
+ languageVersion = null,
+ apiVersion = null
+ )
appendDocumentation(module, contentRootFromPath("testdata/format/website-html/$path/jvm.kt"), defaultPlatforms = listOf("JVM"), options = options)
appendDocumentation(module, contentRootFromPath("testdata/format/website-html/$path/jre7.kt"), defaultPlatforms = listOf("JVM", "JRE7"), options = options)
appendDocumentation(module, contentRootFromPath("testdata/format/website-html/$path/js.kt"), defaultPlatforms = listOf("JS"), options = options)
diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt
index 48b06d6e..820af361 100644
--- a/core/src/test/kotlin/format/MarkdownFormatTest.kt
+++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt
@@ -251,6 +251,10 @@ class MarkdownFormatTest {
verifyMarkdownPackage("sinceKotlin")
}
+ @Test fun sinceKotlinWide() {
+ verifyMarkdownPackage("sinceKotlinWide")
+ }
+
@Test fun dynamicType() {
verifyMarkdownNode("dynamicType")
}
@@ -300,7 +304,14 @@ class MarkdownFormatTest {
@Test fun packagePlatformsWithExtExtensions() {
val path = "multiplatform/packagePlatformsWithExtExtensions"
val module = DocumentationModule("test")
- val options = DocumentationOptions("", "html", generateIndexPages = false, noStdlibLink = true)
+ val options = DocumentationOptions(
+ outputDir = "",
+ outputFormat = "html",
+ generateIndexPages = false,
+ noStdlibLink = true,
+ languageVersion = null,
+ apiVersion = null
+ )
appendDocumentation(module, contentRootFromPath("testdata/format/$path/jvm.kt"), defaultPlatforms = listOf("JVM"), withKotlinRuntime = true, options = options)
verifyMultiplatformIndex(module, path)
verifyMultiplatformPackage(module, path)
@@ -376,9 +387,40 @@ class MarkdownFormatTest {
verifyMarkdownPackage("newlineInTableCell")
}
+ @Test fun indentedCodeBlock() {
+ verifyMarkdownNode("indentedCodeBlock")
+ }
+
+ @Test fun receiverReference() {
+ verifyMarkdownNode("receiverReference")
+ }
+
+ @Test fun extensionScope() {
+ verifyMarkdownNodeByName("extensionScope", "test")
+ }
+
+ @Test fun typeParameterReference() {
+ verifyMarkdownNode("typeParameterReference")
+ }
+
+ @Test fun notPublishedTypeAliasAutoExpansion() {
+ verifyMarkdownNodeByName("notPublishedTypeAliasAutoExpansion", "foo", includeNonPublic = false)
+ }
+
+ @Test fun companionImplements() {
+ verifyMarkdownNodeByName("companionImplements", "Foo")
+ }
+
private fun buildMultiplePlatforms(path: String): DocumentationModule {
val module = DocumentationModule("test")
- val options = DocumentationOptions("", "html", generateIndexPages = false, noStdlibLink = true)
+ val options = DocumentationOptions(
+ outputDir = "",
+ outputFormat = "html",
+ generateIndexPages = false,
+ noStdlibLink = true,
+ languageVersion = null,
+ apiVersion = null
+ )
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
@@ -412,8 +454,18 @@ class MarkdownFormatTest {
verifyMarkdownNodes(fileName, withKotlinRuntime) { model -> model.members.single().members }
}
- private fun verifyMarkdownNodes(fileName: String, withKotlinRuntime: Boolean = false, nodeFilter: (DocumentationModule) -> List<DocumentationNode>) {
- verifyOutput("testdata/format/$fileName.kt", ".md", withKotlinRuntime = withKotlinRuntime) { model, output ->
+ private fun verifyMarkdownNodes(
+ fileName: String,
+ withKotlinRuntime: Boolean = false,
+ includeNonPublic: Boolean = true,
+ nodeFilter: (DocumentationModule) -> List<DocumentationNode>
+ ) {
+ verifyOutput(
+ "testdata/format/$fileName.kt",
+ ".md",
+ withKotlinRuntime = withKotlinRuntime,
+ includeNonPublic = includeNonPublic
+ ) { model, output ->
markdownService.createOutputBuilder(output, tempLocation).appendNodes(nodeFilter(model))
}
}
@@ -428,8 +480,13 @@ class MarkdownFormatTest {
}
}
- private fun verifyMarkdownNodeByName(fileName: String, name: String, withKotlinRuntime: Boolean = false) {
- verifyMarkdownNodes(fileName, withKotlinRuntime) { model->
+ private fun verifyMarkdownNodeByName(
+ fileName: String,
+ name: String,
+ withKotlinRuntime: Boolean = false,
+ includeNonPublic: Boolean = true
+ ) {
+ verifyMarkdownNodes(fileName, withKotlinRuntime, includeNonPublic) { model->
val nodesWithName = model.members.single().members.filter { it.name == name }
if (nodesWithName.isEmpty()) {
throw IllegalArgumentException("Found no nodes named $name")
diff --git a/core/src/test/kotlin/javadoc/JavadocTest.kt b/core/src/test/kotlin/javadoc/JavadocTest.kt
index 359c5fef..45c45aa4 100644
--- a/core/src/test/kotlin/javadoc/JavadocTest.kt
+++ b/core/src/test/kotlin/javadoc/JavadocTest.kt
@@ -151,6 +151,16 @@ class JavadocTest {
}
}
+ @Test
+ fun testCompanionMethodReference() {
+ verifyJavadoc("testdata/javadoc/companionMethodReference.kt") { doc ->
+ val classDoc = doc.classNamed("foo.TestClass")!!
+ val tag = classDoc.inlineTags().filterIsInstance<SeeMethodTagAdapter>().first()
+ assertEquals("TestClass.Companion", tag.referencedClassName())
+ assertEquals("test", tag.referencedMemberName())
+ }
+ }
+
private fun verifyJavadoc(name: String,
withJdk: Boolean = false,
withKotlinRuntime: Boolean = false,
diff --git a/core/src/test/kotlin/model/FunctionTest.kt b/core/src/test/kotlin/model/FunctionTest.kt
index 065decef..32910682 100644
--- a/core/src/test/kotlin/model/FunctionTest.kt
+++ b/core/src/test/kotlin/model/FunctionTest.kt
@@ -5,6 +5,7 @@ import org.jetbrains.dokka.NodeKind
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
+import kotlin.test.assertNotNull
class FunctionTest {
@Test fun function() {
@@ -83,9 +84,10 @@ class FunctionTest {
assertEquals(NodeKind.Function, kind)
assertEquals("generic function", content.summary.toTestString())
- assertEquals("public", details.elementAt(0).name)
- assertEquals("final", details.elementAt(1).name)
- with(details.elementAt(3)) {
+ val functionDetails = details
+ assertEquals("public", functionDetails.elementAt(0).name)
+ assertEquals("final", functionDetails.elementAt(1).name)
+ with(functionDetails.elementAt(3)) {
assertEquals("T", name)
assertEquals(NodeKind.TypeParameter, kind)
assertEquals(Content.Empty, content)
@@ -95,19 +97,19 @@ class FunctionTest {
assertEquals(Content.Empty, content)
assertTrue(details.none())
assertTrue(members.none())
- assertTrue(links.none())
+ assertTrue(links.singleOrNull() == functionDetails.elementAt(4))
}
assertTrue(members.none())
assertTrue(links.none())
}
- with(details.elementAt(4)) {
+ with(functionDetails.elementAt(4)) {
assertEquals("R", name)
assertEquals(NodeKind.TypeParameter, kind)
assertEquals(Content.Empty, content)
assertTrue(members.none())
assertTrue(links.none())
}
- assertEquals("Unit", details.elementAt(5).name)
+ assertEquals("Unit", functionDetails.elementAt(5).name)
assertTrue(members.none())
assertTrue(links.none())
diff --git a/core/src/test/kotlin/model/PackageTest.kt b/core/src/test/kotlin/model/PackageTest.kt
index 97810e80..052f0d28 100644
--- a/core/src/test/kotlin/model/PackageTest.kt
+++ b/core/src/test/kotlin/model/PackageTest.kt
@@ -2,10 +2,10 @@ package org.jetbrains.dokka.tests
import org.jetbrains.dokka.Content
import org.jetbrains.dokka.NodeKind
+import org.jetbrains.dokka.PackageOptionsImpl
import org.jetbrains.kotlin.config.KotlinSourceRoot
+import org.junit.Assert.*
import org.junit.Test
-import org.junit.Assert.assertEquals
-import org.junit.Assert.assertTrue
public class PackageTest {
@Test fun rootPackage() {
@@ -83,4 +83,33 @@ public class PackageTest {
}
}
}
-} \ No newline at end of file
+
+ @Test fun classAtPackageLevel() {
+ verifyModel(KotlinSourceRoot("testdata/packages/classInPackage.kt")) { model ->
+ assertEquals(1, model.members.count())
+ with(model.members.elementAt(0)) {
+ assertEquals(NodeKind.Package, kind)
+ assertEquals("simple.name", name)
+ assertEquals(Content.Empty, content)
+ assertTrue(details.none())
+ assertEquals(1, members.size)
+ assertTrue(links.none())
+ }
+ }
+ }
+
+ @Test fun suppressAtPackageLevel() {
+ verifyModel(KotlinSourceRoot("testdata/packages/classInPackage.kt"),
+ perPackageOptions = listOf(PackageOptionsImpl(prefix = "simple.name", suppress = true))) { model ->
+ assertEquals(1, model.members.count())
+ with(model.members.elementAt(0)) {
+ assertEquals(NodeKind.Package, kind)
+ assertEquals("simple.name", name)
+ assertEquals(Content.Empty, content)
+ assertTrue(details.none())
+ assertTrue(members.none())
+ assertTrue(links.none())
+ }
+ }
+ }
+}