diff options
author | Eugene Petrenko <eugene.petrenko@gmail.com> | 2018-09-11 14:03:29 +0300 |
---|---|---|
committer | Eugene Petrenko <eugene.petrenko@gmail.com> | 2018-09-11 14:03:29 +0300 |
commit | a54070f5db04d05b48c369b211efe044fbc02a8d (patch) | |
tree | aac5889906f49f68c39e1416ea39d4d19bad008e /core/src/test | |
parent | e29f1c966056b0f7ee31dd9bd7d55f9e526fa7fe (diff) | |
parent | 0df19264ccae3d294946caf634ee15eea0c4fe4a (diff) | |
download | dokka-a54070f5db04d05b48c369b211efe044fbc02a8d.tar.gz dokka-a54070f5db04d05b48c369b211efe044fbc02a8d.tar.bz2 dokka-a54070f5db04d05b48c369b211efe044fbc02a8d.zip |
Merge remote-tracking branch 'zub/dev-multiplatf' into kotlin-website-jonnyzzz
Diffstat (limited to 'core/src/test')
20 files changed, 1079 insertions, 633 deletions
diff --git a/core/src/test/kotlin/TestAPI.kt b/core/src/test/kotlin/TestAPI.kt index ff8a5260..8974bd0b 100644 --- a/core/src/test/kotlin/TestAPI.kt +++ b/core/src/test/kotlin/TestAPI.kt @@ -6,8 +6,8 @@ import com.intellij.openapi.util.Disposer import com.intellij.openapi.util.io.FileUtil import com.intellij.rt.execution.junit.FileComparisonFailure import org.jetbrains.dokka.* -import org.jetbrains.dokka.DokkaConfiguration.SourceLinkDefinition import org.jetbrains.dokka.Utilities.DokkaAnalysisModule +import org.jetbrains.dokka.Utilities.DokkaRunModule import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.cli.common.messages.MessageCollector @@ -15,49 +15,58 @@ 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 +data class ModelConfig( + val roots: Array<ContentRoot> = arrayOf(), + val withJdk: Boolean = false, + val withKotlinRuntime: Boolean = false, + val format: String = "html", + val includeNonPublic: Boolean = true, + val perPackageOptions: List<DokkaConfiguration.PackageOptions> = emptyList(), + val analysisPlatform: Platform = Platform.DEFAULT, + val defaultPlatforms: List<String> = emptyList(), + val noStdlibLink: Boolean = true, + val collectInheritedExtensionsFromLibraries: Boolean = false +) -fun verifyModel(vararg roots: ContentRoot, - withJdk: Boolean = false, - withKotlinRuntime: Boolean = false, - format: String = "html", - includeNonPublic: Boolean = true, - perPackageOptions: List<DokkaConfiguration.PackageOptions> = emptyList(), +fun verifyModel(modelConfig: ModelConfig, verifier: (DocumentationModule) -> Unit) { val documentation = DocumentationModule("test") - val options = DocumentationOptions( - "", - format, - includeNonPublic = includeNonPublic, - skipEmptyPackages = false, - includeRootPackage = true, - sourceLinks = listOf(), - perPackageOptions = perPackageOptions, - generateIndexPages = false, - noStdlibLink = true, - cacheRoot = "default", - languageVersion = null, - apiVersion = null + val passConfiguration = PassConfigurationImpl ( + includeNonPublic = modelConfig.includeNonPublic, + skipEmptyPackages = false, + includeRootPackage = true, + sourceLinks = listOf(), + perPackageOptions = modelConfig.perPackageOptions, + noStdlibLink = modelConfig.noStdlibLink, + noJdkLink = false, + languageVersion = null, + apiVersion = null, + collectInheritedExtensionsFromLibraries = modelConfig.collectInheritedExtensionsFromLibraries + ) + val configuration = DokkaConfigurationImpl( + outputDir = "", + format = modelConfig.format, + generateIndexPages = false, + cacheRoot = "default", + passesConfigurations = listOf(passConfiguration) ) - appendDocumentation(documentation, *roots, - withJdk = withJdk, - withKotlinRuntime = withKotlinRuntime, - options = options) - documentation.prepareForGeneration(options) + appendDocumentation(documentation, configuration, passConfiguration, modelConfig) + documentation.prepareForGeneration(configuration) verifier(documentation) } fun appendDocumentation(documentation: DocumentationModule, - vararg roots: ContentRoot, - withJdk: Boolean = false, - withKotlinRuntime: Boolean = false, - options: DocumentationOptions, - defaultPlatforms: List<String> = emptyList()) { + dokkaConfiguration: DokkaConfiguration, + passConfiguration: DokkaConfiguration.PassConfiguration, + modelConfig: ModelConfig +) { val messageCollector = object : MessageCollector { override fun clear() { @@ -82,64 +91,105 @@ fun appendDocumentation(documentation: DocumentationModule, override fun hasErrors() = false } - val environment = AnalysisEnvironment(messageCollector) + val environment = AnalysisEnvironment(messageCollector, modelConfig.analysisPlatform) environment.apply { - if (withJdk || withKotlinRuntime) { - val stringRoot = PathManager.getResourceRoot(String::class.java, "/java/lang/String.class") - addClasspath(File(stringRoot)) + if (modelConfig.withJdk || modelConfig.withKotlinRuntime) { + addClasspath(PathUtil.getJdkClassesRootsFromCurrentJre()) } - if (withKotlinRuntime) { - val kotlinStrictfpRoot = PathManager.getResourceRoot(Strictfp::class.java, "/kotlin/jvm/Strictfp.class") - addClasspath(File(kotlinStrictfpRoot)) + if (modelConfig.withKotlinRuntime) { + 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(roots.toList()) + addRoots(modelConfig.roots.toList()) - loadLanguageVersionSettings(options.languageVersion, options.apiVersion) + loadLanguageVersionSettings(passConfiguration.languageVersion, passConfiguration.apiVersion) } val defaultPlatformsProvider = object : DefaultPlatformsProvider { - override fun getDefaultPlatforms(descriptor: DeclarationDescriptor) = defaultPlatforms + override fun getDefaultPlatforms(descriptor: DeclarationDescriptor) = modelConfig.defaultPlatforms } - val injector = Guice.createInjector( - DokkaAnalysisModule(environment, options, defaultPlatformsProvider, documentation.nodeRefGraph, DokkaConsoleLogger)) + + val globalInjector = Guice.createInjector( + DokkaRunModule(dokkaConfiguration) + ) + + val injector = globalInjector.createChildInjector( + DokkaAnalysisModule( + environment, + dokkaConfiguration, + defaultPlatformsProvider, + documentation.nodeRefGraph, + passConfiguration, + DokkaConsoleLogger + ) + ) + buildDocumentationModule(injector, documentation) Disposer.dispose(environment) } -fun verifyModel(source: String, - withJdk: Boolean = false, - withKotlinRuntime: Boolean = false, - format: String = "html", - includeNonPublic: Boolean = true, - verifier: (DocumentationModule) -> Unit) { +fun checkSourceExistsAndVerifyModel(source: String, + modelConfig: ModelConfig = ModelConfig(), + verifier: (DocumentationModule) -> Unit) { if (!File(source).exists()) { throw IllegalArgumentException("Can't find test data file $source") } - verifyModel(contentRootFromPath(source), - withJdk = withJdk, - withKotlinRuntime = withKotlinRuntime, - format = format, - includeNonPublic = includeNonPublic, - verifier = verifier) + verifyModel( + ModelConfig( + roots = arrayOf(contentRootFromPath(source)), + withJdk = modelConfig.withJdk, + withKotlinRuntime = modelConfig.withKotlinRuntime, + format = modelConfig.format, + includeNonPublic = modelConfig.includeNonPublic, + analysisPlatform = modelConfig.analysisPlatform + ), + + verifier = verifier + ) } fun verifyPackageMember(source: String, - withJdk: Boolean = false, - withKotlinRuntime: Boolean = false, + modelConfig: ModelConfig = ModelConfig(), verifier: (DocumentationNode) -> Unit) { - verifyModel(source, withJdk = withJdk, withKotlinRuntime = withKotlinRuntime) { model -> + checkSourceExistsAndVerifyModel( + source, + modelConfig = ModelConfig( + withJdk = modelConfig.withJdk, + withKotlinRuntime = modelConfig.withKotlinRuntime, + analysisPlatform = modelConfig.analysisPlatform + ) + ) { model -> val pkg = model.members.single() verifier(pkg.members.single()) } } fun verifyJavaModel(source: String, - withKotlinRuntime: Boolean = false, + modelConfig: ModelConfig = ModelConfig(), verifier: (DocumentationModule) -> Unit) { val tempDir = FileUtil.createTempDirectory("dokka", "") try { val sourceFile = File(source) FileUtil.copy(sourceFile, File(tempDir, sourceFile.name)) - verifyModel(JavaSourceRoot(tempDir, null), withJdk = true, withKotlinRuntime = withKotlinRuntime, verifier = verifier) + verifyModel( + ModelConfig( + roots = arrayOf(JavaSourceRoot(tempDir, null)), + withJdk = true, + withKotlinRuntime = modelConfig.withKotlinRuntime, + analysisPlatform = modelConfig.analysisPlatform + ), + verifier = verifier + ) } finally { FileUtil.delete(tempDir) @@ -147,32 +197,42 @@ fun verifyJavaModel(source: String, } fun verifyJavaPackageMember(source: String, - withKotlinRuntime: Boolean = false, + modelConfig: ModelConfig = ModelConfig(), verifier: (DocumentationNode) -> Unit) { - verifyJavaModel(source, withKotlinRuntime) { model -> + verifyJavaModel(source, modelConfig) { model -> val pkg = model.members.single() verifier(pkg.members.single()) } } -fun verifyOutput(roots: Array<ContentRoot>, +fun verifyOutput(modelConfig: ModelConfig = ModelConfig(), outputExtension: String, - withJdk: Boolean = false, - withKotlinRuntime: Boolean = false, - format: String = "html", - includeNonPublic: Boolean = true, outputGenerator: (DocumentationModule, StringBuilder) -> Unit) { - verifyModel( - *roots, - withJdk = withJdk, - withKotlinRuntime = withKotlinRuntime, - format = format, - includeNonPublic = includeNonPublic - ) { - verifyModelOutput(it, outputExtension, roots.first().path, outputGenerator) + verifyModel(modelConfig) { + verifyModelOutput(it, outputExtension, modelConfig.roots.first().path, outputGenerator) } } +fun verifyOutput(path: String, + outputExtension: String, + modelConfig: ModelConfig = ModelConfig(), + outputGenerator: (DocumentationModule, StringBuilder) -> Unit) { + verifyOutput( + ModelConfig( + roots = arrayOf(contentRootFromPath(path)) + modelConfig.roots, + withJdk = modelConfig.withJdk, + withKotlinRuntime = modelConfig.withKotlinRuntime, + format = modelConfig.format, + includeNonPublic = modelConfig.includeNonPublic, + analysisPlatform = modelConfig.analysisPlatform, + noStdlibLink = modelConfig.noStdlibLink, + collectInheritedExtensionsFromLibraries = modelConfig.collectInheritedExtensionsFromLibraries + ), + outputExtension, + outputGenerator + ) +} + fun verifyModelOutput(it: DocumentationModule, outputExtension: String, sourcePath: String, @@ -184,29 +244,11 @@ fun verifyModelOutput(it: DocumentationModule, assertEqualsIgnoringSeparators(expectedFile, output.toString()) } -fun verifyOutput(path: String, - outputExtension: String, - withJdk: Boolean = false, - withKotlinRuntime: Boolean = false, - format: String = "html", - includeNonPublic: Boolean = true, - outputGenerator: (DocumentationModule, StringBuilder) -> Unit) { - verifyOutput( - arrayOf(contentRootFromPath(path)), - outputExtension, - withJdk, - withKotlinRuntime, - format, - includeNonPublic, - outputGenerator - ) -} - fun verifyJavaOutput(path: String, outputExtension: String, - withKotlinRuntime: Boolean = false, + modelConfig: ModelConfig = ModelConfig(), outputGenerator: (DocumentationModule, StringBuilder) -> Unit) { - verifyJavaModel(path, withKotlinRuntime) { model -> + verifyJavaModel(path, modelConfig) { model -> verifyModelOutput(model, outputExtension, path, outputGenerator) } } @@ -257,6 +299,14 @@ fun StringBuilder.appendNode(node: ContentNode): StringBuilder { is ContentBlock -> { appendChildren(node) } + is NodeRenderContent -> { + append("render(") + append(node.node) + append(",") + append(node.mode) + append(")") + } + is ContentSymbol -> { append(node.text) } is ContentEmpty -> { /* nothing */ } else -> throw IllegalStateException("Don't know how to format node $node") } @@ -270,21 +320,6 @@ fun ContentNode.toTestString(): String { }.toString() } -class InMemoryLocation(override val path: String): Location { - override fun relativePathTo(other: Location, anchor: String?): String = - if (anchor != null) other.path + "#" + anchor else other.path -} - -object InMemoryLocationService: LocationService { - override fun location(qualifiedName: List<String>, hasMembers: Boolean) = - InMemoryLocation(relativePathToNode(qualifiedName, hasMembers)) - - override val root: Location - get() = InMemoryLocation("") -} - -val tempLocation = InMemoryLocation("") - val ContentRoot.path: String get() = when(this) { is KotlinSourceRoot -> path diff --git a/core/src/test/kotlin/format/FileGeneratorTestCase.kt b/core/src/test/kotlin/format/FileGeneratorTestCase.kt new file mode 100644 index 00000000..ef9e815d --- /dev/null +++ b/core/src/test/kotlin/format/FileGeneratorTestCase.kt @@ -0,0 +1,35 @@ +package org.jetbrains.dokka.tests + +import org.jetbrains.dokka.* +import org.junit.Before +import org.junit.Rule +import org.junit.rules.TemporaryFolder + + +abstract class FileGeneratorTestCase { + abstract val formatService: FormatService + + @get:Rule + var folder = TemporaryFolder() + + val fileGenerator = FileGenerator(folder.apply { create() }.root) + + @Before + fun bindGenerator() { + fileGenerator.formatService = formatService + } + + fun buildPagesAndReadInto(nodes: List<DocumentationNode>, sb: StringBuilder) = with(fileGenerator) { + buildPages(nodes) + val byLocations = nodes.groupBy { location(it) } + byLocations.forEach { (loc, _) -> + if (byLocations.size > 1) { + if (sb.isNotBlank() && !sb.endsWith('\n')) { + sb.appendln() + } + sb.appendln("<!-- File: ${loc.file.relativeTo(root).toUnixString()} -->") + } + sb.append(loc.file.readText()) + } + } +}
\ No newline at end of file diff --git a/core/src/test/kotlin/format/GFMFormatTest.kt b/core/src/test/kotlin/format/GFMFormatTest.kt index c097c5c8..60de7d29 100644 --- a/core/src/test/kotlin/format/GFMFormatTest.kt +++ b/core/src/test/kotlin/format/GFMFormatTest.kt @@ -2,22 +2,35 @@ 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 { - private val gfmService = GFMFormatService(InMemoryLocationService, KotlinLanguageService(), listOf()) +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") + + @Test + fun sample() { + verifyGFMNodeByName("sample", "Foo", defaultModelConfig) } - @Test fun listInTableCell() { - verifyGFMNodeByName("listInTableCell", "Foo") + @Test + fun listInTableCell() { + verifyGFMNodeByName("listInTableCell", "Foo", defaultModelConfig) } - private fun verifyGFMNodeByName(fileName: String, name: String) { - verifyOutput("testdata/format/gfm/$fileName.kt", ".md") { model, output -> - gfmService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members.filter { it.name == name }) + 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 + ) } } } + + +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 index 01e4559e..20891963 100644 --- a/core/src/test/kotlin/format/HtmlFormatTest.kt +++ b/core/src/test/kotlin/format/HtmlFormatTest.kt @@ -3,175 +3,191 @@ 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 -class HtmlFormatTest { - private val htmlService = HtmlFormatService(InMemoryLocationService, KotlinLanguageService(), HtmlTemplateService.default(), listOf()) +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") + verifyHtmlNode("classWithCompanionObject", defaultModelConfig) } @Test fun htmlEscaping() { - verifyHtmlNode("htmlEscaping") + verifyHtmlNode("htmlEscaping", defaultModelConfig) } @Test fun overloads() { - verifyHtmlNodes("overloads") { model -> model.members } + verifyHtmlNodes("overloads", defaultModelConfig) { model -> model.members } } @Test fun overloadsWithDescription() { - verifyHtmlNode("overloadsWithDescription") + verifyHtmlNode("overloadsWithDescription", defaultModelConfig) } @Test fun overloadsWithDifferentDescriptions() { - verifyHtmlNode("overloadsWithDifferentDescriptions") + verifyHtmlNode("overloadsWithDifferentDescriptions", defaultModelConfig) } @Test fun deprecated() { - verifyOutput("testdata/format/deprecated.kt", ".package.html") { model, output -> - htmlService.createOutputBuilder(output, tempLocation).appendNodes(model.members) + verifyOutput("testdata/format/deprecated.kt", ".package.html", defaultModelConfig) { model, output -> + buildPagesAndReadInto(model.members, output) } - verifyOutput("testdata/format/deprecated.kt", ".class.html") { model, output -> - htmlService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members) + verifyOutput("testdata/format/deprecated.kt", ".class.html", defaultModelConfig) { model, output -> + buildPagesAndReadInto(model.members.single().members, output) } } @Test fun brokenLink() { - verifyHtmlNode("brokenLink") + verifyHtmlNode("brokenLink", defaultModelConfig) } @Test fun codeSpan() { - verifyHtmlNode("codeSpan") + verifyHtmlNode("codeSpan", defaultModelConfig) } @Test fun parenthesis() { - verifyHtmlNode("parenthesis") + verifyHtmlNode("parenthesis", defaultModelConfig) } @Test fun bracket() { - verifyHtmlNode("bracket") + verifyHtmlNode("bracket", defaultModelConfig) } @Test fun see() { - verifyHtmlNode("see") + verifyHtmlNode("see", defaultModelConfig) } @Test fun tripleBackticks() { - verifyHtmlNode("tripleBackticks") + verifyHtmlNode("tripleBackticks", defaultModelConfig) } @Test fun typeLink() { - verifyHtmlNodes("typeLink") { model -> model.members.single().members.filter { it.name == "Bar" } } + verifyHtmlNodes("typeLink", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } } @Test fun parameterAnchor() { - verifyHtmlNode("parameterAnchor") - } - - @Test fun javaSupertypeLink() { - verifyJavaHtmlNodes("JavaSupertype") { model -> - model.members.single().members.single { it.name == "JavaSupertype" }.members.filter { it.name == "Bar" } - } + verifyHtmlNode("parameterAnchor", defaultModelConfig) } @Test fun codeBlock() { - verifyHtmlNode("codeBlock") - } - - @Test fun javaLinkTag() { - verifyJavaHtmlNode("javaLinkTag") - } - - @Test fun javaLinkTagWithLabel() { - verifyJavaHtmlNode("javaLinkTagWithLabel") - } - - @Test fun javaSeeTag() { - verifyJavaHtmlNode("javaSeeTag") - } - - @Test fun javaDeprecated() { - verifyJavaHtmlNodes("javaDeprecated") { model -> - model.members.single().members.single { it.name == "Foo" }.members.filter { it.name == "foo" } - } + verifyHtmlNode("codeBlock", defaultModelConfig) } - - @Test fun crossLanguageKotlinExtendsJava() { - verifyOutput(arrayOf(KotlinSourceRoot("testdata/format/crossLanguage/kotlinExtendsJava/Bar.kt"), - JavaSourceRoot(File("testdata/format/crossLanguage/kotlinExtendsJava"), null)), - ".html") { model, output -> - htmlService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members.filter { it.name == "Bar" }) - } - } - @Test fun orderedList() { - verifyHtmlNodes("orderedList") { model -> model.members.single().members.filter { it.name == "Bar" } } + verifyHtmlNodes("orderedList", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } } @Test fun linkWithLabel() { - verifyHtmlNodes("linkWithLabel") { model -> model.members.single().members.filter { it.name == "Bar" } } + verifyHtmlNodes("linkWithLabel", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } } @Test fun entity() { - verifyHtmlNodes("entity") { model -> model.members.single().members.filter { it.name == "Bar" } } + verifyHtmlNodes("entity", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Bar" } } } @Test fun uninterpretedEmphasisCharacters() { - verifyHtmlNode("uninterpretedEmphasisCharacters") + verifyHtmlNode("uninterpretedEmphasisCharacters", defaultModelConfig) } @Test fun markdownInLinks() { - verifyHtmlNode("markdownInLinks") + verifyHtmlNode("markdownInLinks", defaultModelConfig) } @Test fun returnWithLink() { - verifyHtmlNode("returnWithLink") + verifyHtmlNode("returnWithLink", defaultModelConfig) } @Test fun linkWithStarProjection() { - verifyHtmlNode("linkWithStarProjection", withKotlinRuntime = true) + verifyHtmlNode("linkWithStarProjection", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) } @Test fun functionalTypeWithNamedParameters() { - verifyHtmlNode("functionalTypeWithNamedParameters") + verifyHtmlNode("functionalTypeWithNamedParameters", defaultModelConfig) } @Test fun sinceKotlin() { - verifyHtmlNode("sinceKotlin") + verifyHtmlNode("sinceKotlin", defaultModelConfig) } @Test fun blankLineInsideCodeBlock() { - verifyHtmlNode("blankLineInsideCodeBlock") + verifyHtmlNode("blankLineInsideCodeBlock", defaultModelConfig) } @Test fun indentedCodeBlock() { - verifyHtmlNode("indentedCodeBlock") + verifyHtmlNode("indentedCodeBlock", defaultModelConfig) } - private fun verifyHtmlNode(fileName: String, withKotlinRuntime: Boolean = false) { - verifyHtmlNodes(fileName, withKotlinRuntime) { model -> model.members.single().members } + private fun verifyHtmlNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { + verifyHtmlNodes(fileName, modelConfig) { model -> model.members.single().members } } private fun verifyHtmlNodes(fileName: String, - withKotlinRuntime: Boolean = false, + modelConfig: ModelConfig = ModelConfig(), nodeFilter: (DocumentationModule) -> List<DocumentationNode>) { - verifyOutput("testdata/format/$fileName.kt", ".html", withKotlinRuntime = withKotlinRuntime) { model, output -> - htmlService.createOutputBuilder(output, tempLocation).appendNodes(nodeFilter(model)) + 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<DocumentationNode>) { + 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 + ) } } - private fun verifyJavaHtmlNode(fileName: String, withKotlinRuntime: Boolean = false) { - verifyJavaHtmlNodes(fileName, withKotlinRuntime) { model -> model.members.single().members } + @Test fun javaLinkTag() { + verifyJavaHtmlNode("javaLinkTag", defaultModelConfig) + } + + @Test fun javaLinkTagWithLabel() { + verifyJavaHtmlNode("javaLinkTagWithLabel", defaultModelConfig) } - private fun verifyJavaHtmlNodes(fileName: String, - withKotlinRuntime: Boolean = false, - nodeFilter: (DocumentationModule) -> List<DocumentationNode>) { - verifyJavaOutput("testdata/format/$fileName.java", ".html", withKotlinRuntime = withKotlinRuntime) { model, output -> - htmlService.createOutputBuilder(output, tempLocation).appendNodes(nodeFilter(model)) + @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/KotlinWebSiteFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt index af44b048..4f292e37 100644 --- a/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt +++ b/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt @@ -5,8 +5,8 @@ import org.junit.Ignore import org.junit.Test @Ignore -class KotlinWebSiteFormatTest { - private val kwsService = KotlinWebsiteFormatService(InMemoryLocationService, KotlinLanguageService(), listOf(), DokkaConsoleLogger) +class KotlinWebSiteFormatTest: FileGeneratorTestCase() { + override val formatService = KotlinWebsiteFormatService(fileGenerator, KotlinLanguageService(), listOf(), DokkaConsoleLogger) @Test fun sample() { verifyKWSNodeByName("sample", "foo") @@ -29,36 +29,64 @@ class KotlinWebSiteFormatTest { val path = "dataTagsInGroupNode" val module = buildMultiplePlatforms(path) verifyModelOutput(module, ".md", "testdata/format/website/$path/multiplatform.kt") { model, output -> - kwsService.createOutputBuilder(output, tempLocation).appendNodes(listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode })) + buildPagesAndReadInto( + listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }), + output + ) } verifyMultiplatformPackage(module, path) } private fun verifyKWSNodeByName(fileName: String, name: String) { - verifyOutput("testdata/format/website/$fileName.kt", ".md", format = "kotlin-website") { model, output -> - kwsService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members.filter { it.name == name }) + verifyOutput("testdata/format/website/$fileName.kt", ".md", ModelConfig(format = "kotlin-website")) { model, output -> + buildPagesAndReadInto( + model.members.single().members.filter { it.name == name }, + output + ) } } private fun buildMultiplePlatforms(path: String): DocumentationModule { val module = DocumentationModule("test") - val options = DocumentationOptions( - outputDir = "", - outputFormat = "html", - generateIndexPages = false, - noStdlibLink = true, + val passConfiguration = PassConfigurationImpl(noStdlibLink = true, + noJdkLink = true, languageVersion = null, apiVersion = null ) - appendDocumentation(module, contentRootFromPath("testdata/format/website/$path/jvm.kt"), defaultPlatforms = listOf("JVM"), options = options) - appendDocumentation(module, contentRootFromPath("testdata/format/website/$path/jre7.kt"), defaultPlatforms = listOf("JVM", "JRE7"), options = options) - appendDocumentation(module, contentRootFromPath("testdata/format/website/$path/js.kt"), defaultPlatforms = listOf("JS"), options = options) + val configuration = DokkaConfigurationImpl( + outputDir = "", + format = "html", + generateIndexPages = false, + passesConfigurations = listOf(passConfiguration) + ) + + appendDocumentation( + module, configuration, passConfiguration, ModelConfig( + roots = arrayOf(contentRootFromPath("testdata/format/website/$path/jvm.kt")), + defaultPlatforms = listOf("JVM") + ) + + ) + + + appendDocumentation( + module, configuration, passConfiguration, ModelConfig( + roots = arrayOf(contentRootFromPath("testdata/format/website/$path/jre7.kt")), + defaultPlatforms = listOf("JVM", "JRE7") + ) + ) + appendDocumentation( + module, configuration, passConfiguration, ModelConfig( + roots = arrayOf(contentRootFromPath("testdata/format/website/$path/js.kt")), + defaultPlatforms = listOf("JS") + ) + ) return module } private fun verifyMultiplatformPackage(module: DocumentationModule, path: String) { verifyModelOutput(module, ".package.md", "testdata/format/website/$path/multiplatform.kt") { model, output -> - kwsService.createOutputBuilder(output, tempLocation).appendNodes(model.members) + buildPagesAndReadInto(model.members, output) } } diff --git a/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt index 433c9c13..1901154f 100644 --- a/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt +++ b/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt @@ -3,36 +3,36 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.* import org.junit.Test -class KotlinWebSiteHtmlFormatTest { - private val kwsService = KotlinWebsiteHtmlFormatService(InMemoryLocationService, KotlinLanguageService(), listOf()) - +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() { @@ -44,37 +44,73 @@ class KotlinWebSiteHtmlFormatTest { val path = "dataTagsInGroupNode" val module = buildMultiplePlatforms(path) verifyModelOutput(module, ".html", "testdata/format/website-html/$path/multiplatform.kt") { model, output -> - kwsService.createOutputBuilder(output, tempLocation).appendNodes(listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode })) + buildPagesAndReadInto( + listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }), + output + ) } verifyMultiplatformPackage(module, path) } - private fun verifyKWSNodeByName(fileName: String, name: String) { - verifyOutput("testdata/format/website-html/$fileName.kt", ".html", format = "kotlin-website-html") { model, output -> - kwsService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members.filter { it.name == name }) + 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) } } private fun buildMultiplePlatforms(path: String): DocumentationModule { val module = DocumentationModule("test") - val options = DocumentationOptions( - outputDir = "", - outputFormat = "kotlin-website-html", - generateIndexPages = false, + val passConfiguration = PassConfigurationImpl( noStdlibLink = true, + noJdkLink = true, languageVersion = null, apiVersion = null ) - appendDocumentation(module, contentRootFromPath("testdata/format/website-html/$path/jvm.kt"), defaultPlatforms = listOf("JVM"), options = options) - appendDocumentation(module, contentRootFromPath("testdata/format/website-html/$path/jre7.kt"), defaultPlatforms = listOf("JVM", "JRE7"), options = options) - appendDocumentation(module, contentRootFromPath("testdata/format/website-html/$path/js.kt"), defaultPlatforms = listOf("JS"), options = options) + + val dokkaConfiguration = DokkaConfigurationImpl( + outputDir = "", + format = "kotlin-website-html", + generateIndexPages = false, + passesConfigurations = listOf( + passConfiguration + ) + + ) + + appendDocumentation( + module, dokkaConfiguration, passConfiguration, ModelConfig( + roots = arrayOf(contentRootFromPath("testdata/format/website-html/$path/jvm.kt")), + defaultPlatforms = listOf("JVM") + ) + ) + appendDocumentation( + module, dokkaConfiguration, passConfiguration, ModelConfig( + roots = arrayOf(contentRootFromPath("testdata/format/website-html/$path/jre7.kt")), + defaultPlatforms = listOf("JVM", "JRE7") + ) + ) + appendDocumentation( + module, dokkaConfiguration, passConfiguration, ModelConfig( + roots = arrayOf(contentRootFromPath("testdata/format/website-html/$path/js.kt")), + defaultPlatforms = listOf("JS") + ) + ) + return module } private fun verifyMultiplatformPackage(module: DocumentationModule, path: String) { verifyModelOutput(module, ".package.html", "testdata/format/website-html/$path/multiplatform.kt") { model, output -> - kwsService.createOutputBuilder(output, tempLocation).appendNodes(model.members) + buildPagesAndReadInto(model.members, output) } } } + +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/KotlinWebSiteRunnableSamplesFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteRunnableSamplesFormatTest.kt index 44155004..453b1de8 100644 --- a/core/src/test/kotlin/format/KotlinWebSiteRunnableSamplesFormatTest.kt +++ b/core/src/test/kotlin/format/KotlinWebSiteRunnableSamplesFormatTest.kt @@ -8,32 +8,32 @@ import org.junit.Test @Ignore class KotlinWebSiteRunnableSamplesFormatTest { - private val kwsService = KotlinWebsiteRunnableSamplesFormatService(InMemoryLocationService, KotlinLanguageService(), listOf(), DokkaConsoleLogger) - - - @Test fun dropImport() { - verifyKWSNodeByName("dropImport", "foo") - } - - @Test fun sample() { - verifyKWSNodeByName("sample", "foo") - } - - @Test fun sampleWithAsserts() { - verifyKWSNodeByName("sampleWithAsserts", "a") - } - - @Test fun newLinesInSamples() { - verifyKWSNodeByName("newLinesInSamples", "foo") - } - - @Test fun newLinesInImportList() { - verifyKWSNodeByName("newLinesInImportList", "foo") - } - - private fun verifyKWSNodeByName(fileName: String, name: String) { - verifyOutput("testdata/format/website-samples/$fileName.kt", ".md", format = "kotlin-website-samples") { model, output -> - kwsService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members.filter { it.name == name }) - } - } +// private val kwsService = KotlinWebsiteRunnableSamplesFormatService(InMemoryLocationService, KotlinLanguageService(), listOf(), DokkaConsoleLogger) +// +// +// @Test fun dropImport() { +// verifyKWSNodeByName("dropImport", "foo") +// } +// +// @Test fun sample() { +// verifyKWSNodeByName("sample", "foo") +// } +// +// @Test fun sampleWithAsserts() { +// verifyKWSNodeByName("sampleWithAsserts", "a") +// } +// +// @Test fun newLinesInSamples() { +// verifyKWSNodeByName("newLinesInSamples", "foo") +// } +// +// @Test fun newLinesInImportList() { +// verifyKWSNodeByName("newLinesInImportList", "foo") +// } +// +// private fun verifyKWSNodeByName(fileName: String, name: String) { +// verifyOutput("testdata/format/website-samples/$fileName.kt", ".md", format = "kotlin-website-samples") { model, output -> +// kwsService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members.filter { it.name == name }) +// } +// } } diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt index 820af361..29d2d20f 100644 --- a/core/src/test/kotlin/format/MarkdownFormatTest.kt +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -3,272 +3,215 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.* import org.junit.Test -class MarkdownFormatTest { - private val markdownService = MarkdownFormatService(InMemoryLocationService, KotlinLanguageService(), listOf()) +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") + verifyMarkdownNode("emptyDescription", defaultModelConfig) } @Test fun classWithCompanionObject() { - verifyMarkdownNode("classWithCompanionObject") + verifyMarkdownNode("classWithCompanionObject", defaultModelConfig) } @Test fun annotations() { - verifyMarkdownNode("annotations") + verifyMarkdownNode("annotations", defaultModelConfig) } @Test fun annotationClass() { - verifyMarkdownNode("annotationClass", withKotlinRuntime = true) - verifyMarkdownPackage("annotationClass", withKotlinRuntime = true) - } - - @Test fun exceptionClass() { - verifyMarkdownNode("exceptionClass", withKotlinRuntime = true) - verifyMarkdownPackage("exceptionClass", withKotlinRuntime = true) - } - - @Test fun annotationParams() { - verifyMarkdownNode("annotationParams", withKotlinRuntime = true) - } - - @Test fun extensions() { - verifyOutput("testdata/format/extensions.kt", ".package.md") { model, output -> - markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members) - } - verifyOutput("testdata/format/extensions.kt", ".class.md") { model, output -> - markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members) - } + verifyMarkdownNode("annotationClass", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) + verifyMarkdownPackage("annotationClass", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) } @Test fun enumClass() { - verifyOutput("testdata/format/enumClass.kt", ".md") { model, output -> - markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members) + verifyOutput("testdata/format/enumClass.kt", ".md", defaultModelConfig) { model, output -> + buildPagesAndReadInto(model.members.single().members, output) } - verifyOutput("testdata/format/enumClass.kt", ".value.md") { model, output -> + verifyOutput("testdata/format/enumClass.kt", ".value.md", defaultModelConfig) { model, output -> val enumClassNode = model.members.single().members[0] - markdownService.createOutputBuilder(output, tempLocation).appendNodes( - enumClassNode.members.filter { it.name == "LOCAL_CONTINUE_AND_BREAK" }) + buildPagesAndReadInto( + enumClassNode.members.filter { it.name == "LOCAL_CONTINUE_AND_BREAK" }, + output + ) } } @Test fun varargsFunction() { - verifyMarkdownNode("varargsFunction") + verifyMarkdownNode("varargsFunction", defaultModelConfig) } @Test fun overridingFunction() { - verifyMarkdownNodes("overridingFunction") { model-> + 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") + verifyMarkdownNode("propertyVar", defaultModelConfig) } @Test fun functionWithDefaultParameter() { - verifyMarkdownNode("functionWithDefaultParameter") + verifyMarkdownNode("functionWithDefaultParameter", defaultModelConfig) } @Test fun accessor() { - verifyMarkdownNodes("accessor") { model -> + verifyMarkdownNodes("accessor", defaultModelConfig) { model -> model.members.single().members.first { it.name == "C" }.members.filter { it.name == "x" } } } @Test fun paramTag() { - verifyMarkdownNode("paramTag") + verifyMarkdownNode("paramTag", defaultModelConfig) } @Test fun throwsTag() { - verifyMarkdownNode("throwsTag") + verifyMarkdownNode("throwsTag", defaultModelConfig) } @Test fun typeParameterBounds() { - verifyMarkdownNode("typeParameterBounds") + verifyMarkdownNode("typeParameterBounds", defaultModelConfig) } @Test fun typeParameterVariance() { - verifyMarkdownNode("typeParameterVariance") + verifyMarkdownNode("typeParameterVariance", defaultModelConfig) } @Test fun typeProjectionVariance() { - verifyMarkdownNode("typeProjectionVariance") - } - - @Test fun javadocHtml() { - verifyJavaMarkdownNode("javadocHtml") - } - - @Test fun javaCodeLiteralTags() { - verifyJavaMarkdownNode("javaCodeLiteralTags") - } - - @Test fun javaCodeInParam() { - verifyJavaMarkdownNode("javaCodeInParam") - } - - @Test fun javaSpaceInAuthor() { - verifyJavaMarkdownNode("javaSpaceInAuthor") - } - - @Test fun nullability() { - verifyMarkdownNode("nullability") - } - - @Test fun operatorOverloading() { - verifyMarkdownNodes("operatorOverloading") { model-> - model.members.single().members.single { it.name == "C" }.members.filter { it.name == "plus" } - } - } - - @Test fun javadocOrderedList() { - verifyJavaMarkdownNodes("javadocOrderedList") { model -> - model.members.single().members.filter { it.name == "Bar" } - } + verifyMarkdownNode("typeProjectionVariance", defaultModelConfig) } @Test fun codeBlockNoHtmlEscape() { - verifyMarkdownNodeByName("codeBlockNoHtmlEscape", "hackTheArithmetic") + verifyMarkdownNodeByName("codeBlockNoHtmlEscape", "hackTheArithmetic", defaultModelConfig) } @Test fun companionObjectExtension() { - verifyMarkdownNodeByName("companionObjectExtension", "Foo") + verifyMarkdownNodeByName("companionObjectExtension", "Foo", defaultModelConfig) } @Test fun starProjection() { - verifyMarkdownNode("starProjection") + verifyMarkdownNode("starProjection", defaultModelConfig) } @Test fun extensionFunctionParameter() { - verifyMarkdownNode("extensionFunctionParameter") + verifyMarkdownNode("extensionFunctionParameter", defaultModelConfig) } @Test fun summarizeSignatures() { - verifyMarkdownNodes("summarizeSignatures") { model -> model.members } - } - - @Test fun summarizeSignaturesProperty() { - verifyMarkdownNodes("summarizeSignaturesProperty") { model -> model.members } + verifyMarkdownNodes("summarizeSignatures", defaultModelConfig) { model -> model.members } } @Test fun reifiedTypeParameter() { - verifyMarkdownNode("reifiedTypeParameter", withKotlinRuntime = true) + verifyMarkdownNode("reifiedTypeParameter", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) } @Test fun annotatedTypeParameter() { - verifyMarkdownNode("annotatedTypeParameter", withKotlinRuntime = true) + verifyMarkdownNode("annotatedTypeParameter", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) } @Test fun inheritedMembers() { - verifyMarkdownNodeByName("inheritedMembers", "Bar") + verifyMarkdownNodeByName("inheritedMembers", "Bar", defaultModelConfig) } @Test fun inheritedExtensions() { - verifyMarkdownNodeByName("inheritedExtensions", "Bar") + verifyMarkdownNodeByName("inheritedExtensions", "Bar", defaultModelConfig) } @Test fun genericInheritedExtensions() { - verifyMarkdownNodeByName("genericInheritedExtensions", "Bar") + verifyMarkdownNodeByName("genericInheritedExtensions", "Bar", defaultModelConfig) } @Test fun arrayAverage() { - verifyMarkdownNodeByName("arrayAverage", "XArray") + verifyMarkdownNodeByName("arrayAverage", "XArray", defaultModelConfig) } @Test fun multipleTypeParameterConstraints() { - verifyMarkdownNode("multipleTypeParameterConstraints", withKotlinRuntime = true) + verifyMarkdownNode("multipleTypeParameterConstraints", ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) } @Test fun inheritedCompanionObjectProperties() { - verifyMarkdownNodeByName("inheritedCompanionObjectProperties", "C") + verifyMarkdownNodeByName("inheritedCompanionObjectProperties", "C", defaultModelConfig) } @Test fun shadowedExtensionFunctions() { - verifyMarkdownNodeByName("shadowedExtensionFunctions", "Bar") + verifyMarkdownNodeByName("shadowedExtensionFunctions", "Bar", defaultModelConfig) } @Test fun inapplicableExtensionFunctions() { - verifyMarkdownNodeByName("inapplicableExtensionFunctions", "Bar") + verifyMarkdownNodeByName("inapplicableExtensionFunctions", "Bar", defaultModelConfig) } @Test fun receiverParameterTypeBound() { - verifyMarkdownNodeByName("receiverParameterTypeBound", "Foo") + verifyMarkdownNodeByName("receiverParameterTypeBound", "Foo", defaultModelConfig) } @Test fun extensionWithDocumentedReceiver() { - verifyMarkdownNodes("extensionWithDocumentedReceiver") { model -> + verifyMarkdownNodes("extensionWithDocumentedReceiver", defaultModelConfig) { model -> model.members.single().members.single().members.filter { it.name == "fn" } } } - @Test fun jdkLinks() { - verifyMarkdownNode("jdkLinks", withKotlinRuntime = true) - } - @Test fun codeBlock() { - verifyMarkdownNode("codeBlock") + verifyMarkdownNode("codeBlock", defaultModelConfig) } @Test fun exclInCodeBlock() { - verifyMarkdownNodeByName("exclInCodeBlock", "foo") + verifyMarkdownNodeByName("exclInCodeBlock", "foo", defaultModelConfig) } @Test fun backtickInCodeBlock() { - verifyMarkdownNodeByName("backtickInCodeBlock", "foo") + verifyMarkdownNodeByName("backtickInCodeBlock", "foo", defaultModelConfig) } @Test fun qualifiedNameLink() { - verifyMarkdownNodeByName("qualifiedNameLink", "foo", withKotlinRuntime = true) + verifyMarkdownNodeByName("qualifiedNameLink", "foo", + ModelConfig(analysisPlatform = analysisPlatform, withKotlinRuntime = true)) } @Test fun functionalTypeWithNamedParameters() { - verifyMarkdownNode("functionalTypeWithNamedParameters") + verifyMarkdownNode("functionalTypeWithNamedParameters", defaultModelConfig) } @Test fun typeAliases() { - verifyMarkdownNode("typeAliases") - verifyMarkdownPackage("typeAliases") - } - - @Test fun sampleByFQName() { - verifyMarkdownNode("sampleByFQName") + verifyMarkdownNode("typeAliases", defaultModelConfig) + verifyMarkdownPackage("typeAliases", defaultModelConfig) } @Test fun sampleByShortName() { - verifyMarkdownNode("sampleByShortName") + verifyMarkdownNode("sampleByShortName", defaultModelConfig) } @Test fun suspendParam() { - verifyMarkdownNode("suspendParam") - verifyMarkdownPackage("suspendParam") + verifyMarkdownNode("suspendParam", defaultModelConfig) + verifyMarkdownPackage("suspendParam", defaultModelConfig) } @Test fun sinceKotlin() { - verifyMarkdownNode("sinceKotlin") - verifyMarkdownPackage("sinceKotlin") + verifyMarkdownNode("sinceKotlin", defaultModelConfig) + verifyMarkdownPackage("sinceKotlin", defaultModelConfig) } @Test fun sinceKotlinWide() { - verifyMarkdownPackage("sinceKotlinWide") + verifyMarkdownPackage("sinceKotlinWide", defaultModelConfig) } @Test fun dynamicType() { - verifyMarkdownNode("dynamicType") + verifyMarkdownNode("dynamicType", defaultModelConfig) } @Test fun dynamicExtension() { - verifyMarkdownNodes("dynamicExtension") { model -> model.members.single().members.filter { it.name == "Foo" } } + verifyMarkdownNodes("dynamicExtension", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Foo" } } } @Test fun memberExtension() { - verifyMarkdownNodes("memberExtension") { model -> model.members.single().members.filter { it.name == "Foo" } } + verifyMarkdownNodes("memberExtension", defaultModelConfig) { model -> model.members.single().members.filter { it.name == "Foo" } } } @Test fun renderFunctionalTypeInParenthesisWhenItIsReceiver() { - verifyMarkdownNode("renderFunctionalTypeInParenthesisWhenItIsReceiver") + verifyMarkdownNode("renderFunctionalTypeInParenthesisWhenItIsReceiver", defaultModelConfig) } @Test fun multiplePlatforms() { @@ -282,37 +225,52 @@ class MarkdownFormatTest { @Test fun multiplePlatformsMergeMembers() { val module = buildMultiplePlatforms("multiplatform/mergeMembers") verifyModelOutput(module, ".md", "testdata/format/multiplatform/mergeMembers/foo.kt") { model, output -> - markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members) + 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 -> - markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members) + 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 -> - MarkdownFormatService(InMemoryLocationService, KotlinLanguageService(), listOf("JVM", "JS")) - .createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members) + 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, + val passConfiguration = PassConfigurationImpl( noStdlibLink = true, + noJdkLink = true, languageVersion = null, apiVersion = null ) - appendDocumentation(module, contentRootFromPath("testdata/format/$path/jvm.kt"), defaultPlatforms = listOf("JVM"), withKotlinRuntime = true, options = options) + + val dokkaConfiguration = DokkaConfigurationImpl( + outputDir = "", + format = "html", + generateIndexPages = false, + passesConfigurations = listOf( + passConfiguration + ) + ) + + appendDocumentation(module, dokkaConfiguration, passConfiguration, ModelConfig( + roots = arrayOf(contentRootFromPath("testdata/format/$path/jvm.kt")), + defaultPlatforms = listOf("JVM"), + withKotlinRuntime = true, + analysisPlatform = analysisPlatform + ) + ) verifyMultiplatformIndex(module, path) verifyMultiplatformPackage(module, path) } @@ -328,8 +286,10 @@ class MarkdownFormatTest { val path = "multiplatform/groupNode" val module = buildMultiplePlatforms(path) verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.kt") { model, output -> - markdownService.createOutputBuilder(output, tempLocation) - .appendNodes(listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode })) + buildPagesAndReadInto( + listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }), + output + ) } verifyMultiplatformPackage(module, path) } @@ -338,155 +298,179 @@ class MarkdownFormatTest { val path = "multiplatform/breadcrumbsInMemberOfMemberOfGroupNode" val module = buildMultiplePlatforms(path) verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.kt") { model, output -> - markdownService.createOutputBuilder(output, tempLocation) - .appendNodes(listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }?.member(NodeKind.Class)?.member(NodeKind.Function))) + buildPagesAndReadInto( + listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }?.member(NodeKind.Class)?.member(NodeKind.Function)), + output + ) } } @Test fun linksInEmphasis() { - verifyMarkdownNode("linksInEmphasis") + verifyMarkdownNode("linksInEmphasis", defaultModelConfig) } @Test fun linksInStrong() { - verifyMarkdownNode("linksInStrong") + verifyMarkdownNode("linksInStrong", defaultModelConfig) } @Test fun linksInHeaders() { - verifyMarkdownNode("linksInHeaders") + verifyMarkdownNode("linksInHeaders", defaultModelConfig) } @Test fun tokensInEmphasis() { - verifyMarkdownNode("tokensInEmphasis") + verifyMarkdownNode("tokensInEmphasis", defaultModelConfig) } @Test fun tokensInStrong() { - verifyMarkdownNode("tokensInStrong") + verifyMarkdownNode("tokensInStrong", defaultModelConfig) } @Test fun tokensInHeaders() { - verifyMarkdownNode("tokensInHeaders") + verifyMarkdownNode("tokensInHeaders", defaultModelConfig) } @Test fun unorderedLists() { - verifyMarkdownNode("unorderedLists") + verifyMarkdownNode("unorderedLists", defaultModelConfig) } @Test fun nestedLists() { - verifyMarkdownNode("nestedLists") + verifyMarkdownNode("nestedLists", defaultModelConfig) } @Test fun referenceLink() { - verifyMarkdownNode("referenceLink") + verifyMarkdownNode("referenceLink", defaultModelConfig) } @Test fun externalReferenceLink() { - verifyMarkdownNode("externalReferenceLink") + verifyMarkdownNode("externalReferenceLink", defaultModelConfig) } @Test fun newlineInTableCell() { - verifyMarkdownPackage("newlineInTableCell") + verifyMarkdownPackage("newlineInTableCell", defaultModelConfig) } @Test fun indentedCodeBlock() { - verifyMarkdownNode("indentedCodeBlock") + verifyMarkdownNode("indentedCodeBlock", defaultModelConfig) } @Test fun receiverReference() { - verifyMarkdownNode("receiverReference") + verifyMarkdownNode("receiverReference", defaultModelConfig) } @Test fun extensionScope() { - verifyMarkdownNodeByName("extensionScope", "test") + verifyMarkdownNodeByName("extensionScope", "test", defaultModelConfig) } @Test fun typeParameterReference() { - verifyMarkdownNode("typeParameterReference") + verifyMarkdownNode("typeParameterReference", defaultModelConfig) } @Test fun notPublishedTypeAliasAutoExpansion() { - verifyMarkdownNodeByName("notPublishedTypeAliasAutoExpansion", "foo", includeNonPublic = false) + verifyMarkdownNodeByName("notPublishedTypeAliasAutoExpansion", "foo", ModelConfig( + analysisPlatform = analysisPlatform, + includeNonPublic = false + )) } @Test fun companionImplements() { - verifyMarkdownNodeByName("companionImplements", "Foo") + verifyMarkdownNodeByName("companionImplements", "Foo", defaultModelConfig) } + private fun buildMultiplePlatforms(path: String): DocumentationModule { val module = DocumentationModule("test") - val options = DocumentationOptions( - outputDir = "", - outputFormat = "html", - generateIndexPages = false, + val passConfiguration = PassConfigurationImpl( noStdlibLink = true, + noJdkLink = true, languageVersion = null, apiVersion = null ) - appendDocumentation(module, contentRootFromPath("testdata/format/$path/jvm.kt"), defaultPlatforms = listOf("JVM"), options = options) - appendDocumentation(module, contentRootFromPath("testdata/format/$path/js.kt"), defaultPlatforms = listOf("JS"), options = options) + val dokkaConfiguration = DokkaConfigurationImpl( + outputDir = "", + format = "html", + generateIndexPages = false, + passesConfigurations = listOf( + passConfiguration + ) + + ) + appendDocumentation( + module, dokkaConfiguration, passConfiguration, ModelConfig( + roots = arrayOf(contentRootFromPath("testdata/format/$path/jvm.kt")), + defaultPlatforms = listOf("JVM"), + analysisPlatform = Platform.jvm + ) + ) + appendDocumentation( + module, dokkaConfiguration, passConfiguration, 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 -> - markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members) + buildPagesAndReadInto(model.members, output) } } private fun verifyMultiplatformIndex(module: DocumentationModule, path: String) { verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.index.kt") { model, output -> - MarkdownFormatService(InMemoryLocationService, KotlinLanguageService(), listOf()) - .createOutputBuilder(output, tempLocation).appendNodes(listOf(model)) + val service = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf()) + fileGenerator.formatService = service + buildPagesAndReadInto(listOf(model), output) } } @Test fun blankLineInsideCodeBlock() { - verifyMarkdownNode("blankLineInsideCodeBlock") + verifyMarkdownNode("blankLineInsideCodeBlock", defaultModelConfig) } - private fun verifyMarkdownPackage(fileName: String, withKotlinRuntime: Boolean = false) { - verifyOutput("testdata/format/$fileName.kt", ".package.md", withKotlinRuntime = withKotlinRuntime) { model, output -> - markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members) + protected fun verifyMarkdownPackage(fileName: String, modelConfig: ModelConfig = ModelConfig()) { + verifyOutput("testdata/format/$fileName.kt", ".package.md", modelConfig) { model, output -> + buildPagesAndReadInto(model.members, output) } } - private fun verifyMarkdownNode(fileName: String, withKotlinRuntime: Boolean = false) { - verifyMarkdownNodes(fileName, withKotlinRuntime) { model -> model.members.single().members } + protected fun verifyMarkdownNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { + verifyMarkdownNodes(fileName, modelConfig) { model -> model.members.single().members } } - private fun verifyMarkdownNodes( + protected fun verifyMarkdownNodes( fileName: String, - withKotlinRuntime: Boolean = false, - includeNonPublic: Boolean = true, + modelConfig: ModelConfig = ModelConfig(), nodeFilter: (DocumentationModule) -> List<DocumentationNode> ) { verifyOutput( "testdata/format/$fileName.kt", ".md", - withKotlinRuntime = withKotlinRuntime, - includeNonPublic = includeNonPublic + modelConfig ) { model, output -> - markdownService.createOutputBuilder(output, tempLocation).appendNodes(nodeFilter(model)) + buildPagesAndReadInto(nodeFilter(model), output) } } - private fun verifyJavaMarkdownNode(fileName: String, withKotlinRuntime: Boolean = false) { - verifyJavaMarkdownNodes(fileName, withKotlinRuntime) { model -> model.members.single().members } + protected fun verifyJavaMarkdownNode(fileName: String, modelConfig: ModelConfig = ModelConfig()) { + verifyJavaMarkdownNodes(fileName, modelConfig) { model -> model.members.single().members } } - private fun verifyJavaMarkdownNodes(fileName: String, withKotlinRuntime: Boolean = false, nodeFilter: (DocumentationModule) -> List<DocumentationNode>) { - verifyJavaOutput("testdata/format/$fileName.java", ".md", withKotlinRuntime = withKotlinRuntime) { model, output -> - markdownService.createOutputBuilder(output, tempLocation).appendNodes(nodeFilter(model)) + protected fun verifyJavaMarkdownNodes(fileName: String, modelConfig: ModelConfig = ModelConfig(), nodeFilter: (DocumentationModule) -> List<DocumentationNode>) { + verifyJavaOutput("testdata/format/$fileName.java", ".md", modelConfig) { model, output -> + buildPagesAndReadInto(nodeFilter(model), output) } } - private fun verifyMarkdownNodeByName( + protected fun verifyMarkdownNodeByName( fileName: String, name: String, - withKotlinRuntime: Boolean = false, - includeNonPublic: Boolean = true + modelConfig: ModelConfig = ModelConfig() ) { - verifyMarkdownNodes(fileName, withKotlinRuntime, includeNonPublic) { model-> + verifyMarkdownNodes(fileName, modelConfig) { model-> val nodesWithName = model.members.single().members.filter { it.name == name } if (nodesWithName.isEmpty()) { throw IllegalArgumentException("Found no nodes named $name") @@ -495,3 +479,116 @@ class MarkdownFormatTest { } } } + +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/format/PackageDocsTest.kt b/core/src/test/kotlin/format/PackageDocsTest.kt index a5547025..b7fff1e2 100644 --- a/core/src/test/kotlin/format/PackageDocsTest.kt +++ b/core/src/test/kotlin/format/PackageDocsTest.kt @@ -1,20 +1,46 @@ package org.jetbrains.dokka.tests.format +import com.intellij.openapi.Disposable +import com.intellij.openapi.util.Disposer import com.nhaarman.mockito_kotlin.any import com.nhaarman.mockito_kotlin.doAnswer import com.nhaarman.mockito_kotlin.eq import com.nhaarman.mockito_kotlin.mock import org.jetbrains.dokka.* -import org.jetbrains.dokka.tests.InMemoryLocationService import org.jetbrains.dokka.tests.assertEqualsIgnoringSeparators +import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles +import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment +import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreProjectEnvironment +import org.jetbrains.kotlin.config.CompilerConfiguration import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor +import org.junit.After import org.junit.Assert.assertEquals +import org.junit.Before import org.junit.Test import java.io.File -public class PackageDocsTest { +class PackageDocsTest { + + private lateinit var testDisposable: Disposable + + @Before + fun setup() { + testDisposable = Disposer.newDisposable() + } + + @After + fun cleanup() { + Disposer.dispose(testDisposable) + } + + fun createPackageDocs(linkResolver: DeclarationLinkResolver?): PackageDocs { + val environment = KotlinCoreEnvironment.createForTests(testDisposable, CompilerConfiguration.EMPTY, EnvironmentConfigFiles.JVM_CONFIG_FILES) + return PackageDocs(linkResolver, DokkaConsoleLogger, environment, mock(), mock()) + } + @Test fun verifyParse() { - val docs = PackageDocs(null, DokkaConsoleLogger) + + val docs = createPackageDocs(null) docs.parse("testdata/packagedocs/stdlib.md", emptyList()) val packageContent = docs.packageContent["kotlin"]!! val block = (packageContent.children.single() as ContentBlock).children.first() as ContentText @@ -29,7 +55,7 @@ public class PackageDocsTest { val mockPackageDescriptor = mock<PackageFragmentDescriptor> {} - val docs = PackageDocs(mockLinkResolver, DokkaConsoleLogger) + val docs = createPackageDocs(mockLinkResolver) docs.parse("testdata/packagedocs/referenceLinks.md", listOf(mockPackageDescriptor)) checkMarkdownOutput(docs, "testdata/packagedocs/referenceLinks") @@ -37,8 +63,17 @@ public class PackageDocsTest { fun checkMarkdownOutput(docs: PackageDocs, expectedFilePrefix: String) { + val generator = FileGenerator(File("")) + val out = StringBuilder() - val outputBuilder = MarkdownOutputBuilder(out, InMemoryLocationService.root, InMemoryLocationService, KotlinLanguageService(), ".md", emptyList()) + val outputBuilder = MarkdownOutputBuilder( + out, + FileLocation(generator.root), + generator, + KotlinLanguageService(), + ".md", + emptyList() + ) fun checkOutput(content: Content, filePostfix: String) { outputBuilder.appendContent(content) val expectedFile = File(expectedFilePrefix + filePostfix) diff --git a/core/src/test/kotlin/issues/IssuesTest.kt b/core/src/test/kotlin/issues/IssuesTest.kt index 625d7e46..da5acd6e 100644 --- a/core/src/test/kotlin/issues/IssuesTest.kt +++ b/core/src/test/kotlin/issues/IssuesTest.kt @@ -2,17 +2,19 @@ package issues import org.jetbrains.dokka.DocumentationNode import org.jetbrains.dokka.NodeKind -import org.jetbrains.dokka.tests.toTestString -import org.jetbrains.dokka.tests.verifyModel +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() { - verifyModel("testdata/issues/errorClasses.kt", withJdk = true, withKotlinRuntime = true) { model -> + checkSourceExistsAndVerifyModel("testdata/issues/errorClasses.kt", + 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 @@ -26,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 45c45aa4..7976fccc 100644 --- a/core/src/test/kotlin/javadoc/JavadocTest.kt +++ b/core/src/test/kotlin/javadoc/JavadocTest.kt @@ -3,14 +3,18 @@ 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 { + val defaultModelConfig = ModelConfig(analysisPlatform = Platform.jvm) + @Test fun testTypes() { - verifyJavadoc("testdata/javadoc/types.kt", 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" }!! @@ -26,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) @@ -39,7 +43,10 @@ class JavadocTest { } @Test fun testException() { - verifyJavadoc("testdata/javadoc/exception.kt", 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()) @@ -47,7 +54,10 @@ class JavadocTest { } @Test fun testByteArray() { - verifyJavadoc("testdata/javadoc/bytearr.kt", withKotlinRuntime = true) { doc -> + verifyJavadoc( + "testdata/javadoc/bytearr.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> val classDoc = doc.classNamed("foo.ByteArray")!! assertNotNull(classDoc.asClassDoc()) @@ -57,7 +67,10 @@ class JavadocTest { } @Test fun testStringArray() { - verifyJavadoc("testdata/javadoc/stringarr.kt", withKotlinRuntime = true) { doc -> + verifyJavadoc( + "testdata/javadoc/stringarr.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> val classDoc = doc.classNamed("foo.Foo")!! assertNotNull(classDoc.asClassDoc()) @@ -70,7 +83,10 @@ class JavadocTest { } @Test fun testJvmName() { - verifyJavadoc("testdata/javadoc/jvmname.kt", withKotlinRuntime = true) { doc -> + verifyJavadoc( + "testdata/javadoc/jvmname.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> val classDoc = doc.classNamed("foo.Apple")!! assertNotNull(classDoc.asClassDoc()) @@ -80,7 +96,10 @@ class JavadocTest { } @Test fun testLinkWithParam() { - verifyJavadoc("testdata/javadoc/paramlink.kt", 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<SeeTagAdapter>() @@ -91,7 +110,10 @@ class JavadocTest { } @Test fun testInternalVisibility() { - verifyJavadoc("testdata/javadoc/internal.kt", 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) @@ -100,7 +122,10 @@ class JavadocTest { } @Test fun testSuppress() { - verifyJavadoc("testdata/javadoc/suppress.kt", 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")) @@ -111,7 +136,10 @@ class JavadocTest { } @Test fun testTypeAliases() { - verifyJavadoc("testdata/javadoc/typealiases.kt", withKotlinRuntime = true) { doc -> + verifyJavadoc( + "testdata/javadoc/typealiases.kt", + ModelConfig(analysisPlatform = Platform.jvm, withKotlinRuntime = true) + ) { doc -> assertNull(doc.classNamed("B")) assertNull(doc.classNamed("D")) @@ -126,7 +154,10 @@ class JavadocTest { } @Test fun testKDocKeywordsOnMethod() { - verifyJavadoc("testdata/javadoc/kdocKeywordsOnMethod.kt", 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()) @@ -136,7 +167,10 @@ class JavadocTest { @Test fun testBlankLineInsideCodeBlock() { - verifyJavadoc("testdata/javadoc/blankLineInsideCodeBlock.kt", 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(""" @@ -153,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<SeeMethodTagAdapter>().first() assertEquals("TestClass.Companion", tag.referencedClassName()) @@ -162,12 +196,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) } diff --git a/core/src/test/kotlin/model/ClassTest.kt b/core/src/test/kotlin/model/ClassTest.kt index ea586041..b8e58a62 100644 --- a/core/src/test/kotlin/model/ClassTest.kt +++ b/core/src/test/kotlin/model/ClassTest.kt @@ -2,14 +2,17 @@ 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 -class ClassTest { +abstract class BaseClassTest(val analysisPlatform: Platform) { + protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) @Test fun emptyClass() { - verifyModel("testdata/classes/emptyClass.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/classes/emptyClass.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals(NodeKind.Class, kind) assertEquals("Klass", name) @@ -21,7 +24,7 @@ class ClassTest { } @Test fun emptyObject() { - verifyModel("testdata/classes/emptyObject.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/classes/emptyObject.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals(NodeKind.Object, kind) assertEquals("Obj", name) @@ -33,7 +36,7 @@ class ClassTest { } @Test fun classWithConstructor() { - verifyModel("testdata/classes/classWithConstructor.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/classes/classWithConstructor.kt", defaultModelConfig) { model -> with (model.members.single().members.single()) { assertEquals(NodeKind.Class, kind) assertEquals("Klass", name) @@ -63,7 +66,7 @@ class ClassTest { } @Test fun classWithFunction() { - verifyModel("testdata/classes/classWithFunction.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/classes/classWithFunction.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals(NodeKind.Class, kind) assertEquals("Klass", name) @@ -93,7 +96,7 @@ class ClassTest { } @Test fun classWithProperty() { - verifyModel("testdata/classes/classWithProperty.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/classes/classWithProperty.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals(NodeKind.Class, kind) assertEquals("Klass", name) @@ -123,7 +126,7 @@ class ClassTest { } @Test fun classWithCompanionObject() { - verifyModel("testdata/classes/classWithCompanionObject.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/classes/classWithCompanionObject.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals(NodeKind.Class, kind) assertEquals("Klass", name) @@ -151,33 +154,25 @@ class ClassTest { } } - @Test fun annotatedClass() { - verifyPackageMember("testdata/classes/annotatedClass.kt", withKotlinRuntime = true) { cls -> - assertEquals(1, cls.annotations.count()) - with(cls.annotations[0]) { - assertEquals("Strictfp", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Annotation, kind) - } - } - } - @Test fun dataClass() { - verifyPackageMember("testdata/classes/dataClass.kt") { cls -> + 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") { cls -> + 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() { - verifyModel("testdata/classes/annotatedClassWithAnnotationParameters.kt") { model -> + checkSourceExistsAndVerifyModel( + "testdata/classes/annotatedClassWithAnnotationParameters.kt", + defaultModelConfig + ) { model -> with(model.members.single().members.single()) { with(deprecation!!) { assertEquals("Deprecated", name) @@ -197,29 +192,8 @@ class ClassTest { } } - @Test fun javaAnnotationClass() { - verifyModel("testdata/classes/javaAnnotationClass.kt", withJdk = true) { model -> - with(model.members.single().members.single()) { - assertEquals(1, annotations.count()) - with(annotations[0]) { - assertEquals("Retention", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Annotation, kind) - with(details[0]) { - assertEquals(NodeKind.Parameter, kind) - assertEquals(1, details.count()) - with(details[0]) { - assertEquals(NodeKind.Value, kind) - assertEquals("RetentionPolicy.SOURCE", name) - } - } - } - } - } - } - @Test fun notOpenClass() { - verifyModel("testdata/classes/notOpenClass.kt") { model -> + 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) @@ -232,7 +206,7 @@ class ClassTest { } @Test fun indirectOverride() { - verifyModel("testdata/classes/indirectOverride.kt") { model -> + 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) @@ -245,7 +219,7 @@ class ClassTest { } @Test fun innerClass() { - verifyPackageMember("testdata/classes/innerClass.kt") { cls -> + 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) @@ -254,7 +228,7 @@ class ClassTest { } @Test fun companionObjectExtension() { - verifyModel("testdata/classes/companionObjectExtension.kt") { model -> + 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 } @@ -263,7 +237,7 @@ class ClassTest { } @Test fun secondaryConstructor() { - verifyPackageMember("testdata/classes/secondaryConstructor.kt") { cls -> + 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}) { @@ -274,7 +248,7 @@ class ClassTest { } @Test fun sinceKotlin() { - verifyModel("testdata/classes/sinceKotlin.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/classes/sinceKotlin.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals(listOf("Kotlin 1.1"), platforms) } @@ -282,7 +256,10 @@ class ClassTest { } @Test fun privateCompanionObject() { - verifyModel("testdata/classes/privateCompanionObject.kt", includeNonPublic = false) { model -> + 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) @@ -291,3 +268,51 @@ class ClassTest { } } + +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 3752bb8c..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() { - verifyModel("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() { - verifyModel("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() { - verifyModel("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() { - verifyModel("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() { - verifyModel("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() { - verifyModel("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() { - verifyModel("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() { - verifyModel("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() { - verifyModel("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() { - verifyModel("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() { - verifyModel("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() { - verifyModel("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() { - verifyModel("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() { - verifyModel("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 32910682..47685df2 100644 --- a/core/src/test/kotlin/model/FunctionTest.kt +++ b/core/src/test/kotlin/model/FunctionTest.kt @@ -2,14 +2,17 @@ package org.jetbrains.dokka.tests 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 -import kotlin.test.assertNotNull -class FunctionTest { +abstract class BaseFunctionTest(val analysisPlatform: Platform) { + protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) @Test fun function() { - verifyModel("testdata/functions/function.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/functions/function.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("fn", name) assertEquals(NodeKind.Function, kind) @@ -22,7 +25,7 @@ class FunctionTest { } @Test fun functionWithReceiver() { - verifyModel("testdata/functions/functionWithReceiver.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/functions/functionWithReceiver.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("kotlin.String", name) assertEquals(NodeKind.ExternalClass, kind) @@ -54,7 +57,7 @@ class FunctionTest { } @Test fun genericFunction() { - verifyModel("testdata/functions/genericFunction.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/functions/genericFunction.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("generic", name) assertEquals(NodeKind.Function, kind) @@ -78,7 +81,7 @@ class FunctionTest { } } @Test fun genericFunctionWithConstraints() { - verifyModel("testdata/functions/genericFunctionWithConstraints.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/functions/genericFunctionWithConstraints.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("generic", name) assertEquals(NodeKind.Function, kind) @@ -118,7 +121,7 @@ class FunctionTest { } @Test fun functionWithParams() { - verifyModel("testdata/functions/functionWithParams.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/functions/functionWithParams.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("function", name) assertEquals(NodeKind.Function, kind) @@ -143,32 +146,21 @@ Documentation""", content.description.toTestString()) } } - @Test fun annotatedFunction() { - verifyPackageMember("testdata/functions/annotatedFunction.kt", withKotlinRuntime = true) { func -> - assertEquals(1, func.annotations.count()) - with(func.annotations[0]) { - assertEquals("Strictfp", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Annotation, kind) - } - } - } - @Test fun functionWithNotDocumentedAnnotation() { - verifyPackageMember("testdata/functions/functionWithNotDocumentedAnnotation.kt") { func -> + verifyPackageMember("testdata/functions/functionWithNotDocumentedAnnotation.kt", defaultModelConfig) { func -> assertEquals(0, func.annotations.count()) } } @Test fun inlineFunction() { - verifyPackageMember("testdata/functions/inlineFunction.kt") { func -> + verifyPackageMember("testdata/functions/inlineFunction.kt", defaultModelConfig) { func -> val modifiers = func.details(NodeKind.Modifier).map { it.name } assertTrue("inline" in modifiers) } } @Test fun functionWithAnnotatedParam() { - verifyModel("testdata/functions/functionWithAnnotatedParam.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/functions/functionWithAnnotatedParam.kt", defaultModelConfig) { model -> with(model.members.single().members.single { it.name == "function" }) { with(details(NodeKind.Parameter).first()) { assertEquals(1, annotations.count()) @@ -183,7 +175,7 @@ Documentation""", content.description.toTestString()) } @Test fun functionWithNoinlineParam() { - verifyPackageMember("testdata/functions/functionWithNoinlineParam.kt") { func -> + verifyPackageMember("testdata/functions/functionWithNoinlineParam.kt", defaultModelConfig) { func -> with(func.details(NodeKind.Parameter).first()) { val modifiers = details(NodeKind.Modifier).map { it.name } assertTrue("noinline" in modifiers) @@ -192,7 +184,10 @@ Documentation""", content.description.toTestString()) } @Test fun annotatedFunctionWithAnnotationParameters() { - verifyModel("testdata/functions/annotatedFunctionWithAnnotationParameters.kt") { model -> + checkSourceExistsAndVerifyModel( + "testdata/functions/annotatedFunctionWithAnnotationParameters.kt", + defaultModelConfig + ) { model -> with(model.members.single().members.single { it.name == "f" }) { assertEquals(1, annotations.count()) with(annotations[0]) { @@ -214,7 +209,7 @@ Documentation""", content.description.toTestString()) } @Test fun functionWithDefaultParameter() { - verifyModel("testdata/functions/functionWithDefaultParameter.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/functions/functionWithDefaultParameter.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { with(details.elementAt(3)) { val value = details(NodeKind.Value) @@ -228,10 +223,32 @@ Documentation""", content.description.toTestString()) } @Test fun sinceKotlin() { - verifyModel("testdata/functions/sinceKotlin.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/functions/sinceKotlin.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals(listOf("Kotlin 1.1"), platforms) } } } } + +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/JavaTest.kt b/core/src/test/kotlin/model/JavaTest.kt index e6c22ee4..13bb72ba 100644 --- a/core/src/test/kotlin/model/JavaTest.kt +++ b/core/src/test/kotlin/model/JavaTest.kt @@ -1,14 +1,16 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.NodeKind +import org.jetbrains.dokka.Platform import org.jetbrains.dokka.RefKind import org.junit.Assert.* import org.junit.Ignore import org.junit.Test public class JavaTest { + private val defaultModelConfig = ModelConfig(analysisPlatform = Platform.jvm) @Test fun function() { - verifyJavaPackageMember("testdata/java/member.java") { cls -> + verifyJavaPackageMember("testdata/java/member.java", defaultModelConfig) { cls -> assertEquals("Test", cls.name) assertEquals(NodeKind.Class, cls.kind) with(cls.members(NodeKind.Function).single()) { @@ -18,12 +20,12 @@ public class JavaTest { with(content.sections[0]) { assertEquals("Parameters", tag) assertEquals("name", subjectName) - assertEquals("is String parameter", toTestString()) + assertEquals("render(Type:String,SUMMARY): is String parameter", toTestString()) } with(content.sections[1]) { assertEquals("Parameters", tag) assertEquals("value", subjectName) - assertEquals("is int parameter", toTestString()) + assertEquals("render(Type:String,SUMMARY): is int parameter", toTestString()) } with(content.sections[2]) { assertEquals("Author", tag) @@ -45,7 +47,7 @@ public class JavaTest { } @Test fun memberWithModifiers() { - verifyJavaPackageMember("testdata/java/memberWithModifiers.java") { cls -> + verifyJavaPackageMember("testdata/java/memberWithModifiers.java", defaultModelConfig) { cls -> val modifiers = cls.details(NodeKind.Modifier).map { it.name } assertTrue("abstract" in modifiers) with(cls.members.single { it.name == "fn" }) { @@ -58,7 +60,7 @@ public class JavaTest { } @Test fun superClass() { - verifyJavaPackageMember("testdata/java/superClass.java") { cls -> + verifyJavaPackageMember("testdata/java/superClass.java", defaultModelConfig) { cls -> val superTypes = cls.details(NodeKind.Supertype) assertEquals(2, superTypes.size) assertEquals("Exception", superTypes[0].name) @@ -67,7 +69,7 @@ public class JavaTest { } @Test fun arrayType() { - verifyJavaPackageMember("testdata/java/arrayType.java") { cls -> + verifyJavaPackageMember("testdata/java/arrayType.java", defaultModelConfig) { cls -> with(cls.members(NodeKind.Function).single()) { val type = detail(NodeKind.Type) assertEquals("Array", type.name) @@ -81,7 +83,7 @@ public class JavaTest { } @Test fun typeParameter() { - verifyJavaPackageMember("testdata/java/typeParameter.java") { cls -> + verifyJavaPackageMember("testdata/java/typeParameter.java", defaultModelConfig) { cls -> val typeParameters = cls.details(NodeKind.TypeParameter) with(typeParameters.single()) { assertEquals("T", name) @@ -100,7 +102,7 @@ public class JavaTest { } @Test fun constructors() { - verifyJavaPackageMember("testdata/java/constructors.java") { cls -> + verifyJavaPackageMember("testdata/java/constructors.java", defaultModelConfig) { cls -> val constructors = cls.members(NodeKind.Constructor) assertEquals(2, constructors.size) with(constructors[0]) { @@ -110,14 +112,14 @@ public class JavaTest { } @Test fun innerClass() { - verifyJavaPackageMember("testdata/java/InnerClass.java") { cls -> + verifyJavaPackageMember("testdata/java/InnerClass.java", defaultModelConfig) { cls -> val innerClass = cls.members(NodeKind.Class).single() assertEquals("D", innerClass.name) } } @Test fun varargs() { - verifyJavaPackageMember("testdata/java/varargs.java") { cls -> + verifyJavaPackageMember("testdata/java/varargs.java", defaultModelConfig) { cls -> val fn = cls.members(NodeKind.Function).single() val param = fn.detail(NodeKind.Parameter) assertEquals("vararg", param.details(NodeKind.Modifier).first().name) @@ -128,7 +130,7 @@ public class JavaTest { } @Test fun fields() { - verifyJavaPackageMember("testdata/java/field.java") { cls -> + verifyJavaPackageMember("testdata/java/field.java", defaultModelConfig) { cls -> val i = cls.members(NodeKind.Property).single { it.name == "i" } assertEquals("Int", i.detail(NodeKind.Type).name) assertTrue("var" in i.details(NodeKind.Modifier).map { it.name }) @@ -141,7 +143,7 @@ public class JavaTest { } @Test fun staticMethod() { - verifyJavaPackageMember("testdata/java/staticMethod.java") { cls -> + verifyJavaPackageMember("testdata/java/staticMethod.java", defaultModelConfig) { cls -> val m = cls.members(NodeKind.Function).single { it.name == "foo" } assertTrue("static" in m.details(NodeKind.Modifier).map { it.name }) } @@ -154,13 +156,13 @@ public class JavaTest { * Proposed tag `@exclude` for it, but not supported yet */ @Ignore("@suppress not supported in Java!") @Test fun suppressTag() { - verifyJavaPackageMember("testdata/java/suppressTag.java") { cls -> + verifyJavaPackageMember("testdata/java/suppressTag.java", defaultModelConfig) { cls -> assertEquals(1, cls.members(NodeKind.Function).size) } } @Test fun annotatedAnnotation() { - verifyJavaPackageMember("testdata/java/annotatedAnnotation.java") { cls -> + verifyJavaPackageMember("testdata/java/annotatedAnnotation.java", defaultModelConfig) { cls -> assertEquals(1, cls.annotations.size) with(cls.annotations[0]) { assertEquals(1, details.count()) @@ -177,29 +179,29 @@ public class JavaTest { } @Test fun deprecation() { - verifyJavaPackageMember("testdata/java/deprecation.java") { cls -> + verifyJavaPackageMember("testdata/java/deprecation.java", defaultModelConfig) { cls -> val fn = cls.members(NodeKind.Function).single() assertEquals("This should no longer be used", fn.deprecation!!.content.toTestString()) } } @Test fun javaLangObject() { - verifyJavaPackageMember("testdata/java/javaLangObject.java") { cls -> + verifyJavaPackageMember("testdata/java/javaLangObject.java", defaultModelConfig) { cls -> val fn = cls.members(NodeKind.Function).single() assertEquals("Any", fn.detail(NodeKind.Type).name) } } @Test fun enumValues() { - verifyJavaPackageMember("testdata/java/enumValues.java") { cls -> + verifyJavaPackageMember("testdata/java/enumValues.java", defaultModelConfig) { cls -> val superTypes = cls.details(NodeKind.Supertype) - assertEquals(0, superTypes.size) + assertEquals(1, superTypes.size) assertEquals(1, cls.members(NodeKind.EnumItem).size) } } @Test fun inheritorLinks() { - verifyJavaPackageMember("testdata/java/InheritorLinks.java") { cls -> + verifyJavaPackageMember("testdata/java/InheritorLinks.java", defaultModelConfig) { cls -> val fooClass = cls.members.single { it.name == "Foo" } val inheritors = fooClass.references(RefKind.Inheritor) assertEquals(1, inheritors.size) diff --git a/core/src/test/kotlin/model/KotlinAsJavaTest.kt b/core/src/test/kotlin/model/KotlinAsJavaTest.kt index d24d8bdd..f6f0aa20 100644 --- a/core/src/test/kotlin/model/KotlinAsJavaTest.kt +++ b/core/src/test/kotlin/model/KotlinAsJavaTest.kt @@ -2,6 +2,7 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.DocumentationModule import org.jetbrains.dokka.NodeKind +import org.jetbrains.dokka.Platform import org.junit.Test import org.junit.Assert.assertEquals @@ -30,11 +31,15 @@ class KotlinAsJavaTest { } fun verifyModelAsJava(source: String, - withJdk: Boolean = false, - withKotlinRuntime: Boolean = false, + modelConfig: ModelConfig = ModelConfig(), verifier: (DocumentationModule) -> Unit) { - verifyModel(source, - withJdk = withJdk, withKotlinRuntime = withKotlinRuntime, + checkSourceExistsAndVerifyModel( + source, + modelConfig = ModelConfig( + withJdk = modelConfig.withJdk, + withKotlinRuntime = modelConfig.withKotlinRuntime, format = "html-as-java", - verifier = verifier) + analysisPlatform = Platform.jvm), + verifier = verifier + ) } diff --git a/core/src/test/kotlin/model/LinkTest.kt b/core/src/test/kotlin/model/LinkTest.kt index 6b72525f..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() { - verifyModel("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() { - verifyModel("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() { - verifyModel("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() { - verifyModel("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() { - verifyModel("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() { - verifyModel("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 052f0d28..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() { - verifyModel("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() { - verifyModel("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() { - verifyModel("testdata/packages/dottedNamePackage.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/packages/dottedNamePackage.kt", defaultModelConfig) { model -> with(model.members.single()) { assertEquals(NodeKind.Package, kind) assertEquals("dot.name", name) @@ -48,8 +47,15 @@ public class PackageTest { } @Test fun multipleFiles() { - verifyModel(KotlinSourceRoot("testdata/packages/dottedNamePackage.kt"), - KotlinSourceRoot("testdata/packages/simpleNamePackage.kt")) { model -> + verifyModel( + ModelConfig( + roots = arrayOf( + KotlinSourceRoot("testdata/packages/dottedNamePackage.kt"), + KotlinSourceRoot("testdata/packages/simpleNamePackage.kt") + ), + analysisPlatform = analysisPlatform + ) + ) { model -> assertEquals(2, model.members.count()) with(model.members.single { it.name == "simple" }) { assertEquals(NodeKind.Package, kind) @@ -70,8 +76,15 @@ public class PackageTest { } @Test fun multipleFilesSamePackage() { - verifyModel(KotlinSourceRoot("testdata/packages/simpleNamePackage.kt"), - KotlinSourceRoot("testdata/packages/simpleNamePackage2.kt")) { model -> + verifyModel( + ModelConfig( + roots = arrayOf( + KotlinSourceRoot("testdata/packages/simpleNamePackage.kt"), + KotlinSourceRoot("testdata/packages/simpleNamePackage2.kt") + ), + analysisPlatform = analysisPlatform + ) + ) { model -> assertEquals(1, model.members.count()) with(model.members.elementAt(0)) { assertEquals(NodeKind.Package, kind) @@ -85,7 +98,12 @@ public class PackageTest { } @Test fun classAtPackageLevel() { - verifyModel(KotlinSourceRoot("testdata/packages/classInPackage.kt")) { model -> + verifyModel( + ModelConfig( + roots = arrayOf(KotlinSourceRoot("testdata/packages/classInPackage.kt")), + analysisPlatform = analysisPlatform + ) + ) { model -> assertEquals(1, model.members.count()) with(model.members.elementAt(0)) { assertEquals(NodeKind.Package, kind) @@ -99,8 +117,15 @@ public class PackageTest { } @Test fun suppressAtPackageLevel() { - verifyModel(KotlinSourceRoot("testdata/packages/classInPackage.kt"), - perPackageOptions = listOf(PackageOptionsImpl(prefix = "simple.name", suppress = true))) { model -> + verifyModel( + ModelConfig( + roots = arrayOf(KotlinSourceRoot("testdata/packages/classInPackage.kt")), + perPackageOptions = listOf( + PackageOptionsImpl(prefix = "simple.name", suppress = true) + ), + analysisPlatform = analysisPlatform + ) + ) { model -> assertEquals(1, model.members.count()) with(model.members.elementAt(0)) { assertEquals(NodeKind.Package, kind) @@ -113,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 index 0ee0e0f5..a41ab5a3 100644 --- a/core/src/test/kotlin/model/PropertyTest.kt +++ b/core/src/test/kotlin/model/PropertyTest.kt @@ -1,15 +1,16 @@ package org.jetbrains.dokka.tests -import org.jetbrains.dokka.Content -import org.jetbrains.dokka.NodeKind -import org.jetbrains.dokka.RefKind +import org.jetbrains.dokka.* +import org.junit.Assert import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue import org.junit.Test -class PropertyTest { +abstract class BasePropertyTest(val analysisPlatform: Platform) { + + protected val defaultModelConfig = ModelConfig(analysisPlatform = analysisPlatform) @Test fun valueProperty() { - verifyModel("testdata/properties/valueProperty.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/properties/valueProperty.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("property", name) assertEquals(NodeKind.Property, kind) @@ -22,7 +23,7 @@ class PropertyTest { } @Test fun variableProperty() { - verifyModel("testdata/properties/variableProperty.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/properties/variableProperty.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("property", name) assertEquals(NodeKind.Property, kind) @@ -35,7 +36,7 @@ class PropertyTest { } @Test fun valuePropertyWithGetter() { - verifyModel("testdata/properties/valuePropertyWithGetter.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/properties/valuePropertyWithGetter.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("property", name) assertEquals(NodeKind.Property, kind) @@ -48,7 +49,7 @@ class PropertyTest { } @Test fun variablePropertyWithAccessors() { - verifyModel("testdata/properties/variablePropertyWithAccessors.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/properties/variablePropertyWithAccessors.kt", defaultModelConfig) { model -> with(model.members.single().members.single()) { assertEquals("property", name) assertEquals(NodeKind.Property, kind) @@ -64,21 +65,11 @@ class PropertyTest { } } - @Test fun annotatedProperty() { - verifyModel("testdata/properties/annotatedProperty.kt", withKotlinRuntime = true) { model -> - with(model.members.single().members.single()) { - assertEquals(1, annotations.count()) - with(annotations[0]) { - assertEquals("Volatile", name) - assertEquals(Content.Empty, content) - assertEquals(NodeKind.Annotation, kind) - } - } - } - } - @Test fun propertyWithReceiver() { - verifyModel("testdata/properties/propertyWithReceiver.kt") { model -> + checkSourceExistsAndVerifyModel( + "testdata/properties/propertyWithReceiver.kt", + defaultModelConfig + ) { model -> with(model.members.single().members.single()) { assertEquals("kotlin.String", name) assertEquals(NodeKind.ExternalClass, kind) @@ -91,7 +82,7 @@ class PropertyTest { } @Test fun propertyOverride() { - verifyModel("testdata/properties/propertyOverride.kt") { model -> + 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 @@ -102,10 +93,37 @@ class PropertyTest { } @Test fun sinceKotlin() { - verifyModel("testdata/properties/sinceKotlin.kt") { model -> + 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 diff --git a/core/src/test/kotlin/model/TypeAliasTest.kt b/core/src/test/kotlin/model/TypeAliasTest.kt index c653ac83..a011b44f 100644 --- a/core/src/test/kotlin/model/TypeAliasTest.kt +++ b/core/src/test/kotlin/model/TypeAliasTest.kt @@ -8,7 +8,7 @@ import org.junit.Test class TypeAliasTest { @Test fun testSimple() { - verifyModel("testdata/typealias/simple.kt") { + checkSourceExistsAndVerifyModel("testdata/typealias/simple.kt") { val pkg = it.members.single() with(pkg.member(NodeKind.TypeAlias)) { assertEquals(Content.Empty, content) @@ -20,7 +20,7 @@ class TypeAliasTest { @Test fun testInheritanceFromTypeAlias() { - verifyModel("testdata/typealias/inheritanceFromTypeAlias.kt") { + checkSourceExistsAndVerifyModel("testdata/typealias/inheritanceFromTypeAlias.kt") { val pkg = it.members.single() with(pkg.member(NodeKind.TypeAlias)) { assertEquals(Content.Empty, content) @@ -36,7 +36,7 @@ class TypeAliasTest { @Test fun testChain() { - verifyModel("testdata/typealias/chain.kt") { + checkSourceExistsAndVerifyModel("testdata/typealias/chain.kt") { val pkg = it.members.single() with(pkg.members(NodeKind.TypeAlias).find { it.name == "B" }!!) { assertEquals(Content.Empty, content) @@ -51,7 +51,7 @@ class TypeAliasTest { @Test fun testDocumented() { - verifyModel("testdata/typealias/documented.kt") { + checkSourceExistsAndVerifyModel("testdata/typealias/documented.kt") { val pkg = it.members.single() with(pkg.member(NodeKind.TypeAlias)) { assertEquals("Just typealias", content.summary.toTestString()) @@ -61,7 +61,7 @@ class TypeAliasTest { @Test fun testDeprecated() { - verifyModel("testdata/typealias/deprecated.kt") { + checkSourceExistsAndVerifyModel("testdata/typealias/deprecated.kt") { val pkg = it.members.single() with(pkg.member(NodeKind.TypeAlias)) { assertEquals(Content.Empty, content) @@ -73,7 +73,7 @@ class TypeAliasTest { @Test fun testGeneric() { - verifyModel("testdata/typealias/generic.kt") { + checkSourceExistsAndVerifyModel("testdata/typealias/generic.kt") { val pkg = it.members.single() with(pkg.members(NodeKind.TypeAlias).find { it.name == "B" }!!) { assertEquals("Any", detail(NodeKind.TypeAliasUnderlyingType).detail(NodeKind.Type).name) @@ -88,7 +88,7 @@ class TypeAliasTest { @Test fun testFunctional() { - verifyModel("testdata/typealias/functional.kt") { + checkSourceExistsAndVerifyModel("testdata/typealias/functional.kt") { val pkg = it.members.single() with(pkg.member(NodeKind.TypeAlias)) { assertEquals("Function1", detail(NodeKind.TypeAliasUnderlyingType).name) @@ -105,7 +105,7 @@ class TypeAliasTest { @Test fun testAsTypeBoundWithVariance() { - verifyModel("testdata/typealias/asTypeBoundWithVariance.kt") { + checkSourceExistsAndVerifyModel("testdata/typealias/asTypeBoundWithVariance.kt") { val pkg = it.members.single() with(pkg.members(NodeKind.Class).find { it.name == "C" }!!) { val tParam = detail(NodeKind.TypeParameter) @@ -123,7 +123,7 @@ class TypeAliasTest { @Test fun sinceKotlin() { - verifyModel("testdata/typealias/sinceKotlin.kt") { model -> + checkSourceExistsAndVerifyModel("testdata/typealias/sinceKotlin.kt") { model -> with(model.members.single().members.single()) { assertEquals(listOf("Kotlin 1.1"), platforms) } |