From 960ea9ebb01f280c4966e139c1697f083e9d8965 Mon Sep 17 00:00:00 2001 From: aleksZubakov Date: Thu, 12 Jul 2018 15:37:18 +0300 Subject: Test refactoring and split by different platforms --- core/src/test/kotlin/javadoc/JavadocTest.kt | 39 +++++++++++++++++------------ 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'core/src/test/kotlin/javadoc/JavadocTest.kt') diff --git a/core/src/test/kotlin/javadoc/JavadocTest.kt b/core/src/test/kotlin/javadoc/JavadocTest.kt index 45c45aa4..dc576b61 100644 --- a/core/src/test/kotlin/javadoc/JavadocTest.kt +++ b/core/src/test/kotlin/javadoc/JavadocTest.kt @@ -3,14 +3,16 @@ package org.jetbrains.dokka.javadoc import com.sun.javadoc.Tag import com.sun.javadoc.Type import org.jetbrains.dokka.DokkaConsoleLogger +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.tests.ModelConfig import org.jetbrains.dokka.tests.assertEqualsIgnoringSeparators -import org.jetbrains.dokka.tests.verifyModel +import org.jetbrains.dokka.tests.checkSourceExistsAndVerifyModel import org.junit.Assert.* import org.junit.Test class JavadocTest { @Test fun testTypes() { - verifyJavadoc("testdata/javadoc/types.kt", withJdk = true) { doc -> + verifyJavadoc("testdata/javadoc/types.kt", ModelConfig(withJdk = true)) { doc -> val classDoc = doc.classNamed("foo.TypesKt")!! val method = classDoc.methods().find { it.name() == "foo" }!! @@ -39,7 +41,7 @@ class JavadocTest { } @Test fun testException() { - verifyJavadoc("testdata/javadoc/exception.kt", withKotlinRuntime = true) { doc -> + verifyJavadoc("testdata/javadoc/exception.kt", ModelConfig(withKotlinRuntime = true)) { doc -> val classDoc = doc.classNamed("foo.MyException")!! val member = classDoc.methods().find { it.name() == "foo" } assertEquals(classDoc, member!!.containingClass()) @@ -47,7 +49,7 @@ class JavadocTest { } @Test fun testByteArray() { - verifyJavadoc("testdata/javadoc/bytearr.kt", withKotlinRuntime = true) { doc -> + verifyJavadoc("testdata/javadoc/bytearr.kt", ModelConfig(withKotlinRuntime = true)) { doc -> val classDoc = doc.classNamed("foo.ByteArray")!! assertNotNull(classDoc.asClassDoc()) @@ -57,7 +59,7 @@ class JavadocTest { } @Test fun testStringArray() { - verifyJavadoc("testdata/javadoc/stringarr.kt", withKotlinRuntime = true) { doc -> + verifyJavadoc("testdata/javadoc/stringarr.kt", ModelConfig(withKotlinRuntime = true)) { doc -> val classDoc = doc.classNamed("foo.Foo")!! assertNotNull(classDoc.asClassDoc()) @@ -70,7 +72,7 @@ class JavadocTest { } @Test fun testJvmName() { - verifyJavadoc("testdata/javadoc/jvmname.kt", withKotlinRuntime = true) { doc -> + verifyJavadoc("testdata/javadoc/jvmname.kt", ModelConfig(withKotlinRuntime = true)) { doc -> val classDoc = doc.classNamed("foo.Apple")!! assertNotNull(classDoc.asClassDoc()) @@ -80,7 +82,7 @@ class JavadocTest { } @Test fun testLinkWithParam() { - verifyJavadoc("testdata/javadoc/paramlink.kt", withKotlinRuntime = true) { doc -> + verifyJavadoc("testdata/javadoc/paramlink.kt", ModelConfig(withKotlinRuntime = true)) { doc -> val classDoc = doc.classNamed("demo.Apple")!! assertNotNull(classDoc.asClassDoc()) val tags = classDoc.inlineTags().filterIsInstance() @@ -91,7 +93,7 @@ class JavadocTest { } @Test fun testInternalVisibility() { - verifyJavadoc("testdata/javadoc/internal.kt", withKotlinRuntime = true, includeNonPublic = false) { doc -> + verifyJavadoc("testdata/javadoc/internal.kt", ModelConfig(withKotlinRuntime = true, includeNonPublic = false)) { doc -> val classDoc = doc.classNamed("foo.Person")!! val constructors = classDoc.constructors() assertEquals(1, constructors.size) @@ -100,7 +102,7 @@ class JavadocTest { } @Test fun testSuppress() { - verifyJavadoc("testdata/javadoc/suppress.kt", withKotlinRuntime = true) { doc -> + verifyJavadoc("testdata/javadoc/suppress.kt", ModelConfig(withKotlinRuntime = true)) { doc -> assertNull(doc.classNamed("Some")) assertNull(doc.classNamed("SomeAgain")) assertNull(doc.classNamed("Interface")) @@ -111,7 +113,7 @@ class JavadocTest { } @Test fun testTypeAliases() { - verifyJavadoc("testdata/javadoc/typealiases.kt", withKotlinRuntime = true) { doc -> + verifyJavadoc("testdata/javadoc/typealiases.kt", ModelConfig(withKotlinRuntime = true)) { doc -> assertNull(doc.classNamed("B")) assertNull(doc.classNamed("D")) @@ -126,7 +128,7 @@ class JavadocTest { } @Test fun testKDocKeywordsOnMethod() { - verifyJavadoc("testdata/javadoc/kdocKeywordsOnMethod.kt", withKotlinRuntime = true) { doc -> + verifyJavadoc("testdata/javadoc/kdocKeywordsOnMethod.kt", ModelConfig(withKotlinRuntime = true)) { doc -> val method = doc.classNamed("KdocKeywordsOnMethodKt")!!.methods()[0] assertEquals("@return [ContentText(text=value of a)]", method.tags("return").first().text()) assertEquals("@param a [ContentText(text=Some string)]", method.paramTags().first().text()) @@ -136,7 +138,7 @@ class JavadocTest { @Test fun testBlankLineInsideCodeBlock() { - verifyJavadoc("testdata/javadoc/blankLineInsideCodeBlock.kt", withKotlinRuntime = true) { doc -> + verifyJavadoc("testdata/javadoc/blankLineInsideCodeBlock.kt", ModelConfig(withKotlinRuntime = true)) { doc -> val method = doc.classNamed("BlankLineInsideCodeBlockKt")!!.methods()[0] val text = method.inlineTags().joinToString(separator = "", transform = Tag::text) assertEqualsIgnoringSeparators(""" @@ -162,12 +164,17 @@ class JavadocTest { } private fun verifyJavadoc(name: String, - withJdk: Boolean = false, - withKotlinRuntime: Boolean = false, - includeNonPublic: Boolean = true, + modelConfig: ModelConfig = ModelConfig(), callback: (ModuleNodeAdapter) -> Unit) { - verifyModel(name, format = "javadoc", withJdk = withJdk, withKotlinRuntime = withKotlinRuntime, includeNonPublic = includeNonPublic) { model -> + checkSourceExistsAndVerifyModel(name, + ModelConfig( + analysisPlatform = Platform.jvm, + format = "javadoc", + withJdk = modelConfig.withJdk, + withKotlinRuntime = modelConfig.withKotlinRuntime, + includeNonPublic = modelConfig.includeNonPublic + )) { model -> val doc = ModuleNodeAdapter(model, StandardReporter(DokkaConsoleLogger), "") callback(doc) } -- cgit From 742be4ef7c024a5ea6023fb684cd24d1898f37e4 Mon Sep 17 00:00:00 2001 From: aleksZubakov Date: Thu, 12 Jul 2018 20:23:02 +0300 Subject: Test refactoring, add common platform tests --- core/src/test/kotlin/TestAPI.kt | 15 +- core/src/test/kotlin/format/BaseHtmlFormatTest.kt | 146 ------ .../test/kotlin/format/BaseMarkdownFormatTest.kt | 467 ----------------- core/src/test/kotlin/format/GFMFormatTest.kt | 18 +- core/src/test/kotlin/format/HtmlFormatTest.kt | 193 +++++++ core/src/test/kotlin/format/JSHtmlFormatTest.kt | 6 - .../src/test/kotlin/format/JSMarkdownFormatTest.kt | 7 - core/src/test/kotlin/format/JVMHtmlFormatTest.kt | 54 -- .../test/kotlin/format/JVMMarkdownFormatTest.kt | 117 ----- .../kotlin/format/KotlinWebSiteHtmlFormatTest.kt | 29 +- core/src/test/kotlin/format/MarkdownFormatTest.kt | 580 +++++++++++++++++++++ core/src/test/kotlin/issues/IssuesTest.kt | 11 +- core/src/test/kotlin/javadoc/JavadocTest.kt | 58 ++- core/src/test/kotlin/model/BaseClassTest.kt | 269 ---------- core/src/test/kotlin/model/BasePropertyTest.kt | 101 ---- core/src/test/kotlin/model/ClassTest.kt | 318 +++++++++++ core/src/test/kotlin/model/CommentTest.kt | 36 +- core/src/test/kotlin/model/FunctionTest.kt | 23 + core/src/test/kotlin/model/JSClassTest.kt | 6 - core/src/test/kotlin/model/JSFunctionTest.kt | 8 - core/src/test/kotlin/model/JSPropertyTest.kt | 8 - core/src/test/kotlin/model/JVMClassTest.kt | 55 -- core/src/test/kotlin/model/JVMFunctionTest.kt | 29 -- core/src/test/kotlin/model/JVMPropertyTest.kt | 33 -- core/src/test/kotlin/model/KotlinAsJavaTest.kt | 9 +- core/src/test/kotlin/model/LinkTest.kt | 22 +- core/src/test/kotlin/model/PackageTest.kt | 31 +- core/src/test/kotlin/model/PropertyTest.kt | 129 +++++ 28 files changed, 1395 insertions(+), 1383 deletions(-) delete mode 100644 core/src/test/kotlin/format/BaseHtmlFormatTest.kt delete mode 100644 core/src/test/kotlin/format/BaseMarkdownFormatTest.kt create mode 100644 core/src/test/kotlin/format/HtmlFormatTest.kt delete mode 100644 core/src/test/kotlin/format/JSHtmlFormatTest.kt delete mode 100644 core/src/test/kotlin/format/JSMarkdownFormatTest.kt delete mode 100644 core/src/test/kotlin/format/JVMHtmlFormatTest.kt delete mode 100644 core/src/test/kotlin/format/JVMMarkdownFormatTest.kt create mode 100644 core/src/test/kotlin/format/MarkdownFormatTest.kt delete mode 100644 core/src/test/kotlin/model/BaseClassTest.kt delete mode 100644 core/src/test/kotlin/model/BasePropertyTest.kt create mode 100644 core/src/test/kotlin/model/ClassTest.kt delete mode 100644 core/src/test/kotlin/model/JSClassTest.kt delete mode 100644 core/src/test/kotlin/model/JSFunctionTest.kt delete mode 100644 core/src/test/kotlin/model/JSPropertyTest.kt delete mode 100644 core/src/test/kotlin/model/JVMClassTest.kt delete mode 100644 core/src/test/kotlin/model/JVMFunctionTest.kt delete mode 100644 core/src/test/kotlin/model/JVMPropertyTest.kt create mode 100644 core/src/test/kotlin/model/PropertyTest.kt (limited to 'core/src/test/kotlin/javadoc/JavadocTest.kt') diff --git a/core/src/test/kotlin/TestAPI.kt b/core/src/test/kotlin/TestAPI.kt index bcbbf2fc..7042f41b 100644 --- a/core/src/test/kotlin/TestAPI.kt +++ b/core/src/test/kotlin/TestAPI.kt @@ -14,6 +14,7 @@ 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.jetbrains.kotlin.utils.PathUtil import org.junit.Assert import org.junit.Assert.fail import java.io.File @@ -24,7 +25,7 @@ data class ModelConfig( val format: String = "html", val includeNonPublic: Boolean = true, val perPackageOptions: List = emptyList(), - val analysisPlatform: Platform = Platform.js, + val analysisPlatform: Platform = Platform.DEFAULT, val defaultPlatforms: List = emptyList() ) @@ -84,18 +85,22 @@ fun appendDocumentation(documentation: DocumentationModule, val environment = AnalysisEnvironment(messageCollector, modelConfig.analysisPlatform) environment.apply { if (modelConfig.withJdk || modelConfig.withKotlinRuntime) { - val stringRoot = PathManager.getResourceRoot(String::class.java, "/java/lang/String.class") - addClasspath(File(stringRoot)) + addClasspath(PathUtil.getJdkClassesRootsFromCurrentJre()) } if (modelConfig.withKotlinRuntime) { - val kotlinStrictfpRoot = PathManager.getResourceRoot(Strictfp::class.java, "/kotlin/jvm/Strictfp.class") - addClasspath(File(kotlinStrictfpRoot)) + if (analysisPlatform == Platform.jvm) { + val kotlinStrictfpRoot = PathManager.getResourceRoot(Strictfp::class.java, "/kotlin/jvm/Strictfp.class") + addClasspath(File(kotlinStrictfpRoot)) + } // TODO: Fix concrete path to correct gradle path providing if (analysisPlatform == Platform.js) { addClasspath(File("/home/jetbrains/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/181.5281.24/plugins/Kotlin/kotlinc/lib/kotlin-jslib.jar")) addClasspath(File("/home/jetbrains/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/181.5281.24/plugins/Kotlin/kotlinc/lib/kotlin-stdlib-js.jar")) addClasspath(File("/home/jetbrains/.local/share/JetBrains/Toolbox/apps/IDEA-U/ch-0/181.5281.24/plugins/Kotlin/kotlinc/lib/kotlin-stdlib-js-sources.jar")) } + if (analysisPlatform == Platform.common) { + addClasspath(File("/home/jetbrains/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-common/1.2.51/e4a9d4b13ab19ed1e6531fce6df98e8cfa7f7301/kotlin-stdlib-common-1.2.51.jar")) + } } addRoots(modelConfig.roots.toList()) diff --git a/core/src/test/kotlin/format/BaseHtmlFormatTest.kt b/core/src/test/kotlin/format/BaseHtmlFormatTest.kt deleted file mode 100644 index 7fd331cf..00000000 --- a/core/src/test/kotlin/format/BaseHtmlFormatTest.kt +++ /dev/null @@ -1,146 +0,0 @@ -package org.jetbrains.dokka.tests - -import org.jetbrains.dokka.* -import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot -import org.jetbrains.kotlin.config.KotlinSourceRoot -import org.junit.Before -import org.junit.Test -import java.io.File - -abstract class BaseHtmlFormatTest(val analysisPlatform: Platform): FileGeneratorTestCase() { - protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) - override val formatService = HtmlFormatService(fileGenerator, KotlinLanguageService(), HtmlTemplateService.default(), listOf()) - - @Test fun classWithCompanionObject() { - verifyHtmlNode("classWithCompanionObject", defaultModelConfig) - } - - @Test fun htmlEscaping() { - verifyHtmlNode("htmlEscaping", defaultModelConfig) - } - - @Test fun overloads() { - verifyHtmlNodes("overloads", defaultModelConfig) { model -> model.members } - } - - @Test fun overloadsWithDescription() { - verifyHtmlNode("overloadsWithDescription", defaultModelConfig) - } - - @Test fun overloadsWithDifferentDescriptions() { - verifyHtmlNode("overloadsWithDifferentDescriptions", defaultModelConfig) - } - - @Test fun deprecated() { - verifyOutput("testdata/format/deprecated.kt", ".package.html", defaultModelConfig) { model, output -> - buildPagesAndReadInto(model.members, output) - } - verifyOutput("testdata/format/deprecated.kt", ".class.html", defaultModelConfig) { model, output -> - buildPagesAndReadInto(model.members.single().members, output) - } - } - - @Test fun brokenLink() { - verifyHtmlNode("brokenLink", defaultModelConfig) - } - - @Test fun codeSpan() { - verifyHtmlNode("codeSpan", defaultModelConfig) - } - - @Test fun parenthesis() { - verifyHtmlNode("parenthesis", defaultModelConfig) - } - - @Test fun bracket() { - verifyHtmlNode("bracket", defaultModelConfig) - } - - @Test fun see() { - verifyHtmlNode("see", defaultModelConfig) - } - - @Test fun tripleBackticks() { - verifyHtmlNode("tripleBackticks", defaultModelConfig) - } - - @Test fun typeLink() { - verifyHtmlNodes("typeLink", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } - } - - @Test fun parameterAnchor() { - verifyHtmlNode("parameterAnchor", defaultModelConfig) - } - - @Test fun codeBlock() { - verifyHtmlNode("codeBlock", defaultModelConfig) - } - @Test fun orderedList() { - verifyHtmlNodes("orderedList", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } - } - - @Test fun linkWithLabel() { - verifyHtmlNodes("linkWithLabel", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } - } - - @Test fun entity() { - verifyHtmlNodes("entity", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } - } - - @Test fun uninterpretedEmphasisCharacters() { - verifyHtmlNode("uninterpretedEmphasisCharacters", defaultModelConfig) - } - - @Test fun markdownInLinks() { - verifyHtmlNode("markdownInLinks", defaultModelConfig) - } - - @Test fun returnWithLink() { - verifyHtmlNode("returnWithLink", defaultModelConfig) - } - - @Test fun linkWithStarProjection() { - verifyHtmlNode("linkWithStarProjection", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) - } - - @Test fun functionalTypeWithNamedParameters() { - verifyHtmlNode("functionalTypeWithNamedParameters", defaultModelConfig) - } - - @Test fun sinceKotlin() { - verifyHtmlNode("sinceKotlin", defaultModelConfig) - } - - @Test fun blankLineInsideCodeBlock() { - verifyHtmlNode("blankLineInsideCodeBlock", defaultModelConfig) - } - - @Test fun indentedCodeBlock() { - verifyHtmlNode("indentedCodeBlock", defaultModelConfig) - } - - private fun verifyHtmlNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { - verifyHtmlNodes(fileName, modelConfig) { model -> model.members.single().members } - } - - private fun verifyHtmlNodes(fileName: String, - modelConfig: ModelConfig = ModelConfig(), - nodeFilter: (DocumentationModule) -> List) { - verifyOutput("testdata/format/$fileName.kt", ".html", modelConfig) { model, output -> - buildPagesAndReadInto(nodeFilter(model), output) - } - } - - protected fun verifyJavaHtmlNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { - verifyJavaHtmlNodes(fileName, modelConfig) { model -> model.members.single().members } - } - - protected fun verifyJavaHtmlNodes(fileName: String, - modelConfig: ModelConfig = ModelConfig(), - nodeFilter: (DocumentationModule) -> List) { - verifyJavaOutput("testdata/format/$fileName.java", ".html", modelConfig) { model, output -> - buildPagesAndReadInto(nodeFilter(model), output) - } - } -} - diff --git a/core/src/test/kotlin/format/BaseMarkdownFormatTest.kt b/core/src/test/kotlin/format/BaseMarkdownFormatTest.kt deleted file mode 100644 index 5612b1fd..00000000 --- a/core/src/test/kotlin/format/BaseMarkdownFormatTest.kt +++ /dev/null @@ -1,467 +0,0 @@ -package org.jetbrains.dokka.tests - -import org.jetbrains.dokka.* -import org.junit.Before -import org.junit.Test - -abstract class BaseMarkdownFormatTest(val analysisPlatform: Platform): FileGeneratorTestCase() { - override val formatService = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf()) - - protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) - - @Test fun emptyDescription() { - verifyMarkdownNode("emptyDescription", defaultModelConfig) - } - - @Test fun classWithCompanionObject() { - verifyMarkdownNode("classWithCompanionObject", defaultModelConfig) - } - - @Test fun annotations() { - verifyMarkdownNode("annotations", defaultModelConfig) - } - - @Test fun annotationClass() { - verifyMarkdownNode("annotationClass", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) - verifyMarkdownPackage("annotationClass", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) - } - - @Test fun enumClass() { - verifyOutput("testdata/format/enumClass.kt", ".md", defaultModelConfig) { model, output -> - buildPagesAndReadInto(model.members.single().members, output) - } - verifyOutput("testdata/format/enumClass.kt", ".value.md", defaultModelConfig) { model, output -> - val enumClassNode = model.members.single().members[0] - buildPagesAndReadInto( - enumClassNode.members.filter { it.name == "LOCAL_CONTINUE_AND_BREAK" }, - output - ) - } - } - - @Test fun varargsFunction() { - verifyMarkdownNode("varargsFunction", defaultModelConfig) - } - - @Test fun overridingFunction() { - verifyMarkdownNodes("overridingFunction", defaultModelConfig) { model-> - val classMembers = model.members.single().members.first { it.name == "D" }.members - classMembers.filter { it.name == "f" } - } - } - - @Test fun propertyVar() { - verifyMarkdownNode("propertyVar", defaultModelConfig) - } - - @Test fun functionWithDefaultParameter() { - verifyMarkdownNode("functionWithDefaultParameter", defaultModelConfig) - } - - @Test fun accessor() { - verifyMarkdownNodes("accessor", defaultModelConfig) { model -> - model.members.single().members.first { it.name == "C" }.members.filter { it.name == "x" } - } - } - - @Test fun paramTag() { - verifyMarkdownNode("paramTag", defaultModelConfig) - } - - @Test fun throwsTag() { - verifyMarkdownNode("throwsTag", defaultModelConfig) - } - - @Test fun typeParameterBounds() { - verifyMarkdownNode("typeParameterBounds", defaultModelConfig) - } - - @Test fun typeParameterVariance() { - verifyMarkdownNode("typeParameterVariance", defaultModelConfig) - } - - @Test fun typeProjectionVariance() { - verifyMarkdownNode("typeProjectionVariance", defaultModelConfig) - } - - @Test fun codeBlockNoHtmlEscape() { - verifyMarkdownNodeByName("codeBlockNoHtmlEscape", "hackTheArithmetic", defaultModelConfig) - } - - @Test fun companionObjectExtension() { - verifyMarkdownNodeByName("companionObjectExtension", "Foo", defaultModelConfig) - } - - @Test fun starProjection() { - verifyMarkdownNode("starProjection", defaultModelConfig) - } - - @Test fun extensionFunctionParameter() { - verifyMarkdownNode("extensionFunctionParameter", defaultModelConfig) - } - - @Test fun summarizeSignatures() { - verifyMarkdownNodes("summarizeSignatures", defaultModelConfig) { model -> model.members } - } - - @Test fun reifiedTypeParameter() { - verifyMarkdownNode("reifiedTypeParameter", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) - } - - @Test fun annotatedTypeParameter() { - verifyMarkdownNode("annotatedTypeParameter", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) - } - - @Test fun inheritedMembers() { - verifyMarkdownNodeByName("inheritedMembers", "Bar", defaultModelConfig) - } - - @Test fun inheritedExtensions() { - verifyMarkdownNodeByName("inheritedExtensions", "Bar", defaultModelConfig) - } - - @Test fun genericInheritedExtensions() { - verifyMarkdownNodeByName("genericInheritedExtensions", "Bar", defaultModelConfig) - } - - @Test fun arrayAverage() { - verifyMarkdownNodeByName("arrayAverage", "XArray", defaultModelConfig) - } - - @Test fun multipleTypeParameterConstraints() { - verifyMarkdownNode("multipleTypeParameterConstraints", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) - } - - @Test fun inheritedCompanionObjectProperties() { - verifyMarkdownNodeByName("inheritedCompanionObjectProperties", "C", defaultModelConfig) - } - - @Test fun shadowedExtensionFunctions() { - verifyMarkdownNodeByName("shadowedExtensionFunctions", "Bar", defaultModelConfig) - } - - @Test fun inapplicableExtensionFunctions() { - verifyMarkdownNodeByName("inapplicableExtensionFunctions", "Bar", defaultModelConfig) - } - - @Test fun receiverParameterTypeBound() { - verifyMarkdownNodeByName("receiverParameterTypeBound", "Foo", defaultModelConfig) - } - - @Test fun extensionWithDocumentedReceiver() { - verifyMarkdownNodes("extensionWithDocumentedReceiver", defaultModelConfig) { model -> - model.members.single().members.single().members.filter { it.name == "fn" } - } - } - - @Test fun codeBlock() { - verifyMarkdownNode("codeBlock", defaultModelConfig) - } - - @Test fun exclInCodeBlock() { - verifyMarkdownNodeByName("exclInCodeBlock", "foo", defaultModelConfig) - } - - @Test fun backtickInCodeBlock() { - verifyMarkdownNodeByName("backtickInCodeBlock", "foo", defaultModelConfig) - } - - @Test fun qualifiedNameLink() { - verifyMarkdownNodeByName("qualifiedNameLink", "foo", - ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) - } - - @Test fun functionalTypeWithNamedParameters() { - verifyMarkdownNode("functionalTypeWithNamedParameters", defaultModelConfig) - } - - @Test fun typeAliases() { - verifyMarkdownNode("typeAliases", defaultModelConfig) - verifyMarkdownPackage("typeAliases", defaultModelConfig) - } - - @Test fun sampleByShortName() { - verifyMarkdownNode("sampleByShortName", defaultModelConfig) - } - - - @Test fun suspendParam() { - verifyMarkdownNode("suspendParam", defaultModelConfig) - verifyMarkdownPackage("suspendParam", defaultModelConfig) - } - - @Test fun sinceKotlin() { - verifyMarkdownNode("sinceKotlin", defaultModelConfig) - verifyMarkdownPackage("sinceKotlin", defaultModelConfig) - } - - @Test fun sinceKotlinWide() { - verifyMarkdownPackage("sinceKotlinWide", defaultModelConfig) - } - - @Test fun dynamicType() { - verifyMarkdownNode("dynamicType", defaultModelConfig) - } - - @Test fun dynamicExtension() { - verifyMarkdownNodes("dynamicExtension", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Foo" } } - } - - @Test fun memberExtension() { - verifyMarkdownNodes("memberExtension", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Foo" } } - } - - @Test fun renderFunctionalTypeInParenthesisWhenItIsReceiver() { - verifyMarkdownNode("renderFunctionalTypeInParenthesisWhenItIsReceiver", defaultModelConfig) - } - - @Test fun multiplePlatforms() { - verifyMultiplatformPackage(buildMultiplePlatforms("multiplatform/simple"), "multiplatform/simple") - } - - @Test fun multiplePlatformsMerge() { - verifyMultiplatformPackage(buildMultiplePlatforms("multiplatform/merge"), "multiplatform/merge") - } - - @Test fun multiplePlatformsMergeMembers() { - val module = buildMultiplePlatforms("multiplatform/mergeMembers") - verifyModelOutput(module, ".md", "testdata/format/multiplatform/mergeMembers/foo.kt") { model, output -> - buildPagesAndReadInto(model.members.single().members, output) - } - } - - @Test fun multiplePlatformsOmitRedundant() { - val module = buildMultiplePlatforms("multiplatform/omitRedundant") - verifyModelOutput(module, ".md", "testdata/format/multiplatform/omitRedundant/foo.kt") { model, output -> - buildPagesAndReadInto(model.members.single().members, output) - } - } - - @Test fun multiplePlatformsImplied() { - val module = buildMultiplePlatforms("multiplatform/implied") - verifyModelOutput(module, ".md", "testdata/format/multiplatform/implied/foo.kt") { model, output -> - val service = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf("JVM", "JS")) - fileGenerator.formatService = service - buildPagesAndReadInto(model.members.single().members, output) - } - } - - @Test fun packagePlatformsWithExtExtensions() { - val path = "multiplatform/packagePlatformsWithExtExtensions" - val module = DocumentationModule("test") - val options = DocumentationOptions( - outputDir = "", - outputFormat = "html", - generateIndexPages = false, - noStdlibLink = true, - languageVersion = null, - apiVersion = null - ) - appendDocumentation(module, options, ModelConfig( - roots = arrayOf(contentRootFromPath("testdata/format/$path/jvm.kt")), - defaultPlatforms = listOf("JVM"), - withKotlinRuntime = true, - analysisPlatform = analysisPlatform - ) - ) - verifyMultiplatformIndex(module, path) - verifyMultiplatformPackage(module, path) - } - - @Test fun multiplePlatformsPackagePlatformFromMembers() { - val path = "multiplatform/packagePlatformsFromMembers" - val module = buildMultiplePlatforms(path) - verifyMultiplatformIndex(module, path) - verifyMultiplatformPackage(module, path) - } - - @Test fun multiplePlatformsGroupNode() { - val path = "multiplatform/groupNode" - val module = buildMultiplePlatforms(path) - verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.kt") { model, output -> - buildPagesAndReadInto( - listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }), - output - ) - } - verifyMultiplatformPackage(module, path) - } - - @Test fun multiplePlatformsBreadcrumbsInMemberOfMemberOfGroupNode() { - val path = "multiplatform/breadcrumbsInMemberOfMemberOfGroupNode" - val module = buildMultiplePlatforms(path) - verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.kt") { model, output -> - buildPagesAndReadInto( - listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }?.member(NodeKind.Class)?.member(NodeKind.Function)), - output - ) - } - } - - @Test fun linksInEmphasis() { - verifyMarkdownNode("linksInEmphasis", defaultModelConfig) - } - - @Test fun linksInStrong() { - verifyMarkdownNode("linksInStrong", defaultModelConfig) - } - - @Test fun linksInHeaders() { - verifyMarkdownNode("linksInHeaders", defaultModelConfig) - } - - @Test fun tokensInEmphasis() { - verifyMarkdownNode("tokensInEmphasis", defaultModelConfig) - } - - @Test fun tokensInStrong() { - verifyMarkdownNode("tokensInStrong", defaultModelConfig) - } - - @Test fun tokensInHeaders() { - verifyMarkdownNode("tokensInHeaders", defaultModelConfig) - } - - @Test fun unorderedLists() { - verifyMarkdownNode("unorderedLists", defaultModelConfig) - } - - @Test fun nestedLists() { - verifyMarkdownNode("nestedLists", defaultModelConfig) - } - - @Test fun referenceLink() { - verifyMarkdownNode("referenceLink", defaultModelConfig) - } - - @Test fun externalReferenceLink() { - verifyMarkdownNode("externalReferenceLink", defaultModelConfig) - } - - @Test fun newlineInTableCell() { - verifyMarkdownPackage("newlineInTableCell", defaultModelConfig) - } - - @Test fun indentedCodeBlock() { - verifyMarkdownNode("indentedCodeBlock", defaultModelConfig) - } - - @Test fun receiverReference() { - verifyMarkdownNode("receiverReference", defaultModelConfig) - } - - @Test fun extensionScope() { - verifyMarkdownNodeByName("extensionScope", "test", defaultModelConfig) - } - - @Test fun typeParameterReference() { - verifyMarkdownNode("typeParameterReference", defaultModelConfig) - } - - @Test fun notPublishedTypeAliasAutoExpansion() { - verifyMarkdownNodeByName("notPublishedTypeAliasAutoExpansion", "foo", ModelConfig( - analysisPlatform = analysisPlatform, - includeNonPublic = false - )) - } - - @Test fun companionImplements() { - verifyMarkdownNodeByName("companionImplements", "Foo", defaultModelConfig) - } - - - private fun buildMultiplePlatforms(path: String): DocumentationModule { - val module = DocumentationModule("test") - val options = DocumentationOptions( - outputDir = "", - outputFormat = "html", - generateIndexPages = false, - noStdlibLink = true, - languageVersion = null, - apiVersion = null - ) - appendDocumentation( - module, options, ModelConfig( - roots = arrayOf(contentRootFromPath("testdata/format/$path/jvm.kt")), - defaultPlatforms = listOf("JVM"), - analysisPlatform = Platform.jvm - ) - ) - appendDocumentation( - module, options, ModelConfig( - roots = arrayOf(contentRootFromPath("testdata/format/$path/js.kt")), - defaultPlatforms = listOf("JS"), - analysisPlatform = Platform.js - ) - ) - - return module - } - - private fun verifyMultiplatformPackage(module: DocumentationModule, path: String) { - verifyModelOutput(module, ".package.md", "testdata/format/$path/multiplatform.kt") { model, output -> - buildPagesAndReadInto(model.members, output) - } - } - - private fun verifyMultiplatformIndex(module: DocumentationModule, path: String) { - verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.index.kt") { - model, output -> - val service = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf()) - fileGenerator.formatService = service - buildPagesAndReadInto(listOf(model), output) - } - } - - @Test fun blankLineInsideCodeBlock() { - verifyMarkdownNode("blankLineInsideCodeBlock", defaultModelConfig) - } - - protected fun verifyMarkdownPackage(fileName: String, modelConfig: ModelConfig = ModelConfig()) { - verifyOutput("testdata/format/$fileName.kt", ".package.md", modelConfig) { model, output -> - buildPagesAndReadInto(model.members, output) - } - } - - protected fun verifyMarkdownNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { - verifyMarkdownNodes(fileName, modelConfig) { model -> model.members.single().members } - } - - protected fun verifyMarkdownNodes( - fileName: String, - modelConfig: ModelConfig = ModelConfig(), - nodeFilter: (DocumentationModule) -> List - ) { - verifyOutput( - "testdata/format/$fileName.kt", - ".md", - modelConfig - ) { model, output -> - buildPagesAndReadInto(nodeFilter(model), output) - } - } - - protected fun verifyJavaMarkdownNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { - verifyJavaMarkdownNodes(fileName, modelConfig) { model -> model.members.single().members } - } - - protected fun verifyJavaMarkdownNodes(fileName: String, modelConfig: ModelConfig = ModelConfig(), nodeFilter: (DocumentationModule) -> List) { - verifyJavaOutput("testdata/format/$fileName.java", ".md", modelConfig) { model, output -> - buildPagesAndReadInto(nodeFilter(model), output) - } - } - - protected fun verifyMarkdownNodeByName( - fileName: String, - name: String, - modelConfig: ModelConfig = ModelConfig() - ) { - verifyMarkdownNodes(fileName, modelConfig) { model-> - val nodesWithName = model.members.single().members.filter { it.name == name } - if (nodesWithName.isEmpty()) { - throw IllegalArgumentException("Found no nodes named $name") - } - nodesWithName - } - } -} diff --git a/core/src/test/kotlin/format/GFMFormatTest.kt b/core/src/test/kotlin/format/GFMFormatTest.kt index b90ab2bf..60de7d29 100644 --- a/core/src/test/kotlin/format/GFMFormatTest.kt +++ b/core/src/test/kotlin/format/GFMFormatTest.kt @@ -2,23 +2,26 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.GFMFormatService import org.jetbrains.dokka.KotlinLanguageService +import org.jetbrains.dokka.Platform import org.junit.Test -class GFMFormatTest : FileGeneratorTestCase() { +abstract class BaseGFMFormatTest(val analysisPlatform: Platform) : FileGeneratorTestCase() { override val formatService = GFMFormatService(fileGenerator, KotlinLanguageService(), listOf()) + private val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) + @Test fun sample() { - verifyGFMNodeByName("sample", "Foo") + verifyGFMNodeByName("sample", "Foo", defaultModelConfig) } @Test fun listInTableCell() { - verifyGFMNodeByName("listInTableCell", "Foo") + verifyGFMNodeByName("listInTableCell", "Foo", defaultModelConfig) } - private fun verifyGFMNodeByName(fileName: String, name: String) { - verifyOutput("testdata/format/gfm/$fileName.kt", ".md") { model, output -> + private fun verifyGFMNodeByName(fileName: String, name: String, modelConfig: ModelConfig) { + verifyOutput("testdata/format/gfm/$fileName.kt", ".md", modelConfig) { model, output -> buildPagesAndReadInto( model.members.single().members.filter { it.name == name }, output @@ -26,3 +29,8 @@ class GFMFormatTest : FileGeneratorTestCase() { } } } + + +class JsGFMFormatTest : BaseGFMFormatTest(Platform.js) +class JvmGFMFormatTest : BaseGFMFormatTest(Platform.jvm) +class CommonGFMFormatTest : BaseGFMFormatTest(Platform.common) \ No newline at end of file diff --git a/core/src/test/kotlin/format/HtmlFormatTest.kt b/core/src/test/kotlin/format/HtmlFormatTest.kt new file mode 100644 index 00000000..20891963 --- /dev/null +++ b/core/src/test/kotlin/format/HtmlFormatTest.kt @@ -0,0 +1,193 @@ +package org.jetbrains.dokka.tests + +import org.jetbrains.dokka.* +import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot +import org.jetbrains.kotlin.config.KotlinSourceRoot +import org.junit.Before +import org.junit.Test +import java.io.File + +abstract class BaseHtmlFormatTest(val analysisPlatform: Platform): FileGeneratorTestCase() { + protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) + override val formatService = HtmlFormatService(fileGenerator, KotlinLanguageService(), HtmlTemplateService.default(), listOf()) + + @Test fun classWithCompanionObject() { + verifyHtmlNode("classWithCompanionObject", defaultModelConfig) + } + + @Test fun htmlEscaping() { + verifyHtmlNode("htmlEscaping", defaultModelConfig) + } + + @Test fun overloads() { + verifyHtmlNodes("overloads", defaultModelConfig) { model -> model.members } + } + + @Test fun overloadsWithDescription() { + verifyHtmlNode("overloadsWithDescription", defaultModelConfig) + } + + @Test fun overloadsWithDifferentDescriptions() { + verifyHtmlNode("overloadsWithDifferentDescriptions", defaultModelConfig) + } + + @Test fun deprecated() { + verifyOutput("testdata/format/deprecated.kt", ".package.html", defaultModelConfig) { model, output -> + buildPagesAndReadInto(model.members, output) + } + verifyOutput("testdata/format/deprecated.kt", ".class.html", defaultModelConfig) { model, output -> + buildPagesAndReadInto(model.members.single().members, output) + } + } + + @Test fun brokenLink() { + verifyHtmlNode("brokenLink", defaultModelConfig) + } + + @Test fun codeSpan() { + verifyHtmlNode("codeSpan", defaultModelConfig) + } + + @Test fun parenthesis() { + verifyHtmlNode("parenthesis", defaultModelConfig) + } + + @Test fun bracket() { + verifyHtmlNode("bracket", defaultModelConfig) + } + + @Test fun see() { + verifyHtmlNode("see", defaultModelConfig) + } + + @Test fun tripleBackticks() { + verifyHtmlNode("tripleBackticks", defaultModelConfig) + } + + @Test fun typeLink() { + verifyHtmlNodes("typeLink", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } + } + + @Test fun parameterAnchor() { + verifyHtmlNode("parameterAnchor", defaultModelConfig) + } + + @Test fun codeBlock() { + verifyHtmlNode("codeBlock", defaultModelConfig) + } + @Test fun orderedList() { + verifyHtmlNodes("orderedList", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } + } + + @Test fun linkWithLabel() { + verifyHtmlNodes("linkWithLabel", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } + } + + @Test fun entity() { + verifyHtmlNodes("entity", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } + } + + @Test fun uninterpretedEmphasisCharacters() { + verifyHtmlNode("uninterpretedEmphasisCharacters", defaultModelConfig) + } + + @Test fun markdownInLinks() { + verifyHtmlNode("markdownInLinks", defaultModelConfig) + } + + @Test fun returnWithLink() { + verifyHtmlNode("returnWithLink", defaultModelConfig) + } + + @Test fun linkWithStarProjection() { + verifyHtmlNode("linkWithStarProjection", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + } + + @Test fun functionalTypeWithNamedParameters() { + verifyHtmlNode("functionalTypeWithNamedParameters", defaultModelConfig) + } + + @Test fun sinceKotlin() { + verifyHtmlNode("sinceKotlin", defaultModelConfig) + } + + @Test fun blankLineInsideCodeBlock() { + verifyHtmlNode("blankLineInsideCodeBlock", defaultModelConfig) + } + + @Test fun indentedCodeBlock() { + verifyHtmlNode("indentedCodeBlock", defaultModelConfig) + } + + private fun verifyHtmlNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { + verifyHtmlNodes(fileName, modelConfig) { model -> model.members.single().members } + } + + private fun verifyHtmlNodes(fileName: String, + modelConfig: ModelConfig = ModelConfig(), + nodeFilter: (DocumentationModule) -> List) { + verifyOutput("testdata/format/$fileName.kt", ".html", modelConfig) { model, output -> + buildPagesAndReadInto(nodeFilter(model), output) + } + } + + protected fun verifyJavaHtmlNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { + verifyJavaHtmlNodes(fileName, modelConfig) { model -> model.members.single().members } + } + + protected fun verifyJavaHtmlNodes(fileName: String, + modelConfig: ModelConfig = ModelConfig(), + nodeFilter: (DocumentationModule) -> List) { + verifyJavaOutput("testdata/format/$fileName.java", ".html", modelConfig) { model, output -> + buildPagesAndReadInto(nodeFilter(model), output) + } + } +} + +class JSHtmlFormatTest: BaseHtmlFormatTest(Platform.js) + +class JVMHtmlFormatTest: BaseHtmlFormatTest(Platform.jvm) { + @Test + fun javaSeeTag() { + verifyJavaHtmlNode("javaSeeTag", defaultModelConfig) + } + + @Test fun javaDeprecated() { + verifyJavaHtmlNodes("javaDeprecated", defaultModelConfig) { model -> + model.members.single().members.single { it.name == "Foo" }.members.filter { it.name == "foo" } + } + } + + @Test fun crossLanguageKotlinExtendsJava() { + verifyOutput( + ModelConfig( + roots = arrayOf( + KotlinSourceRoot("testdata/format/crossLanguage/kotlinExtendsJava/Bar.kt"), + JavaSourceRoot(File("testdata/format/crossLanguage/kotlinExtendsJava"), null) + ), + analysisPlatform = analysisPlatform + ), ".html") { model, output -> + buildPagesAndReadInto( + model.members.single().members.filter { it.name == "Bar" }, + output + ) + } + } + + @Test fun javaLinkTag() { + verifyJavaHtmlNode("javaLinkTag", defaultModelConfig) + } + + @Test fun javaLinkTagWithLabel() { + verifyJavaHtmlNode("javaLinkTagWithLabel", defaultModelConfig) + } + + @Test fun javaSupertypeLink() { + verifyJavaHtmlNodes("JavaSupertype", defaultModelConfig) { model -> + model.members.single().members.single { it.name == "JavaSupertype" }.members.filter { it.name == "Bar" } + } + } + +} + +class CommonHtmlFormatTest: BaseHtmlFormatTest(Platform.common) \ No newline at end of file diff --git a/core/src/test/kotlin/format/JSHtmlFormatTest.kt b/core/src/test/kotlin/format/JSHtmlFormatTest.kt deleted file mode 100644 index afa0ce0a..00000000 --- a/core/src/test/kotlin/format/JSHtmlFormatTest.kt +++ /dev/null @@ -1,6 +0,0 @@ -package org.jetbrains.dokka.tests.format - -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.tests.BaseHtmlFormatTest - -class JSHtmlFormatTest: BaseHtmlFormatTest(Platform.js) {} \ No newline at end of file diff --git a/core/src/test/kotlin/format/JSMarkdownFormatTest.kt b/core/src/test/kotlin/format/JSMarkdownFormatTest.kt deleted file mode 100644 index ca92d9f6..00000000 --- a/core/src/test/kotlin/format/JSMarkdownFormatTest.kt +++ /dev/null @@ -1,7 +0,0 @@ -package org.jetbrains.dokka.tests.format - -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.tests.BaseMarkdownFormatTest - -class JSMarkdownFormatTest: BaseMarkdownFormatTest(Platform.js) { -} \ No newline at end of file diff --git a/core/src/test/kotlin/format/JVMHtmlFormatTest.kt b/core/src/test/kotlin/format/JVMHtmlFormatTest.kt deleted file mode 100644 index 1696ffb2..00000000 --- a/core/src/test/kotlin/format/JVMHtmlFormatTest.kt +++ /dev/null @@ -1,54 +0,0 @@ -package org.jetbrains.dokka.tests.format - -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.tests.BaseHtmlFormatTest -import org.jetbrains.dokka.tests.ModelConfig -import org.jetbrains.dokka.tests.verifyOutput -import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot -import org.jetbrains.kotlin.config.KotlinSourceRoot -import org.junit.Test -import java.io.File - -class JVMHtmlFormatTest: BaseHtmlFormatTest(Platform.jvm) { - @Test - fun javaSeeTag() { - verifyJavaHtmlNode("javaSeeTag", defaultModelConfig) - } - - @Test fun javaDeprecated() { - verifyJavaHtmlNodes("javaDeprecated", defaultModelConfig) { model -> - model.members.single().members.single { it.name == "Foo" }.members.filter { it.name == "foo" } - } - } - - @Test fun crossLanguageKotlinExtendsJava() { - verifyOutput( - ModelConfig( - roots = arrayOf( - KotlinSourceRoot("testdata/format/crossLanguage/kotlinExtendsJava/Bar.kt"), - JavaSourceRoot(File("testdata/format/crossLanguage/kotlinExtendsJava"), null) - ), - analysisPlatform = analysisPlatform - ), ".html") { model, output -> - buildPagesAndReadInto( - model.members.single().members.filter { it.name == "Bar" }, - output - ) - } - } - - @Test fun javaLinkTag() { - verifyJavaHtmlNode("javaLinkTag", defaultModelConfig) - } - - @Test fun javaLinkTagWithLabel() { - verifyJavaHtmlNode("javaLinkTagWithLabel", defaultModelConfig) - } - - @Test fun javaSupertypeLink() { - verifyJavaHtmlNodes("JavaSupertype", defaultModelConfig) { model -> - model.members.single().members.single { it.name == "JavaSupertype" }.members.filter { it.name == "Bar" } - } - } - -} \ No newline at end of file diff --git a/core/src/test/kotlin/format/JVMMarkdownFormatTest.kt b/core/src/test/kotlin/format/JVMMarkdownFormatTest.kt deleted file mode 100644 index ee8169af..00000000 --- a/core/src/test/kotlin/format/JVMMarkdownFormatTest.kt +++ /dev/null @@ -1,117 +0,0 @@ -package org.jetbrains.dokka.tests.format - -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.contentRootFromPath -import org.jetbrains.dokka.tests.BaseMarkdownFormatTest -import org.jetbrains.dokka.tests.ModelConfig -import org.jetbrains.dokka.tests.verifyOutput -import org.junit.Test - -class JVMMarkdownFormatTest: BaseMarkdownFormatTest(Platform.jvm) { - - @Test - fun enumRef() { - verifyMarkdownNode("enumRef", defaultModelConfig) - } - - @Test - fun javaCodeLiteralTags() { - verifyJavaMarkdownNode("javaCodeLiteralTags", defaultModelConfig) - } - - @Test - fun nullability() { - verifyMarkdownNode("nullability", defaultModelConfig) - } - - @Test - fun exceptionClass() { - verifyMarkdownNode( - "exceptionClass", ModelConfig( - analysisPlatform = analysisPlatform, - withKotlinRuntime = true - ) - ) - verifyMarkdownPackage( - "exceptionClass", ModelConfig( - analysisPlatform = analysisPlatform, - withKotlinRuntime = true - ) - ) - } - - @Test - fun operatorOverloading() { - verifyMarkdownNodes("operatorOverloading", defaultModelConfig) { model-> - model.members.single().members.single { it.name == "C" }.members.filter { it.name == "plus" } - } - } - - @Test - fun extensions() { - verifyOutput("testdata/format/extensions.kt", ".package.md", defaultModelConfig) { model, output -> - buildPagesAndReadInto(model.members, output) - } - verifyOutput("testdata/format/extensions.kt", ".class.md", defaultModelConfig) { model, output -> - buildPagesAndReadInto(model.members.single().members, output) - } - } - - @Test - fun summarizeSignaturesProperty() { - verifyMarkdownNodes("summarizeSignaturesProperty", defaultModelConfig) { model -> model.members } - } - - @Test - fun javaSpaceInAuthor() { - verifyJavaMarkdownNode("javaSpaceInAuthor", defaultModelConfig) - } - - @Test - fun javaCodeInParam() { - verifyJavaMarkdownNode("javaCodeInParam", defaultModelConfig) - } - - @Test - fun annotationParams() { - verifyMarkdownNode("annotationParams", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) - } - - @Test fun inheritedLink() { - val filePath = "testdata/format/inheritedLink" - verifyOutput( - filePath, - ".md", - ModelConfig( - roots = arrayOf( - contentRootFromPath("$filePath.kt"), - contentRootFromPath("$filePath.1.kt") - ), - withJdk = true, - withKotlinRuntime = true, - includeNonPublic = false, - analysisPlatform = analysisPlatform - - ) - ) { model, output -> - buildPagesAndReadInto(model.members.single { it.name == "p2" }.members.single().members, output) - } - } - - @Test - fun javadocOrderedList() { - verifyJavaMarkdownNodes("javadocOrderedList", defaultModelConfig) { model -> - model.members.single().members.filter { it.name == "Bar" } - } - } - - @Test - fun jdkLinks() { - verifyMarkdownNode("jdkLinks", ModelConfig(withKotlinRuntime = true, analysisPlatform = analysisPlatform)) - } - - @Test - fun javadocHtml() { - verifyJavaMarkdownNode("javadocHtml", defaultModelConfig) - } -} diff --git a/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt index c02d3ad4..5df43017 100644 --- a/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt +++ b/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt @@ -3,35 +3,36 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.* import org.junit.Test -class KotlinWebSiteHtmlFormatTest: FileGeneratorTestCase() { +abstract class BaseKotlinWebSiteHtmlFormatTest(val analysisPlatform: Platform): FileGeneratorTestCase() { + val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) override val formatService = KotlinWebsiteHtmlFormatService(fileGenerator, KotlinLanguageService(), listOf(), EmptyHtmlTemplateService) @Test fun dropImport() { - verifyKWSNodeByName("dropImport", "foo") + verifyKWSNodeByName("dropImport", "foo", defaultModelConfig) } @Test fun sample() { - verifyKWSNodeByName("sample", "foo") + verifyKWSNodeByName("sample", "foo", defaultModelConfig) } @Test fun sampleWithAsserts() { - verifyKWSNodeByName("sampleWithAsserts", "a") + verifyKWSNodeByName("sampleWithAsserts", "a", defaultModelConfig) } @Test fun newLinesInSamples() { - verifyKWSNodeByName("newLinesInSamples", "foo") + verifyKWSNodeByName("newLinesInSamples", "foo", defaultModelConfig) } @Test fun newLinesInImportList() { - verifyKWSNodeByName("newLinesInImportList", "foo") + verifyKWSNodeByName("newLinesInImportList", "foo", defaultModelConfig) } @Test fun returnTag() { - verifyKWSNodeByName("returnTag", "indexOf") + verifyKWSNodeByName("returnTag", "indexOf", defaultModelConfig) } @Test fun overloadGroup() { - verifyKWSNodeByName("overloadGroup", "magic") + verifyKWSNodeByName("overloadGroup", "magic", defaultModelConfig) } @Test fun dataTags() { @@ -51,8 +52,12 @@ class KotlinWebSiteHtmlFormatTest: FileGeneratorTestCase() { verifyMultiplatformPackage(module, path) } - private fun verifyKWSNodeByName(fileName: String, name: String) { - verifyOutput("testdata/format/website-html/$fileName.kt", ".html", ModelConfig(format = "kotlin-website-html")) { model, output -> + private fun verifyKWSNodeByName(fileName: String, name: String, modelConfig: ModelConfig) { + verifyOutput( + "testdata/format/website-html/$fileName.kt", + ".html", + ModelConfig(analysisPlatform = modelConfig.analysisPlatform, format = "kotlin-website-html") + ) { model, output -> buildPagesAndReadInto(model.members.single().members.filter { it.name == name }, output) } } @@ -96,3 +101,7 @@ class KotlinWebSiteHtmlFormatTest: FileGeneratorTestCase() { } } + +class JsKotlinWebSiteHtmlFormatTest: BaseKotlinWebSiteHtmlFormatTest(Platform.js) +class JvmKotlinWebSiteHtmlFormatTest: BaseKotlinWebSiteHtmlFormatTest(Platform.jvm) +class CommonKotlinWebSiteHtmlFormatTest: BaseKotlinWebSiteHtmlFormatTest(Platform.common) \ No newline at end of file diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt new file mode 100644 index 00000000..6c62587b --- /dev/null +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -0,0 +1,580 @@ +package org.jetbrains.dokka.tests + +import org.jetbrains.dokka.* +import org.junit.Before +import org.junit.Test + +abstract class BaseMarkdownFormatTest(val analysisPlatform: Platform): FileGeneratorTestCase() { + override val formatService = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf()) + + protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) + + @Test fun emptyDescription() { + verifyMarkdownNode("emptyDescription", defaultModelConfig) + } + + @Test fun classWithCompanionObject() { + verifyMarkdownNode("classWithCompanionObject", defaultModelConfig) + } + + @Test fun annotations() { + verifyMarkdownNode("annotations", defaultModelConfig) + } + + @Test fun annotationClass() { + verifyMarkdownNode("annotationClass", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + verifyMarkdownPackage("annotationClass", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + } + + @Test fun enumClass() { + verifyOutput("testdata/format/enumClass.kt", ".md", defaultModelConfig) { model, output -> + buildPagesAndReadInto(model.members.single().members, output) + } + verifyOutput("testdata/format/enumClass.kt", ".value.md", defaultModelConfig) { model, output -> + val enumClassNode = model.members.single().members[0] + buildPagesAndReadInto( + enumClassNode.members.filter { it.name == "LOCAL_CONTINUE_AND_BREAK" }, + output + ) + } + } + + @Test fun varargsFunction() { + verifyMarkdownNode("varargsFunction", defaultModelConfig) + } + + @Test fun overridingFunction() { + verifyMarkdownNodes("overridingFunction", defaultModelConfig) { model-> + val classMembers = model.members.single().members.first { it.name == "D" }.members + classMembers.filter { it.name == "f" } + } + } + + @Test fun propertyVar() { + verifyMarkdownNode("propertyVar", defaultModelConfig) + } + + @Test fun functionWithDefaultParameter() { + verifyMarkdownNode("functionWithDefaultParameter", defaultModelConfig) + } + + @Test fun accessor() { + verifyMarkdownNodes("accessor", defaultModelConfig) { model -> + model.members.single().members.first { it.name == "C" }.members.filter { it.name == "x" } + } + } + + @Test fun paramTag() { + verifyMarkdownNode("paramTag", defaultModelConfig) + } + + @Test fun throwsTag() { + verifyMarkdownNode("throwsTag", defaultModelConfig) + } + + @Test fun typeParameterBounds() { + verifyMarkdownNode("typeParameterBounds", defaultModelConfig) + } + + @Test fun typeParameterVariance() { + verifyMarkdownNode("typeParameterVariance", defaultModelConfig) + } + + @Test fun typeProjectionVariance() { + verifyMarkdownNode("typeProjectionVariance", defaultModelConfig) + } + + @Test fun codeBlockNoHtmlEscape() { + verifyMarkdownNodeByName("codeBlockNoHtmlEscape", "hackTheArithmetic", defaultModelConfig) + } + + @Test fun companionObjectExtension() { + verifyMarkdownNodeByName("companionObjectExtension", "Foo", defaultModelConfig) + } + + @Test fun starProjection() { + verifyMarkdownNode("starProjection", defaultModelConfig) + } + + @Test fun extensionFunctionParameter() { + verifyMarkdownNode("extensionFunctionParameter", defaultModelConfig) + } + + @Test fun summarizeSignatures() { + verifyMarkdownNodes("summarizeSignatures", defaultModelConfig) { model -> model.members } + } + + @Test fun reifiedTypeParameter() { + verifyMarkdownNode("reifiedTypeParameter", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + } + + @Test fun annotatedTypeParameter() { + verifyMarkdownNode("annotatedTypeParameter", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + } + + @Test fun inheritedMembers() { + verifyMarkdownNodeByName("inheritedMembers", "Bar", defaultModelConfig) + } + + @Test fun inheritedExtensions() { + verifyMarkdownNodeByName("inheritedExtensions", "Bar", defaultModelConfig) + } + + @Test fun genericInheritedExtensions() { + verifyMarkdownNodeByName("genericInheritedExtensions", "Bar", defaultModelConfig) + } + + @Test fun arrayAverage() { + verifyMarkdownNodeByName("arrayAverage", "XArray", defaultModelConfig) + } + + @Test fun multipleTypeParameterConstraints() { + verifyMarkdownNode("multipleTypeParameterConstraints", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + } + + @Test fun inheritedCompanionObjectProperties() { + verifyMarkdownNodeByName("inheritedCompanionObjectProperties", "C", defaultModelConfig) + } + + @Test fun shadowedExtensionFunctions() { + verifyMarkdownNodeByName("shadowedExtensionFunctions", "Bar", defaultModelConfig) + } + + @Test fun inapplicableExtensionFunctions() { + verifyMarkdownNodeByName("inapplicableExtensionFunctions", "Bar", defaultModelConfig) + } + + @Test fun receiverParameterTypeBound() { + verifyMarkdownNodeByName("receiverParameterTypeBound", "Foo", defaultModelConfig) + } + + @Test fun extensionWithDocumentedReceiver() { + verifyMarkdownNodes("extensionWithDocumentedReceiver", defaultModelConfig) { model -> + model.members.single().members.single().members.filter { it.name == "fn" } + } + } + + @Test fun codeBlock() { + verifyMarkdownNode("codeBlock", defaultModelConfig) + } + + @Test fun exclInCodeBlock() { + verifyMarkdownNodeByName("exclInCodeBlock", "foo", defaultModelConfig) + } + + @Test fun backtickInCodeBlock() { + verifyMarkdownNodeByName("backtickInCodeBlock", "foo", defaultModelConfig) + } + + @Test fun qualifiedNameLink() { + verifyMarkdownNodeByName("qualifiedNameLink", "foo", + ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + } + + @Test fun functionalTypeWithNamedParameters() { + verifyMarkdownNode("functionalTypeWithNamedParameters", defaultModelConfig) + } + + @Test fun typeAliases() { + verifyMarkdownNode("typeAliases", defaultModelConfig) + verifyMarkdownPackage("typeAliases", defaultModelConfig) + } + + @Test fun sampleByShortName() { + verifyMarkdownNode("sampleByShortName", defaultModelConfig) + } + + + @Test fun suspendParam() { + verifyMarkdownNode("suspendParam", defaultModelConfig) + verifyMarkdownPackage("suspendParam", defaultModelConfig) + } + + @Test fun sinceKotlin() { + verifyMarkdownNode("sinceKotlin", defaultModelConfig) + verifyMarkdownPackage("sinceKotlin", defaultModelConfig) + } + + @Test fun sinceKotlinWide() { + verifyMarkdownPackage("sinceKotlinWide", defaultModelConfig) + } + + @Test fun dynamicType() { + verifyMarkdownNode("dynamicType", defaultModelConfig) + } + + @Test fun dynamicExtension() { + verifyMarkdownNodes("dynamicExtension", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Foo" } } + } + + @Test fun memberExtension() { + verifyMarkdownNodes("memberExtension", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Foo" } } + } + + @Test fun renderFunctionalTypeInParenthesisWhenItIsReceiver() { + verifyMarkdownNode("renderFunctionalTypeInParenthesisWhenItIsReceiver", defaultModelConfig) + } + + @Test fun multiplePlatforms() { + verifyMultiplatformPackage(buildMultiplePlatforms("multiplatform/simple"), "multiplatform/simple") + } + + @Test fun multiplePlatformsMerge() { + verifyMultiplatformPackage(buildMultiplePlatforms("multiplatform/merge"), "multiplatform/merge") + } + + @Test fun multiplePlatformsMergeMembers() { + val module = buildMultiplePlatforms("multiplatform/mergeMembers") + verifyModelOutput(module, ".md", "testdata/format/multiplatform/mergeMembers/foo.kt") { model, output -> + buildPagesAndReadInto(model.members.single().members, output) + } + } + + @Test fun multiplePlatformsOmitRedundant() { + val module = buildMultiplePlatforms("multiplatform/omitRedundant") + verifyModelOutput(module, ".md", "testdata/format/multiplatform/omitRedundant/foo.kt") { model, output -> + buildPagesAndReadInto(model.members.single().members, output) + } + } + + @Test fun multiplePlatformsImplied() { + val module = buildMultiplePlatforms("multiplatform/implied") + verifyModelOutput(module, ".md", "testdata/format/multiplatform/implied/foo.kt") { model, output -> + val service = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf("JVM", "JS")) + fileGenerator.formatService = service + buildPagesAndReadInto(model.members.single().members, output) + } + } + + @Test fun packagePlatformsWithExtExtensions() { + val path = "multiplatform/packagePlatformsWithExtExtensions" + val module = DocumentationModule("test") + val options = DocumentationOptions( + outputDir = "", + outputFormat = "html", + generateIndexPages = false, + noStdlibLink = true, + languageVersion = null, + apiVersion = null + ) + appendDocumentation(module, options, ModelConfig( + roots = arrayOf(contentRootFromPath("testdata/format/$path/jvm.kt")), + defaultPlatforms = listOf("JVM"), + withKotlinRuntime = true, + analysisPlatform = analysisPlatform + ) + ) + verifyMultiplatformIndex(module, path) + verifyMultiplatformPackage(module, path) + } + + @Test fun multiplePlatformsPackagePlatformFromMembers() { + val path = "multiplatform/packagePlatformsFromMembers" + val module = buildMultiplePlatforms(path) + verifyMultiplatformIndex(module, path) + verifyMultiplatformPackage(module, path) + } + + @Test fun multiplePlatformsGroupNode() { + val path = "multiplatform/groupNode" + val module = buildMultiplePlatforms(path) + verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.kt") { model, output -> + buildPagesAndReadInto( + listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }), + output + ) + } + verifyMultiplatformPackage(module, path) + } + + @Test fun multiplePlatformsBreadcrumbsInMemberOfMemberOfGroupNode() { + val path = "multiplatform/breadcrumbsInMemberOfMemberOfGroupNode" + val module = buildMultiplePlatforms(path) + verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.kt") { model, output -> + buildPagesAndReadInto( + listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }?.member(NodeKind.Class)?.member(NodeKind.Function)), + output + ) + } + } + + @Test fun linksInEmphasis() { + verifyMarkdownNode("linksInEmphasis", defaultModelConfig) + } + + @Test fun linksInStrong() { + verifyMarkdownNode("linksInStrong", defaultModelConfig) + } + + @Test fun linksInHeaders() { + verifyMarkdownNode("linksInHeaders", defaultModelConfig) + } + + @Test fun tokensInEmphasis() { + verifyMarkdownNode("tokensInEmphasis", defaultModelConfig) + } + + @Test fun tokensInStrong() { + verifyMarkdownNode("tokensInStrong", defaultModelConfig) + } + + @Test fun tokensInHeaders() { + verifyMarkdownNode("tokensInHeaders", defaultModelConfig) + } + + @Test fun unorderedLists() { + verifyMarkdownNode("unorderedLists", defaultModelConfig) + } + + @Test fun nestedLists() { + verifyMarkdownNode("nestedLists", defaultModelConfig) + } + + @Test fun referenceLink() { + verifyMarkdownNode("referenceLink", defaultModelConfig) + } + + @Test fun externalReferenceLink() { + verifyMarkdownNode("externalReferenceLink", defaultModelConfig) + } + + @Test fun newlineInTableCell() { + verifyMarkdownPackage("newlineInTableCell", defaultModelConfig) + } + + @Test fun indentedCodeBlock() { + verifyMarkdownNode("indentedCodeBlock", defaultModelConfig) + } + + @Test fun receiverReference() { + verifyMarkdownNode("receiverReference", defaultModelConfig) + } + + @Test fun extensionScope() { + verifyMarkdownNodeByName("extensionScope", "test", defaultModelConfig) + } + + @Test fun typeParameterReference() { + verifyMarkdownNode("typeParameterReference", defaultModelConfig) + } + + @Test fun notPublishedTypeAliasAutoExpansion() { + verifyMarkdownNodeByName("notPublishedTypeAliasAutoExpansion", "foo", ModelConfig( + analysisPlatform = analysisPlatform, + includeNonPublic = false + )) + } + + @Test fun companionImplements() { + verifyMarkdownNodeByName("companionImplements", "Foo", defaultModelConfig) + } + + + private fun buildMultiplePlatforms(path: String): DocumentationModule { + val module = DocumentationModule("test") + val options = DocumentationOptions( + outputDir = "", + outputFormat = "html", + generateIndexPages = false, + noStdlibLink = true, + languageVersion = null, + apiVersion = null + ) + appendDocumentation( + module, options, ModelConfig( + roots = arrayOf(contentRootFromPath("testdata/format/$path/jvm.kt")), + defaultPlatforms = listOf("JVM"), + analysisPlatform = Platform.jvm + ) + ) + appendDocumentation( + module, options, ModelConfig( + roots = arrayOf(contentRootFromPath("testdata/format/$path/js.kt")), + defaultPlatforms = listOf("JS"), + analysisPlatform = Platform.js + ) + ) + + return module + } + + private fun verifyMultiplatformPackage(module: DocumentationModule, path: String) { + verifyModelOutput(module, ".package.md", "testdata/format/$path/multiplatform.kt") { model, output -> + buildPagesAndReadInto(model.members, output) + } + } + + private fun verifyMultiplatformIndex(module: DocumentationModule, path: String) { + verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.index.kt") { + model, output -> + val service = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf()) + fileGenerator.formatService = service + buildPagesAndReadInto(listOf(model), output) + } + } + + @Test fun blankLineInsideCodeBlock() { + verifyMarkdownNode("blankLineInsideCodeBlock", defaultModelConfig) + } + + protected fun verifyMarkdownPackage(fileName: String, modelConfig: ModelConfig = ModelConfig()) { + verifyOutput("testdata/format/$fileName.kt", ".package.md", modelConfig) { model, output -> + buildPagesAndReadInto(model.members, output) + } + } + + protected fun verifyMarkdownNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { + verifyMarkdownNodes(fileName, modelConfig) { model -> model.members.single().members } + } + + protected fun verifyMarkdownNodes( + fileName: String, + modelConfig: ModelConfig = ModelConfig(), + nodeFilter: (DocumentationModule) -> List + ) { + verifyOutput( + "testdata/format/$fileName.kt", + ".md", + modelConfig + ) { model, output -> + buildPagesAndReadInto(nodeFilter(model), output) + } + } + + protected fun verifyJavaMarkdownNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { + verifyJavaMarkdownNodes(fileName, modelConfig) { model -> model.members.single().members } + } + + protected fun verifyJavaMarkdownNodes(fileName: String, modelConfig: ModelConfig = ModelConfig(), nodeFilter: (DocumentationModule) -> List) { + verifyJavaOutput("testdata/format/$fileName.java", ".md", modelConfig) { model, output -> + buildPagesAndReadInto(nodeFilter(model), output) + } + } + + protected fun verifyMarkdownNodeByName( + fileName: String, + name: String, + modelConfig: ModelConfig = ModelConfig() + ) { + verifyMarkdownNodes(fileName, modelConfig) { model-> + val nodesWithName = model.members.single().members.filter { it.name == name } + if (nodesWithName.isEmpty()) { + throw IllegalArgumentException("Found no nodes named $name") + } + nodesWithName + } + } +} + +class JSMarkdownFormatTest: BaseMarkdownFormatTest(Platform.js) + +class JVMMarkdownFormatTest: BaseMarkdownFormatTest(Platform.jvm) { + + @Test + fun enumRef() { + verifyMarkdownNode("enumRef", defaultModelConfig) + } + + @Test + fun javaCodeLiteralTags() { + verifyJavaMarkdownNode("javaCodeLiteralTags", defaultModelConfig) + } + + @Test + fun nullability() { + verifyMarkdownNode("nullability", defaultModelConfig) + } + + @Test + fun exceptionClass() { + verifyMarkdownNode( + "exceptionClass", ModelConfig( + analysisPlatform = analysisPlatform, + withKotlinRuntime = true + ) + ) + verifyMarkdownPackage( + "exceptionClass", ModelConfig( + analysisPlatform = analysisPlatform, + withKotlinRuntime = true + ) + ) + } + + @Test + fun operatorOverloading() { + verifyMarkdownNodes("operatorOverloading", defaultModelConfig) { model-> + model.members.single().members.single { it.name == "C" }.members.filter { it.name == "plus" } + } + } + + @Test + fun extensions() { + verifyOutput("testdata/format/extensions.kt", ".package.md", defaultModelConfig) { model, output -> + buildPagesAndReadInto(model.members, output) + } + verifyOutput("testdata/format/extensions.kt", ".class.md", defaultModelConfig) { model, output -> + buildPagesAndReadInto(model.members.single().members, output) + } + } + + @Test + fun summarizeSignaturesProperty() { + verifyMarkdownNodes("summarizeSignaturesProperty", defaultModelConfig) { model -> model.members } + } + + @Test + fun javaSpaceInAuthor() { + verifyJavaMarkdownNode("javaSpaceInAuthor", defaultModelConfig) + } + + @Test + fun javaCodeInParam() { + verifyJavaMarkdownNode("javaCodeInParam", defaultModelConfig) + } + + @Test + fun annotationParams() { + verifyMarkdownNode("annotationParams", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + } + + @Test fun inheritedLink() { + val filePath = "testdata/format/inheritedLink" + verifyOutput( + filePath, + ".md", + ModelConfig( + roots = arrayOf( + contentRootFromPath("$filePath.kt"), + contentRootFromPath("$filePath.1.kt") + ), + withJdk = true, + withKotlinRuntime = true, + includeNonPublic = false, + analysisPlatform = analysisPlatform + + ) + ) { model, output -> + buildPagesAndReadInto(model.members.single { it.name == "p2" }.members.single().members, output) + } + } + + @Test + fun javadocOrderedList() { + verifyJavaMarkdownNodes("javadocOrderedList", defaultModelConfig) { model -> + model.members.single().members.filter { it.name == "Bar" } + } + } + + @Test + fun jdkLinks() { + verifyMarkdownNode("jdkLinks", ModelConfig(withKotlinRuntime = true, analysisPlatform = analysisPlatform)) + } + + @Test + fun javadocHtml() { + verifyJavaMarkdownNode("javadocHtml", defaultModelConfig) + } +} + +class CommonMarkdownFormatTest: BaseMarkdownFormatTest(Platform.common) \ No newline at end of file diff --git a/core/src/test/kotlin/issues/IssuesTest.kt b/core/src/test/kotlin/issues/IssuesTest.kt index 58b3a2d2..da5acd6e 100644 --- a/core/src/test/kotlin/issues/IssuesTest.kt +++ b/core/src/test/kotlin/issues/IssuesTest.kt @@ -2,18 +2,19 @@ package issues import org.jetbrains.dokka.DocumentationNode import org.jetbrains.dokka.NodeKind +import org.jetbrains.dokka.Platform import org.jetbrains.dokka.tests.ModelConfig import org.jetbrains.dokka.tests.checkSourceExistsAndVerifyModel import org.junit.Test import kotlin.test.assertEquals - -class IssuesTest { +abstract class BaseIssuesTest(val analysisPlatform: Platform) { + val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) @Test fun errorClasses() { checkSourceExistsAndVerifyModel("testdata/issues/errorClasses.kt", - modelConfig = ModelConfig(withJdk = true, withKotlinRuntime = true)) { model -> + modelConfig = ModelConfig(analysisPlatform = analysisPlatform, withJdk = true, withKotlinRuntime = true)) { model -> val cls = model.members.single().members.single() fun DocumentationNode.returnType() = this.details.find { it.kind == NodeKind.Type }?.name @@ -27,3 +28,7 @@ class IssuesTest { } } } + +class JSIssuesTest: BaseIssuesTest(Platform.js) +class JVMIssuesTest: BaseIssuesTest(Platform.jvm) +class CommonIssuesTest: BaseIssuesTest(Platform.common) \ No newline at end of file diff --git a/core/src/test/kotlin/javadoc/JavadocTest.kt b/core/src/test/kotlin/javadoc/JavadocTest.kt index dc576b61..7976fccc 100644 --- a/core/src/test/kotlin/javadoc/JavadocTest.kt +++ b/core/src/test/kotlin/javadoc/JavadocTest.kt @@ -11,8 +11,10 @@ import org.junit.Assert.* import org.junit.Test class JavadocTest { + val defaultModelConfig = ModelConfig(analysisPlatform = Platform.jvm) + @Test fun testTypes() { - verifyJavadoc("testdata/javadoc/types.kt", ModelConfig(withJdk = true)) { doc -> + verifyJavadoc("testdata/javadoc/types.kt", ModelConfig(analysisPlatform = Platform.jvm, withJdk = true)) { doc -> val classDoc = doc.classNamed("foo.TypesKt")!! val method = classDoc.methods().find { it.name() == "foo" }!! @@ -28,7 +30,7 @@ class JavadocTest { } @Test fun testObject() { - verifyJavadoc("testdata/javadoc/obj.kt") { doc -> + verifyJavadoc("testdata/javadoc/obj.kt", defaultModelConfig) { doc -> val classDoc = doc.classNamed("foo.O") assertNotNull(classDoc) @@ -41,7 +43,10 @@ class JavadocTest { } @Test fun testException() { - verifyJavadoc("testdata/javadoc/exception.kt", ModelConfig(withKotlinRuntime = true)) { doc -> + verifyJavadoc( + "testdata/javadoc/exception.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> val classDoc = doc.classNamed("foo.MyException")!! val member = classDoc.methods().find { it.name() == "foo" } assertEquals(classDoc, member!!.containingClass()) @@ -49,7 +54,10 @@ class JavadocTest { } @Test fun testByteArray() { - verifyJavadoc("testdata/javadoc/bytearr.kt", ModelConfig(withKotlinRuntime = true)) { doc -> + verifyJavadoc( + "testdata/javadoc/bytearr.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> val classDoc = doc.classNamed("foo.ByteArray")!! assertNotNull(classDoc.asClassDoc()) @@ -59,7 +67,10 @@ class JavadocTest { } @Test fun testStringArray() { - verifyJavadoc("testdata/javadoc/stringarr.kt", ModelConfig(withKotlinRuntime = true)) { doc -> + verifyJavadoc( + "testdata/javadoc/stringarr.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> val classDoc = doc.classNamed("foo.Foo")!! assertNotNull(classDoc.asClassDoc()) @@ -72,7 +83,10 @@ class JavadocTest { } @Test fun testJvmName() { - verifyJavadoc("testdata/javadoc/jvmname.kt", ModelConfig(withKotlinRuntime = true)) { doc -> + verifyJavadoc( + "testdata/javadoc/jvmname.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> val classDoc = doc.classNamed("foo.Apple")!! assertNotNull(classDoc.asClassDoc()) @@ -82,7 +96,10 @@ class JavadocTest { } @Test fun testLinkWithParam() { - verifyJavadoc("testdata/javadoc/paramlink.kt", ModelConfig(withKotlinRuntime = true)) { doc -> + verifyJavadoc( + "testdata/javadoc/paramlink.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> val classDoc = doc.classNamed("demo.Apple")!! assertNotNull(classDoc.asClassDoc()) val tags = classDoc.inlineTags().filterIsInstance() @@ -93,7 +110,10 @@ class JavadocTest { } @Test fun testInternalVisibility() { - verifyJavadoc("testdata/javadoc/internal.kt", ModelConfig(withKotlinRuntime = true, includeNonPublic = false)) { doc -> + verifyJavadoc( + "testdata/javadoc/internal.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true, includeNonPublic = false) + ) { doc -> val classDoc = doc.classNamed("foo.Person")!! val constructors = classDoc.constructors() assertEquals(1, constructors.size) @@ -102,7 +122,10 @@ class JavadocTest { } @Test fun testSuppress() { - verifyJavadoc("testdata/javadoc/suppress.kt", ModelConfig(withKotlinRuntime = true)) { doc -> + verifyJavadoc( + "testdata/javadoc/suppress.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> assertNull(doc.classNamed("Some")) assertNull(doc.classNamed("SomeAgain")) assertNull(doc.classNamed("Interface")) @@ -113,7 +136,10 @@ class JavadocTest { } @Test fun testTypeAliases() { - verifyJavadoc("testdata/javadoc/typealiases.kt", ModelConfig(withKotlinRuntime = true)) { doc -> + verifyJavadoc( + "testdata/javadoc/typealiases.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> assertNull(doc.classNamed("B")) assertNull(doc.classNamed("D")) @@ -128,7 +154,10 @@ class JavadocTest { } @Test fun testKDocKeywordsOnMethod() { - verifyJavadoc("testdata/javadoc/kdocKeywordsOnMethod.kt", ModelConfig(withKotlinRuntime = true)) { doc -> + verifyJavadoc( + "testdata/javadoc/kdocKeywordsOnMethod.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> val method = doc.classNamed("KdocKeywordsOnMethodKt")!!.methods()[0] assertEquals("@return [ContentText(text=value of a)]", method.tags("return").first().text()) assertEquals("@param a [ContentText(text=Some string)]", method.paramTags().first().text()) @@ -138,7 +167,10 @@ class JavadocTest { @Test fun testBlankLineInsideCodeBlock() { - verifyJavadoc("testdata/javadoc/blankLineInsideCodeBlock.kt", ModelConfig(withKotlinRuntime = true)) { doc -> + verifyJavadoc( + "testdata/javadoc/blankLineInsideCodeBlock.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> val method = doc.classNamed("BlankLineInsideCodeBlockKt")!!.methods()[0] val text = method.inlineTags().joinToString(separator = "", transform = Tag::text) assertEqualsIgnoringSeparators(""" @@ -155,7 +187,7 @@ class JavadocTest { @Test fun testCompanionMethodReference() { - verifyJavadoc("testdata/javadoc/companionMethodReference.kt") { doc -> + verifyJavadoc("testdata/javadoc/companionMethodReference.kt", defaultModelConfig) { doc -> val classDoc = doc.classNamed("foo.TestClass")!! val tag = classDoc.inlineTags().filterIsInstance().first() assertEquals("TestClass.Companion", tag.referencedClassName()) diff --git a/core/src/test/kotlin/model/BaseClassTest.kt b/core/src/test/kotlin/model/BaseClassTest.kt deleted file mode 100644 index d48ecb48..00000000 --- a/core/src/test/kotlin/model/BaseClassTest.kt +++ /dev/null @@ -1,269 +0,0 @@ -package org.jetbrains.dokka.tests - -import org.jetbrains.dokka.Content -import org.jetbrains.dokka.NodeKind -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.RefKind -import org.junit.Assert.assertEquals -import org.junit.Assert.assertTrue -import org.junit.Test - -abstract class BaseClassTest(val analysisPlatform: Platform) { - protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) - @Test fun emptyClass() { - checkSourceExistsAndVerifyModel("testdata/classes/emptyClass.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals(NodeKind.Class, kind) - assertEquals("Klass", name) - assertEquals(Content.Empty, content) - assertEquals("", members.single().name) - assertTrue(links.none()) - } - } - } - - @Test fun emptyObject() { - checkSourceExistsAndVerifyModel("testdata/classes/emptyObject.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals(NodeKind.Object, kind) - assertEquals("Obj", name) - assertEquals(Content.Empty, content) - assertTrue(members.none()) - assertTrue(links.none()) - } - } - } - - @Test fun classWithConstructor() { - checkSourceExistsAndVerifyModel("testdata/classes/classWithConstructor.kt", defaultModelConfig) { model -> - with (model.members.single().members.single()) { - assertEquals(NodeKind.Class, kind) - assertEquals("Klass", name) - assertEquals(Content.Empty, content) - assertTrue(links.none()) - - assertEquals(1, members.count()) - with(members.elementAt(0)) { - assertEquals("", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Constructor, kind) - assertEquals(3, details.count()) - assertEquals("public", details.elementAt(0).name) - with(details.elementAt(2)) { - assertEquals("name", name) - assertEquals(NodeKind.Parameter, kind) - assertEquals(Content.Empty, content) - assertEquals("String", detail(NodeKind.Type).name) - assertTrue(links.none()) - assertTrue(members.none()) - } - assertTrue(links.none()) - assertTrue(members.none()) - } - } - } - } - - @Test fun classWithFunction() { - checkSourceExistsAndVerifyModel("testdata/classes/classWithFunction.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals(NodeKind.Class, kind) - assertEquals("Klass", name) - assertEquals(Content.Empty, content) - assertTrue(links.none()) - - assertEquals(2, members.count()) - with(members.elementAt(0)) { - assertEquals("", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Constructor, kind) - assertEquals(2, details.count()) - assertEquals("public", details.elementAt(0).name) - assertTrue(links.none()) - assertTrue(members.none()) - } - with(members.elementAt(1)) { - assertEquals("fn", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Function, kind) - assertEquals("Unit", detail(NodeKind.Type).name) - assertTrue(links.none()) - assertTrue(members.none()) - } - } - } - } - - @Test fun classWithProperty() { - checkSourceExistsAndVerifyModel("testdata/classes/classWithProperty.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals(NodeKind.Class, kind) - assertEquals("Klass", name) - assertEquals(Content.Empty, content) - assertTrue(links.none()) - - assertEquals(2, members.count()) - with(members.elementAt(0)) { - assertEquals("", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Constructor, kind) - assertEquals(2, details.count()) - assertEquals("public", details.elementAt(0).name) - assertTrue(members.none()) - assertTrue(links.none()) - } - with(members.elementAt(1)) { - assertEquals("name", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Property, kind) - assertEquals("String", detail(NodeKind.Type).name) - assertTrue(members.none()) - assertTrue(links.none()) - } - } - } - } - - @Test fun classWithCompanionObject() { - checkSourceExistsAndVerifyModel("testdata/classes/classWithCompanionObject.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals(NodeKind.Class, kind) - assertEquals("Klass", name) - assertEquals(Content.Empty, content) - assertTrue(links.none()) - - assertEquals(3, members.count()) - with(members.elementAt(0)) { - assertEquals("", name) - assertEquals(Content.Empty, content) - } - with(members.elementAt(1)) { - assertEquals("x", name) - assertEquals(NodeKind.CompanionObjectProperty, kind) - assertTrue(members.none()) - assertTrue(links.none()) - } - with(members.elementAt(2)) { - assertEquals("foo", name) - assertEquals(NodeKind.CompanionObjectFunction, kind) - assertTrue(members.none()) - assertTrue(links.none()) - } - } - } - } - - @Test fun dataClass() { - verifyPackageMember("testdata/classes/dataClass.kt", defaultModelConfig) { cls -> - val modifiers = cls.details(NodeKind.Modifier).map { it.name } - assertTrue("data" in modifiers) - } - } - - @Test fun sealedClass() { - verifyPackageMember("testdata/classes/sealedClass.kt", defaultModelConfig) { cls -> - val modifiers = cls.details(NodeKind.Modifier).map { it.name } - assertEquals(1, modifiers.count { it == "sealed" }) - } - } - - @Test fun annotatedClassWithAnnotationParameters() { - checkSourceExistsAndVerifyModel( - "testdata/classes/annotatedClassWithAnnotationParameters.kt", - defaultModelConfig - ) { model -> - with(model.members.single().members.single()) { - with(deprecation!!) { - assertEquals("Deprecated", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Annotation, kind) - assertEquals(1, details.count()) - with(details[0]) { - assertEquals(NodeKind.Parameter, kind) - assertEquals(1, details.count()) - with(details[0]) { - assertEquals(NodeKind.Value, kind) - assertEquals("\"should no longer be used\"", name) - } - } - } - } - } - } - - @Test fun notOpenClass() { - checkSourceExistsAndVerifyModel("testdata/classes/notOpenClass.kt", defaultModelConfig) { model -> - with(model.members.single().members.first { it.name == "D"}.members.first { it.name == "f" }) { - val modifiers = details(NodeKind.Modifier) - assertEquals(2, modifiers.size) - assertEquals("final", modifiers[1].name) - - val overrideReferences = references(RefKind.Override) - assertEquals(1, overrideReferences.size) - } - } - } - - @Test fun indirectOverride() { - checkSourceExistsAndVerifyModel("testdata/classes/indirectOverride.kt", defaultModelConfig) { model -> - with(model.members.single().members.first { it.name == "E"}.members.first { it.name == "foo" }) { - val modifiers = details(NodeKind.Modifier) - assertEquals(2, modifiers.size) - assertEquals("final", modifiers[1].name) - - val overrideReferences = references(RefKind.Override) - assertEquals(1, overrideReferences.size) - } - } - } - - @Test fun innerClass() { - verifyPackageMember("testdata/classes/innerClass.kt", defaultModelConfig) { cls -> - val innerClass = cls.members.single { it.name == "D" } - val modifiers = innerClass.details(NodeKind.Modifier) - assertEquals(3, modifiers.size) - assertEquals("inner", modifiers[2].name) - } - } - - @Test fun companionObjectExtension() { - checkSourceExistsAndVerifyModel("testdata/classes/companionObjectExtension.kt", defaultModelConfig) { model -> - val pkg = model.members.single() - val cls = pkg.members.single { it.name == "Foo" } - val extensions = cls.extensions.filter { it.kind == NodeKind.CompanionObjectProperty } - assertEquals(1, extensions.size) - } - } - - @Test fun secondaryConstructor() { - verifyPackageMember("testdata/classes/secondaryConstructor.kt", defaultModelConfig) { cls -> - val constructors = cls.members(NodeKind.Constructor) - assertEquals(2, constructors.size) - with (constructors.first { it.details(NodeKind.Parameter).size == 1}) { - assertEquals("", name) - assertEquals("This is a secondary constructor.", summary.toTestString()) - } - } - } - - @Test fun sinceKotlin() { - checkSourceExistsAndVerifyModel("testdata/classes/sinceKotlin.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals(listOf("Kotlin 1.1"), platforms) - } - } - } - - @Test fun privateCompanionObject() { - checkSourceExistsAndVerifyModel( - "testdata/classes/privateCompanionObject.kt", - modelConfig = ModelConfig(analysisPlatform = analysisPlatform, includeNonPublic = false) - ) { model -> - with(model.members.single().members.single()) { - assertEquals(0, members(NodeKind.CompanionObjectFunction).size) - assertEquals(0, members(NodeKind.CompanionObjectProperty).size) - } - } - } - -} diff --git a/core/src/test/kotlin/model/BasePropertyTest.kt b/core/src/test/kotlin/model/BasePropertyTest.kt deleted file mode 100644 index c88fe702..00000000 --- a/core/src/test/kotlin/model/BasePropertyTest.kt +++ /dev/null @@ -1,101 +0,0 @@ -package org.jetbrains.dokka.tests - -import org.jetbrains.dokka.* -import org.junit.Assert.assertEquals -import org.junit.Assert.assertTrue -import org.junit.Test - -abstract class BasePropertyTest(val analysisPlatform: Platform) { - - protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) - @Test fun valueProperty() { - checkSourceExistsAndVerifyModel("testdata/properties/valueProperty.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals("property", name) - assertEquals(NodeKind.Property, kind) - assertEquals(Content.Empty, content) - assertEquals("String", detail(NodeKind.Type).name) - assertTrue(members.none()) - assertTrue(links.none()) - } - } - } - - @Test fun variableProperty() { - checkSourceExistsAndVerifyModel("testdata/properties/variableProperty.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals("property", name) - assertEquals(NodeKind.Property, kind) - assertEquals(Content.Empty, content) - assertEquals("String", detail(NodeKind.Type).name) - assertTrue(members.none()) - assertTrue(links.none()) - } - } - } - - @Test fun valuePropertyWithGetter() { - checkSourceExistsAndVerifyModel("testdata/properties/valuePropertyWithGetter.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals("property", name) - assertEquals(NodeKind.Property, kind) - assertEquals(Content.Empty, content) - assertEquals("String", detail(NodeKind.Type).name) - assertTrue(links.none()) - assertTrue(members.none()) - } - } - } - - @Test fun variablePropertyWithAccessors() { - checkSourceExistsAndVerifyModel("testdata/properties/variablePropertyWithAccessors.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals("property", name) - assertEquals(NodeKind.Property, kind) - assertEquals(Content.Empty, content) - assertEquals("String", detail(NodeKind.Type).name) - val modifiers = details(NodeKind.Modifier).map { it.name } - assertTrue("final" in modifiers) - assertTrue("public" in modifiers) - assertTrue("var" in modifiers) - assertTrue(links.none()) - assertTrue(members.none()) - } - } - } - - @Test fun propertyWithReceiver() { - checkSourceExistsAndVerifyModel( - "testdata/properties/propertyWithReceiver.kt", - defaultModelConfig - ) { model -> - with(model.members.single().members.single()) { - assertEquals("kotlin.String", name) - assertEquals(NodeKind.ExternalClass, kind) - with(members.single()) { - assertEquals("foobar", name) - assertEquals(NodeKind.Property, kind) - } - } - } - } - - @Test fun propertyOverride() { - checkSourceExistsAndVerifyModel("testdata/properties/propertyOverride.kt", defaultModelConfig) { model -> - with(model.members.single().members.single { it.name == "Bar" }.members.single { it.name == "xyzzy"}) { - assertEquals("xyzzy", name) - val override = references(RefKind.Override).single().to - assertEquals("xyzzy", override.name) - assertEquals("Foo", override.owner!!.name) - } - } - } - - @Test fun sinceKotlin() { - checkSourceExistsAndVerifyModel("testdata/properties/sinceKotlin.kt", defaultModelConfig) { model -> - with(model.members.single().members.single()) { - assertEquals(listOf("Kotlin 1.1"), platforms) - } - } - } -} diff --git a/core/src/test/kotlin/model/ClassTest.kt b/core/src/test/kotlin/model/ClassTest.kt new file mode 100644 index 00000000..b8e58a62 --- /dev/null +++ b/core/src/test/kotlin/model/ClassTest.kt @@ -0,0 +1,318 @@ +package org.jetbrains.dokka.tests + +import org.jetbrains.dokka.Content +import org.jetbrains.dokka.NodeKind +import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.RefKind +import org.junit.Assert +import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue +import org.junit.Test + +abstract class BaseClassTest(val analysisPlatform: Platform) { + protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) + @Test fun emptyClass() { + checkSourceExistsAndVerifyModel("testdata/classes/emptyClass.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(NodeKind.Class, kind) + assertEquals("Klass", name) + assertEquals(Content.Empty, content) + assertEquals("", members.single().name) + assertTrue(links.none()) + } + } + } + + @Test fun emptyObject() { + checkSourceExistsAndVerifyModel("testdata/classes/emptyObject.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(NodeKind.Object, kind) + assertEquals("Obj", name) + assertEquals(Content.Empty, content) + assertTrue(members.none()) + assertTrue(links.none()) + } + } + } + + @Test fun classWithConstructor() { + checkSourceExistsAndVerifyModel("testdata/classes/classWithConstructor.kt", defaultModelConfig) { model -> + with (model.members.single().members.single()) { + assertEquals(NodeKind.Class, kind) + assertEquals("Klass", name) + assertEquals(Content.Empty, content) + assertTrue(links.none()) + + assertEquals(1, members.count()) + with(members.elementAt(0)) { + assertEquals("", name) + assertEquals(Content.Empty, content) + assertEquals(NodeKind.Constructor, kind) + assertEquals(3, details.count()) + assertEquals("public", details.elementAt(0).name) + with(details.elementAt(2)) { + assertEquals("name", name) + assertEquals(NodeKind.Parameter, kind) + assertEquals(Content.Empty, content) + assertEquals("String", detail(NodeKind.Type).name) + assertTrue(links.none()) + assertTrue(members.none()) + } + assertTrue(links.none()) + assertTrue(members.none()) + } + } + } + } + + @Test fun classWithFunction() { + checkSourceExistsAndVerifyModel("testdata/classes/classWithFunction.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(NodeKind.Class, kind) + assertEquals("Klass", name) + assertEquals(Content.Empty, content) + assertTrue(links.none()) + + assertEquals(2, members.count()) + with(members.elementAt(0)) { + assertEquals("", name) + assertEquals(Content.Empty, content) + assertEquals(NodeKind.Constructor, kind) + assertEquals(2, details.count()) + assertEquals("public", details.elementAt(0).name) + assertTrue(links.none()) + assertTrue(members.none()) + } + with(members.elementAt(1)) { + assertEquals("fn", name) + assertEquals(Content.Empty, content) + assertEquals(NodeKind.Function, kind) + assertEquals("Unit", detail(NodeKind.Type).name) + assertTrue(links.none()) + assertTrue(members.none()) + } + } + } + } + + @Test fun classWithProperty() { + checkSourceExistsAndVerifyModel("testdata/classes/classWithProperty.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(NodeKind.Class, kind) + assertEquals("Klass", name) + assertEquals(Content.Empty, content) + assertTrue(links.none()) + + assertEquals(2, members.count()) + with(members.elementAt(0)) { + assertEquals("", name) + assertEquals(Content.Empty, content) + assertEquals(NodeKind.Constructor, kind) + assertEquals(2, details.count()) + assertEquals("public", details.elementAt(0).name) + assertTrue(members.none()) + assertTrue(links.none()) + } + with(members.elementAt(1)) { + assertEquals("name", name) + assertEquals(Content.Empty, content) + assertEquals(NodeKind.Property, kind) + assertEquals("String", detail(NodeKind.Type).name) + assertTrue(members.none()) + assertTrue(links.none()) + } + } + } + } + + @Test fun classWithCompanionObject() { + checkSourceExistsAndVerifyModel("testdata/classes/classWithCompanionObject.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(NodeKind.Class, kind) + assertEquals("Klass", name) + assertEquals(Content.Empty, content) + assertTrue(links.none()) + + assertEquals(3, members.count()) + with(members.elementAt(0)) { + assertEquals("", name) + assertEquals(Content.Empty, content) + } + with(members.elementAt(1)) { + assertEquals("x", name) + assertEquals(NodeKind.CompanionObjectProperty, kind) + assertTrue(members.none()) + assertTrue(links.none()) + } + with(members.elementAt(2)) { + assertEquals("foo", name) + assertEquals(NodeKind.CompanionObjectFunction, kind) + assertTrue(members.none()) + assertTrue(links.none()) + } + } + } + } + + @Test fun dataClass() { + verifyPackageMember("testdata/classes/dataClass.kt", defaultModelConfig) { cls -> + val modifiers = cls.details(NodeKind.Modifier).map { it.name } + assertTrue("data" in modifiers) + } + } + + @Test fun sealedClass() { + verifyPackageMember("testdata/classes/sealedClass.kt", defaultModelConfig) { cls -> + val modifiers = cls.details(NodeKind.Modifier).map { it.name } + assertEquals(1, modifiers.count { it == "sealed" }) + } + } + + @Test fun annotatedClassWithAnnotationParameters() { + checkSourceExistsAndVerifyModel( + "testdata/classes/annotatedClassWithAnnotationParameters.kt", + defaultModelConfig + ) { model -> + with(model.members.single().members.single()) { + with(deprecation!!) { + assertEquals("Deprecated", name) + assertEquals(Content.Empty, content) + assertEquals(NodeKind.Annotation, kind) + assertEquals(1, details.count()) + with(details[0]) { + assertEquals(NodeKind.Parameter, kind) + assertEquals(1, details.count()) + with(details[0]) { + assertEquals(NodeKind.Value, kind) + assertEquals("\"should no longer be used\"", name) + } + } + } + } + } + } + + @Test fun notOpenClass() { + checkSourceExistsAndVerifyModel("testdata/classes/notOpenClass.kt", defaultModelConfig) { model -> + with(model.members.single().members.first { it.name == "D"}.members.first { it.name == "f" }) { + val modifiers = details(NodeKind.Modifier) + assertEquals(2, modifiers.size) + assertEquals("final", modifiers[1].name) + + val overrideReferences = references(RefKind.Override) + assertEquals(1, overrideReferences.size) + } + } + } + + @Test fun indirectOverride() { + checkSourceExistsAndVerifyModel("testdata/classes/indirectOverride.kt", defaultModelConfig) { model -> + with(model.members.single().members.first { it.name == "E"}.members.first { it.name == "foo" }) { + val modifiers = details(NodeKind.Modifier) + assertEquals(2, modifiers.size) + assertEquals("final", modifiers[1].name) + + val overrideReferences = references(RefKind.Override) + assertEquals(1, overrideReferences.size) + } + } + } + + @Test fun innerClass() { + verifyPackageMember("testdata/classes/innerClass.kt", defaultModelConfig) { cls -> + val innerClass = cls.members.single { it.name == "D" } + val modifiers = innerClass.details(NodeKind.Modifier) + assertEquals(3, modifiers.size) + assertEquals("inner", modifiers[2].name) + } + } + + @Test fun companionObjectExtension() { + checkSourceExistsAndVerifyModel("testdata/classes/companionObjectExtension.kt", defaultModelConfig) { model -> + val pkg = model.members.single() + val cls = pkg.members.single { it.name == "Foo" } + val extensions = cls.extensions.filter { it.kind == NodeKind.CompanionObjectProperty } + assertEquals(1, extensions.size) + } + } + + @Test fun secondaryConstructor() { + verifyPackageMember("testdata/classes/secondaryConstructor.kt", defaultModelConfig) { cls -> + val constructors = cls.members(NodeKind.Constructor) + assertEquals(2, constructors.size) + with (constructors.first { it.details(NodeKind.Parameter).size == 1}) { + assertEquals("", name) + assertEquals("This is a secondary constructor.", summary.toTestString()) + } + } + } + + @Test fun sinceKotlin() { + checkSourceExistsAndVerifyModel("testdata/classes/sinceKotlin.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(listOf("Kotlin 1.1"), platforms) + } + } + } + + @Test fun privateCompanionObject() { + checkSourceExistsAndVerifyModel( + "testdata/classes/privateCompanionObject.kt", + modelConfig = ModelConfig(analysisPlatform = analysisPlatform, includeNonPublic = false) + ) { model -> + with(model.members.single().members.single()) { + assertEquals(0, members(NodeKind.CompanionObjectFunction).size) + assertEquals(0, members(NodeKind.CompanionObjectProperty).size) + } + } + } + +} + +class JSClassTest: BaseClassTest(Platform.js) {} + +class JVMClassTest: BaseClassTest(Platform.jvm) { + @Test + fun annotatedClass() { + verifyPackageMember("testdata/classes/annotatedClass.kt", ModelConfig( + analysisPlatform = analysisPlatform, + withKotlinRuntime = true + ) + ) { cls -> + Assert.assertEquals(1, cls.annotations.count()) + with(cls.annotations[0]) { + Assert.assertEquals("Strictfp", name) + Assert.assertEquals(Content.Empty, content) + Assert.assertEquals(NodeKind.Annotation, kind) + } + } + } + + + @Test fun javaAnnotationClass() { + checkSourceExistsAndVerifyModel( + "testdata/classes/javaAnnotationClass.kt", + modelConfig = ModelConfig(analysisPlatform = analysisPlatform, withJdk = true) + ) { model -> + with(model.members.single().members.single()) { + Assert.assertEquals(1, annotations.count()) + with(annotations[0]) { + Assert.assertEquals("Retention", name) + Assert.assertEquals(Content.Empty, content) + Assert.assertEquals(NodeKind.Annotation, kind) + with(details[0]) { + Assert.assertEquals(NodeKind.Parameter, kind) + Assert.assertEquals(1, details.count()) + with(details[0]) { + Assert.assertEquals(NodeKind.Value, kind) + Assert.assertEquals("RetentionPolicy.SOURCE", name) + } + } + } + } + } + } + +} + +class CommonClassTest: BaseClassTest(Platform.common) {} \ No newline at end of file diff --git a/core/src/test/kotlin/model/CommentTest.kt b/core/src/test/kotlin/model/CommentTest.kt index a97c55eb..08aa3572 100644 --- a/core/src/test/kotlin/model/CommentTest.kt +++ b/core/src/test/kotlin/model/CommentTest.kt @@ -4,10 +4,10 @@ import org.junit.Test import org.junit.Assert.* import org.jetbrains.dokka.* -public class CommentTest { - +abstract class BaseCommentTest(val analysisPlatform: Platform) { + val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) @Test fun codeBlockComment() { - checkSourceExistsAndVerifyModel("testdata/comments/codeBlockComment.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/codeBlockComment.kt", defaultModelConfig) { model -> with(model.members.single().members.first()) { assertEqualsIgnoringSeparators("""[code lang=brainfuck] | @@ -30,7 +30,7 @@ public class CommentTest { } @Test fun emptyDoc() { - checkSourceExistsAndVerifyModel("testdata/comments/emptyDoc.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/emptyDoc.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals(Content.Empty, content) } @@ -38,7 +38,7 @@ public class CommentTest { } @Test fun emptyDocButComment() { - checkSourceExistsAndVerifyModel("testdata/comments/emptyDocButComment.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/emptyDocButComment.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals(Content.Empty, content) } @@ -46,7 +46,7 @@ public class CommentTest { } @Test fun multilineDoc() { - checkSourceExistsAndVerifyModel("testdata/comments/multilineDoc.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/multilineDoc.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("doc1", content.summary.toTestString()) assertEquals("doc2\ndoc3", content.description.toTestString()) @@ -55,7 +55,7 @@ public class CommentTest { } @Test fun multilineDocWithComment() { - checkSourceExistsAndVerifyModel("testdata/comments/multilineDocWithComment.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/multilineDocWithComment.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("doc1", content.summary.toTestString()) assertEquals("doc2\ndoc3", content.description.toTestString()) @@ -64,7 +64,7 @@ public class CommentTest { } @Test fun oneLineDoc() { - checkSourceExistsAndVerifyModel("testdata/comments/oneLineDoc.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/oneLineDoc.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("doc", content.summary.toTestString()) } @@ -72,7 +72,7 @@ public class CommentTest { } @Test fun oneLineDocWithComment() { - checkSourceExistsAndVerifyModel("testdata/comments/oneLineDocWithComment.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/oneLineDocWithComment.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("doc", content.summary.toTestString()) } @@ -80,7 +80,7 @@ public class CommentTest { } @Test fun oneLineDocWithEmptyLine() { - checkSourceExistsAndVerifyModel("testdata/comments/oneLineDocWithEmptyLine.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/oneLineDocWithEmptyLine.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("doc", content.summary.toTestString()) } @@ -88,7 +88,7 @@ public class CommentTest { } @Test fun emptySection() { - checkSourceExistsAndVerifyModel("testdata/comments/emptySection.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/emptySection.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("Summary", content.summary.toTestString()) assertEquals(1, content.sections.count()) @@ -101,7 +101,7 @@ public class CommentTest { } @Test fun quotes() { - checkSourceExistsAndVerifyModel("testdata/comments/quotes.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/quotes.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("it's \"useful\"", content.summary.toTestString()) } @@ -109,7 +109,7 @@ public class CommentTest { } @Test fun section1() { - checkSourceExistsAndVerifyModel("testdata/comments/section1.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/section1.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("Summary", content.summary.toTestString()) assertEquals(1, content.sections.count()) @@ -122,7 +122,7 @@ public class CommentTest { } @Test fun section2() { - checkSourceExistsAndVerifyModel("testdata/comments/section2.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/section2.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("Summary", content.summary.toTestString()) assertEquals(2, content.sections.count()) @@ -139,7 +139,7 @@ public class CommentTest { } @Test fun multilineSection() { - checkSourceExistsAndVerifyModel("testdata/comments/multilineSection.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/multilineSection.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("Summary", content.summary.toTestString()) assertEquals(1, content.sections.count()) @@ -153,7 +153,7 @@ line two""", toTestString()) } @Test fun directive() { - checkSourceExistsAndVerifyModel("testdata/comments/directive.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/comments/directive.kt", defaultModelConfig) { model -> with(model.members.single().members.first()) { assertEquals("Summary", content.summary.toTestString()) with (content.description) { @@ -184,3 +184,7 @@ line two""", toTestString()) } } } + +class JSCommentTest: BaseCommentTest(Platform.js) +class JVMCommentTest: BaseCommentTest(Platform.jvm) +class CommonCommentTest: BaseCommentTest(Platform.common) \ No newline at end of file diff --git a/core/src/test/kotlin/model/FunctionTest.kt b/core/src/test/kotlin/model/FunctionTest.kt index 2704bf65..47685df2 100644 --- a/core/src/test/kotlin/model/FunctionTest.kt +++ b/core/src/test/kotlin/model/FunctionTest.kt @@ -4,6 +4,7 @@ import org.jetbrains.dokka.Content import org.jetbrains.dokka.NodeKind import org.jetbrains.dokka.Platform import org.jetbrains.kotlin.analyzer.PlatformAnalysisParameters +import org.junit.Assert import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue import org.junit.Test @@ -229,3 +230,25 @@ Documentation""", content.description.toTestString()) } } } + +class JSFunctionTest: BaseFunctionTest(Platform.js) + +class JVMFunctionTest: BaseFunctionTest(Platform.jvm) { + @Test + fun annotatedFunction() { + verifyPackageMember("testdata/functions/annotatedFunction.kt", ModelConfig( + analysisPlatform = Platform.jvm, + withKotlinRuntime = true + )) { func -> + Assert.assertEquals(1, func.annotations.count()) + with(func.annotations[0]) { + Assert.assertEquals("Strictfp", name) + Assert.assertEquals(Content.Empty, content) + Assert.assertEquals(NodeKind.Annotation, kind) + } + } + } + +} + +class CommonFunctionTest: BaseFunctionTest(Platform.common) \ No newline at end of file diff --git a/core/src/test/kotlin/model/JSClassTest.kt b/core/src/test/kotlin/model/JSClassTest.kt deleted file mode 100644 index e39b95cc..00000000 --- a/core/src/test/kotlin/model/JSClassTest.kt +++ /dev/null @@ -1,6 +0,0 @@ -package org.jetbrains.dokka.tests.model - -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.tests.BaseClassTest - -class JSClassTest: BaseClassTest(Platform.js) {} \ No newline at end of file diff --git a/core/src/test/kotlin/model/JSFunctionTest.kt b/core/src/test/kotlin/model/JSFunctionTest.kt deleted file mode 100644 index f6b987a9..00000000 --- a/core/src/test/kotlin/model/JSFunctionTest.kt +++ /dev/null @@ -1,8 +0,0 @@ -package org.jetbrains.dokka.tests.model - -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.tests.BaseFunctionTest - -class JSFunctionTest: BaseFunctionTest(Platform.js) { - -} \ No newline at end of file diff --git a/core/src/test/kotlin/model/JSPropertyTest.kt b/core/src/test/kotlin/model/JSPropertyTest.kt deleted file mode 100644 index 0193d899..00000000 --- a/core/src/test/kotlin/model/JSPropertyTest.kt +++ /dev/null @@ -1,8 +0,0 @@ -package org.jetbrains.dokka.tests.model - -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.tests.BasePropertyTest - -class JSPropertyTest: BasePropertyTest(Platform.js) { - -} \ No newline at end of file diff --git a/core/src/test/kotlin/model/JVMClassTest.kt b/core/src/test/kotlin/model/JVMClassTest.kt deleted file mode 100644 index 22e23722..00000000 --- a/core/src/test/kotlin/model/JVMClassTest.kt +++ /dev/null @@ -1,55 +0,0 @@ -package org.jetbrains.dokka.tests.model - -import org.jetbrains.dokka.Content -import org.jetbrains.dokka.NodeKind -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.tests.BaseClassTest -import org.jetbrains.dokka.tests.ModelConfig -import org.jetbrains.dokka.tests.checkSourceExistsAndVerifyModel -import org.jetbrains.dokka.tests.verifyPackageMember -import org.junit.Assert -import org.junit.Test - -class JVMClassTest: BaseClassTest(Platform.jvm) { - @Test - fun annotatedClass() { - verifyPackageMember("testdata/classes/annotatedClass.kt", ModelConfig( - analysisPlatform = analysisPlatform, - withKotlinRuntime = true - ) - ) { cls -> - Assert.assertEquals(1, cls.annotations.count()) - with(cls.annotations[0]) { - Assert.assertEquals("Strictfp", name) - Assert.assertEquals(Content.Empty, content) - Assert.assertEquals(NodeKind.Annotation, kind) - } - } - } - - - @Test fun javaAnnotationClass() { - checkSourceExistsAndVerifyModel( - "testdata/classes/javaAnnotationClass.kt", - modelConfig = ModelConfig(analysisPlatform = analysisPlatform, withJdk = true) - ) { model -> - with(model.members.single().members.single()) { - Assert.assertEquals(1, annotations.count()) - with(annotations[0]) { - Assert.assertEquals("Retention", name) - Assert.assertEquals(Content.Empty, content) - Assert.assertEquals(NodeKind.Annotation, kind) - with(details[0]) { - Assert.assertEquals(NodeKind.Parameter, kind) - Assert.assertEquals(1, details.count()) - with(details[0]) { - Assert.assertEquals(NodeKind.Value, kind) - Assert.assertEquals("RetentionPolicy.SOURCE", name) - } - } - } - } - } - } - -} \ No newline at end of file diff --git a/core/src/test/kotlin/model/JVMFunctionTest.kt b/core/src/test/kotlin/model/JVMFunctionTest.kt deleted file mode 100644 index a2fb0d2a..00000000 --- a/core/src/test/kotlin/model/JVMFunctionTest.kt +++ /dev/null @@ -1,29 +0,0 @@ -package org.jetbrains.dokka.tests.model - -import com.sun.tools.javac.util.BaseFileManager -import org.jetbrains.dokka.Content -import org.jetbrains.dokka.NodeKind -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.tests.BaseFunctionTest -import org.jetbrains.dokka.tests.ModelConfig -import org.jetbrains.dokka.tests.verifyPackageMember -import org.junit.Assert -import org.junit.Test - -class JVMFunctionTest: BaseFunctionTest(Platform.jvm) { - @Test - fun annotatedFunction() { - verifyPackageMember("testdata/functions/annotatedFunction.kt", ModelConfig( - analysisPlatform = Platform.jvm, - withKotlinRuntime = true - )) { func -> - Assert.assertEquals(1, func.annotations.count()) - with(func.annotations[0]) { - Assert.assertEquals("Strictfp", name) - Assert.assertEquals(Content.Empty, content) - Assert.assertEquals(NodeKind.Annotation, kind) - } - } - } - -} \ No newline at end of file diff --git a/core/src/test/kotlin/model/JVMPropertyTest.kt b/core/src/test/kotlin/model/JVMPropertyTest.kt deleted file mode 100644 index 182dedbe..00000000 --- a/core/src/test/kotlin/model/JVMPropertyTest.kt +++ /dev/null @@ -1,33 +0,0 @@ -package org.jetbrains.dokka.tests.model - -import org.jetbrains.dokka.Content -import org.jetbrains.dokka.NodeKind -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.tests.BasePropertyTest -import org.jetbrains.dokka.tests.ModelConfig -import org.jetbrains.dokka.tests.checkSourceExistsAndVerifyModel -import org.junit.Assert -import org.junit.Test - -class JVMPropertyTest : BasePropertyTest(Platform.jvm) { - @Test - fun annotatedProperty() { - checkSourceExistsAndVerifyModel( - "testdata/properties/annotatedProperty.kt", - modelConfig = ModelConfig( - analysisPlatform = analysisPlatform, - withKotlinRuntime = true - ) - ) { model -> - with(model.members.single().members.single()) { - Assert.assertEquals(1, annotations.count()) - with(annotations[0]) { - Assert.assertEquals("Volatile", name) - Assert.assertEquals(Content.Empty, content) - Assert.assertEquals(NodeKind.Annotation, kind) - } - } - } - } - -} \ No newline at end of file diff --git a/core/src/test/kotlin/model/KotlinAsJavaTest.kt b/core/src/test/kotlin/model/KotlinAsJavaTest.kt index 1d95556f..f6f0aa20 100644 --- a/core/src/test/kotlin/model/KotlinAsJavaTest.kt +++ b/core/src/test/kotlin/model/KotlinAsJavaTest.kt @@ -7,8 +7,6 @@ import org.junit.Test import org.junit.Assert.assertEquals class KotlinAsJavaTest { - private val defaultModelConfig = ModelConfig (analysisPlatform = Platform.jvm) - @Test fun function() { verifyModelAsJava("testdata/functions/function.kt") { model -> val pkg = model.members.single() @@ -33,14 +31,13 @@ class KotlinAsJavaTest { } fun verifyModelAsJava(source: String, - withJdk: Boolean = false, - withKotlinRuntime: Boolean = false, + modelConfig: ModelConfig = ModelConfig(), verifier: (DocumentationModule) -> Unit) { checkSourceExistsAndVerifyModel( source, modelConfig = ModelConfig( - withJdk = withJdk, - withKotlinRuntime = withKotlinRuntime, + withJdk = modelConfig.withJdk, + withKotlinRuntime = modelConfig.withKotlinRuntime, format = "html-as-java", analysisPlatform = Platform.jvm), verifier = verifier diff --git a/core/src/test/kotlin/model/LinkTest.kt b/core/src/test/kotlin/model/LinkTest.kt index d7283bae..9b2f9f0d 100644 --- a/core/src/test/kotlin/model/LinkTest.kt +++ b/core/src/test/kotlin/model/LinkTest.kt @@ -3,12 +3,14 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.ContentBlock import org.jetbrains.dokka.ContentNodeLazyLink import org.jetbrains.dokka.NodeKind +import org.jetbrains.dokka.Platform import org.junit.Assert.assertEquals import org.junit.Test -class LinkTest { +abstract class BaseLinkTest(val analysisPlatform: Platform) { + private val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) @Test fun linkToSelf() { - checkSourceExistsAndVerifyModel("testdata/links/linkToSelf.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/links/linkToSelf.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("Foo", name) assertEquals(NodeKind.Class, kind) @@ -18,7 +20,7 @@ class LinkTest { } @Test fun linkToMember() { - checkSourceExistsAndVerifyModel("testdata/links/linkToMember.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/links/linkToMember.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("Foo", name) assertEquals(NodeKind.Class, kind) @@ -28,7 +30,7 @@ class LinkTest { } @Test fun linkToConstantWithUnderscores() { - checkSourceExistsAndVerifyModel("testdata/links/linkToConstantWithUnderscores.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/links/linkToConstantWithUnderscores.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("Foo", name) assertEquals(NodeKind.Class, kind) @@ -38,7 +40,7 @@ class LinkTest { } @Test fun linkToQualifiedMember() { - checkSourceExistsAndVerifyModel("testdata/links/linkToQualifiedMember.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/links/linkToQualifiedMember.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("Foo", name) assertEquals(NodeKind.Class, kind) @@ -48,7 +50,7 @@ class LinkTest { } @Test fun linkToParam() { - checkSourceExistsAndVerifyModel("testdata/links/linkToParam.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/links/linkToParam.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("Foo", name) assertEquals(NodeKind.Function, kind) @@ -58,7 +60,7 @@ class LinkTest { } @Test fun linkToPackage() { - checkSourceExistsAndVerifyModel("testdata/links/linkToPackage.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/links/linkToPackage.kt", defaultModelConfig) { model -> val packageNode = model.members.single() with(packageNode) { assertEquals(this.name, "test.magic") @@ -72,4 +74,8 @@ class LinkTest { } } -} \ No newline at end of file +} + +class JSLinkTest: BaseLinkTest(Platform.js) +class JVMLinkTest: BaseLinkTest(Platform.jvm) +class CommonLinkTest: BaseLinkTest(Platform.common) \ No newline at end of file diff --git a/core/src/test/kotlin/model/PackageTest.kt b/core/src/test/kotlin/model/PackageTest.kt index bc8a0e0d..80a2fd56 100644 --- a/core/src/test/kotlin/model/PackageTest.kt +++ b/core/src/test/kotlin/model/PackageTest.kt @@ -1,15 +1,14 @@ package org.jetbrains.dokka.tests -import org.jetbrains.dokka.Content -import org.jetbrains.dokka.NodeKind -import org.jetbrains.dokka.PackageOptionsImpl +import org.jetbrains.dokka.* import org.jetbrains.kotlin.config.KotlinSourceRoot import org.junit.Assert.* import org.junit.Test -public class PackageTest { +abstract class BasePackageTest(val analysisPlatform: Platform) { + val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) @Test fun rootPackage() { - checkSourceExistsAndVerifyModel("testdata/packages/rootPackage.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/packages/rootPackage.kt", defaultModelConfig) { model -> with(model.members.single()) { assertEquals(NodeKind.Package, kind) assertEquals("", name) @@ -22,7 +21,7 @@ public class PackageTest { } @Test fun simpleNamePackage() { - checkSourceExistsAndVerifyModel("testdata/packages/simpleNamePackage.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/packages/simpleNamePackage.kt", defaultModelConfig) { model -> with(model.members.single()) { assertEquals(NodeKind.Package, kind) assertEquals("simple", name) @@ -35,7 +34,7 @@ public class PackageTest { } @Test fun dottedNamePackage() { - checkSourceExistsAndVerifyModel("testdata/packages/dottedNamePackage.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/packages/dottedNamePackage.kt", defaultModelConfig) { model -> with(model.members.single()) { assertEquals(NodeKind.Package, kind) assertEquals("dot.name", name) @@ -53,7 +52,8 @@ public class PackageTest { roots = arrayOf( KotlinSourceRoot("testdata/packages/dottedNamePackage.kt"), KotlinSourceRoot("testdata/packages/simpleNamePackage.kt") - ) + ), + analysisPlatform = analysisPlatform ) ) { model -> assertEquals(2, model.members.count()) @@ -81,7 +81,8 @@ public class PackageTest { roots = arrayOf( KotlinSourceRoot("testdata/packages/simpleNamePackage.kt"), KotlinSourceRoot("testdata/packages/simpleNamePackage2.kt") - ) + ), + analysisPlatform = analysisPlatform ) ) { model -> assertEquals(1, model.members.count()) @@ -98,7 +99,10 @@ public class PackageTest { @Test fun classAtPackageLevel() { verifyModel( - ModelConfig(roots = arrayOf(KotlinSourceRoot("testdata/packages/classInPackage.kt"))) + ModelConfig( + roots = arrayOf(KotlinSourceRoot("testdata/packages/classInPackage.kt")), + analysisPlatform = analysisPlatform + ) ) { model -> assertEquals(1, model.members.count()) with(model.members.elementAt(0)) { @@ -118,7 +122,8 @@ public class PackageTest { roots = arrayOf(KotlinSourceRoot("testdata/packages/classInPackage.kt")), perPackageOptions = listOf( PackageOptionsImpl(prefix = "simple.name", suppress = true) - ) + ), + analysisPlatform = analysisPlatform ) ) { model -> assertEquals(1, model.members.count()) @@ -133,3 +138,7 @@ public class PackageTest { } } } + +class JSPackageTest : BasePackageTest(Platform.js) +class JVMPackageTest : BasePackageTest(Platform.jvm) +class CommonPackageTest : BasePackageTest(Platform.common) \ No newline at end of file diff --git a/core/src/test/kotlin/model/PropertyTest.kt b/core/src/test/kotlin/model/PropertyTest.kt new file mode 100644 index 00000000..a41ab5a3 --- /dev/null +++ b/core/src/test/kotlin/model/PropertyTest.kt @@ -0,0 +1,129 @@ +package org.jetbrains.dokka.tests + +import org.jetbrains.dokka.* +import org.junit.Assert +import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue +import org.junit.Test + +abstract class BasePropertyTest(val analysisPlatform: Platform) { + + protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) + @Test fun valueProperty() { + checkSourceExistsAndVerifyModel("testdata/properties/valueProperty.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals("property", name) + assertEquals(NodeKind.Property, kind) + assertEquals(Content.Empty, content) + assertEquals("String", detail(NodeKind.Type).name) + assertTrue(members.none()) + assertTrue(links.none()) + } + } + } + + @Test fun variableProperty() { + checkSourceExistsAndVerifyModel("testdata/properties/variableProperty.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals("property", name) + assertEquals(NodeKind.Property, kind) + assertEquals(Content.Empty, content) + assertEquals("String", detail(NodeKind.Type).name) + assertTrue(members.none()) + assertTrue(links.none()) + } + } + } + + @Test fun valuePropertyWithGetter() { + checkSourceExistsAndVerifyModel("testdata/properties/valuePropertyWithGetter.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals("property", name) + assertEquals(NodeKind.Property, kind) + assertEquals(Content.Empty, content) + assertEquals("String", detail(NodeKind.Type).name) + assertTrue(links.none()) + assertTrue(members.none()) + } + } + } + + @Test fun variablePropertyWithAccessors() { + checkSourceExistsAndVerifyModel("testdata/properties/variablePropertyWithAccessors.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals("property", name) + assertEquals(NodeKind.Property, kind) + assertEquals(Content.Empty, content) + assertEquals("String", detail(NodeKind.Type).name) + val modifiers = details(NodeKind.Modifier).map { it.name } + assertTrue("final" in modifiers) + assertTrue("public" in modifiers) + assertTrue("var" in modifiers) + assertTrue(links.none()) + assertTrue(members.none()) + } + } + } + + @Test fun propertyWithReceiver() { + checkSourceExistsAndVerifyModel( + "testdata/properties/propertyWithReceiver.kt", + defaultModelConfig + ) { model -> + with(model.members.single().members.single()) { + assertEquals("kotlin.String", name) + assertEquals(NodeKind.ExternalClass, kind) + with(members.single()) { + assertEquals("foobar", name) + assertEquals(NodeKind.Property, kind) + } + } + } + } + + @Test fun propertyOverride() { + checkSourceExistsAndVerifyModel("testdata/properties/propertyOverride.kt", defaultModelConfig) { model -> + with(model.members.single().members.single { it.name == "Bar" }.members.single { it.name == "xyzzy"}) { + assertEquals("xyzzy", name) + val override = references(RefKind.Override).single().to + assertEquals("xyzzy", override.name) + assertEquals("Foo", override.owner!!.name) + } + } + } + + @Test fun sinceKotlin() { + checkSourceExistsAndVerifyModel("testdata/properties/sinceKotlin.kt", defaultModelConfig) { model -> + with(model.members.single().members.single()) { + assertEquals(listOf("Kotlin 1.1"), platforms) + } + } + } +} + +class JSPropertyTest: BasePropertyTest(Platform.js) {} + +class JVMPropertyTest : BasePropertyTest(Platform.jvm) { + @Test + fun annotatedProperty() { + checkSourceExistsAndVerifyModel( + "testdata/properties/annotatedProperty.kt", + modelConfig = ModelConfig( + analysisPlatform = analysisPlatform, + withKotlinRuntime = true + ) + ) { model -> + with(model.members.single().members.single()) { + Assert.assertEquals(1, annotations.count()) + with(annotations[0]) { + Assert.assertEquals("Volatile", name) + Assert.assertEquals(Content.Empty, content) + Assert.assertEquals(NodeKind.Annotation, kind) + } + } + } + } + +} + +class CommonPropertyTest: BasePropertyTest(Platform.common) {} \ No newline at end of file -- cgit