diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-11-28 15:58:10 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-11-28 15:58:10 +0000 |
commit | ecf8061396ac2d1bb0f75c37d48caf53c3be1ce4 (patch) | |
tree | 4058cd853f36166d424eee7e69e95ad3125d1189 /core/src/test/kotlin/format | |
parent | 7f79c3b49be99f3d45d099a30b78faa6d96e93b2 (diff) | |
parent | 77665b03848c6574ff3e40ec875c347d5eb41a8f (diff) | |
download | dokka-androidx-versionedparcelable-release.tar.gz |
Snap for 11149604 from 77665b03848c6574ff3e40ec875c347d5eb41a8f to androidx-versionedparcelable-releaseandroidx-versionedparcelable-release
Change-Id: Ia11dc58bb589d4d20dd8983fae63265d878b9752
Diffstat (limited to 'core/src/test/kotlin/format')
-rw-r--r-- | core/src/test/kotlin/format/DacFormatTest.kt | 58 | ||||
-rw-r--r-- | core/src/test/kotlin/format/DacFormatTestCase.kt | 90 | ||||
-rw-r--r-- | core/src/test/kotlin/format/FileGeneratorTestCase.kt | 35 | ||||
-rw-r--r-- | core/src/test/kotlin/format/GFMFormatTest.kt | 28 | ||||
-rw-r--r-- | core/src/test/kotlin/format/HtmlFormatTest.kt | 182 | ||||
-rw-r--r-- | core/src/test/kotlin/format/JavaLayoutHtmlFormatTest.kt | 114 | ||||
-rw-r--r-- | core/src/test/kotlin/format/JavaLayoutHtmlFormatTestCase.kt | 117 | ||||
-rw-r--r-- | core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt | 74 | ||||
-rw-r--r-- | core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt | 85 | ||||
-rw-r--r-- | core/src/test/kotlin/format/KotlinWebSiteRunnableSamplesFormatTest.kt | 39 | ||||
-rw-r--r-- | core/src/test/kotlin/format/MarkdownFormatTest.kt | 547 | ||||
-rw-r--r-- | core/src/test/kotlin/format/PackageDocsTest.kt | 92 |
12 files changed, 1461 insertions, 0 deletions
diff --git a/core/src/test/kotlin/format/DacFormatTest.kt b/core/src/test/kotlin/format/DacFormatTest.kt new file mode 100644 index 000000000..5d8babc3d --- /dev/null +++ b/core/src/test/kotlin/format/DacFormatTest.kt @@ -0,0 +1,58 @@ +package org.jetbrains.dokka.tests.format + +import org.jetbrains.dokka.Formats.DacAsJavaFormatDescriptor +import org.jetbrains.dokka.Formats.DacFormatDescriptor +import org.jetbrains.dokka.Formats.JavaLayoutHtmlFormatDescriptorBase +import org.junit.Test + +class DacFormatTest: DacFormatTestCase() { + val dacFormatDescriptor = DacFormatDescriptor() + val dacAsJavaFormatDescriptor = DacAsJavaFormatDescriptor() + val dacFormat = "dac" + val dacAsJavaFormat = "dac-as-java" + + private fun verifyBothFormats(directory: String) { + verifyDirectory(directory, dacFormatDescriptor, dacFormat) + verifyDirectory(directory, dacAsJavaFormatDescriptor, dacAsJavaFormat) + } + + @Test fun javaSeeTag() { + verifyBothFormats("javaSeeTag") + } + + @Test fun javaConstructor() { + verifyBothFormats("javaConstructor") + } + + @Test + fun javaSeeTagAsJava() { + verifyBothFormats("javaSeeTag") + } + + @Test + fun javaConstructorAsJava() { + verifyBothFormats("javaConstructor") + } + + @Test + fun javaDefaultConstructor() { + verifyBothFormats("javaDefaultConstructor") + } + + @Test + fun javaInheritedMethods() { + verifyBothFormats("inheritedMethods") + } + + @Test fun javaMethodVisibilities() { + verifyBothFormats("javaMethodVisibilities") + } + + @Test fun javaClassLinks() { + verifyBothFormats("javaClassLinks") + } + + @Test fun deprecation() { + verifyBothFormats("deprecation") + } +}
\ No newline at end of file diff --git a/core/src/test/kotlin/format/DacFormatTestCase.kt b/core/src/test/kotlin/format/DacFormatTestCase.kt new file mode 100644 index 000000000..922b58097 --- /dev/null +++ b/core/src/test/kotlin/format/DacFormatTestCase.kt @@ -0,0 +1,90 @@ +package org.jetbrains.dokka.tests.format + +import com.google.inject.Guice +import com.google.inject.Injector +import com.google.inject.Module +import com.google.inject.name.Names +import org.jetbrains.dokka.DocumentationOptions +import org.jetbrains.dokka.DokkaLogger +import org.jetbrains.dokka.Formats.JavaLayoutHtmlFormatDescriptorBase +import org.jetbrains.dokka.Formats.JavaLayoutHtmlFormatGenerator +import org.jetbrains.dokka.Generator +import org.jetbrains.dokka.Utilities.bind +import org.jetbrains.dokka.tests.assertEqualsIgnoringSeparators +import org.jetbrains.dokka.tests.verifyModel +import org.jetbrains.kotlin.cli.common.config.KotlinSourceRoot +import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot +import org.junit.Rule +import org.junit.rules.TemporaryFolder +import java.io.File +import java.net.URI + +abstract class DacFormatTestCase { + @get:Rule + var folder = TemporaryFolder() + + protected fun verifyDirectory(directory: String, formatDescriptor: JavaLayoutHtmlFormatDescriptorBase, dokkaFormat: String) { + val injector: Injector by lazy { + val options = + DocumentationOptions( + folder.toString(), + dokkaFormat, + apiVersion = null, + languageVersion = null, + generateClassIndexPage = false, + generatePackageIndexPage = false, + noStdlibLink = false, + noJdkLink = false, + collectInheritedExtensionsFromLibraries = true + ) + + Guice.createInjector(Module { binder -> + + binder.bind<Boolean>().annotatedWith(Names.named("generateClassIndex")).toInstance(false) + binder.bind<Boolean>().annotatedWith(Names.named("generatePackageIndex")).toInstance(false) + + binder.bind<String>().annotatedWith(Names.named("dacRoot")).toInstance("") + binder.bind<String>().annotatedWith(Names.named("outlineRoot")).toInstance("") + binder.bind<File>().annotatedWith(Names.named("outputDir")).toInstance(folder.root) + + binder.bind<DocumentationOptions>().toProvider { options } + binder.bind<DokkaLogger>().toInstance(object : DokkaLogger { + override fun info(message: String) { + println(message) + } + + override fun warn(message: String) { + println("WARN: $message") + } + + override fun error(message: String) { + println("ERROR: $message") + } + }) + + formatDescriptor.configureOutput(binder) + }) + } + + + val directoryFile = File("testdata/format/dac/$directory") + verifyModel( + JavaSourceRoot(directoryFile, null), KotlinSourceRoot(directoryFile.path, false), + format = dokkaFormat + ) { documentationModule -> + val nodes = documentationModule.members.single().members + with(injector.getInstance(Generator::class.java)) { + this as JavaLayoutHtmlFormatGenerator + buildPages(listOf(documentationModule)) + val byLocations = nodes.groupBy { mainUri(it) } + val tmpFolder = folder.root.toURI().resolve("${documentationModule.name}/") + byLocations.forEach { (loc, node) -> + val output = StringBuilder() + output.append(tmpFolder.resolve(URI("/").relativize(loc)).toURL().readText()) + val expectedFile = File(File(directoryFile, dokkaFormat), "${node.first().name}.html") + assertEqualsIgnoringSeparators(expectedFile, output.toString()) + } + } + } + } +}
\ No newline at end of file diff --git a/core/src/test/kotlin/format/FileGeneratorTestCase.kt b/core/src/test/kotlin/format/FileGeneratorTestCase.kt new file mode 100644 index 000000000..ef9e815d2 --- /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 new file mode 100644 index 000000000..b90ab2bf2 --- /dev/null +++ b/core/src/test/kotlin/format/GFMFormatTest.kt @@ -0,0 +1,28 @@ +package org.jetbrains.dokka.tests + +import org.jetbrains.dokka.GFMFormatService +import org.jetbrains.dokka.KotlinLanguageService +import org.junit.Test + +class GFMFormatTest : FileGeneratorTestCase() { + override val formatService = GFMFormatService(fileGenerator, KotlinLanguageService(), listOf()) + + @Test + fun sample() { + verifyGFMNodeByName("sample", "Foo") + } + + @Test + fun listInTableCell() { + verifyGFMNodeByName("listInTableCell", "Foo") + } + + private fun verifyGFMNodeByName(fileName: String, name: String) { + verifyOutput("testdata/format/gfm/$fileName.kt", ".md") { model, output -> + buildPagesAndReadInto( + model.members.single().members.filter { it.name == name }, + output + ) + } + } +} diff --git a/core/src/test/kotlin/format/HtmlFormatTest.kt b/core/src/test/kotlin/format/HtmlFormatTest.kt new file mode 100644 index 000000000..01e9b3c5f --- /dev/null +++ b/core/src/test/kotlin/format/HtmlFormatTest.kt @@ -0,0 +1,182 @@ +package org.jetbrains.dokka.tests + +import org.jetbrains.dokka.* +import org.jetbrains.kotlin.cli.common.config.KotlinSourceRoot +import org.jetbrains.kotlin.cli.jvm.config.JavaSourceRoot +import org.junit.Test +import java.io.File + +// TODO: add tests back +class HtmlFormatTest: FileGeneratorTestCase() { + override val formatService = HtmlFormatService(fileGenerator, KotlinLanguageService(), HtmlTemplateService.default(), listOf()) + + @Test fun classWithCompanionObject() { + verifyHtmlNode("classWithCompanionObject") + } + + @Test fun htmlEscaping() { + verifyHtmlNode("htmlEscaping") + } + + @Test fun overloads() { + verifyHtmlNodes("overloads") { model -> model.members } + } + + @Test fun overloadsWithDescription() { + verifyHtmlNode("overloadsWithDescription") + } + + @Test fun overloadsWithDifferentDescriptions() { + verifyHtmlNode("overloadsWithDifferentDescriptions") + } + + @Test fun deprecated() { + verifyOutput("testdata/format/deprecated.kt", ".package.html") { model, output -> + buildPagesAndReadInto(model.members, output) + } + verifyOutput("testdata/format/deprecated.kt", ".class.html") { model, output -> + buildPagesAndReadInto(model.members.single().members, output) + } + } + + @Test fun brokenLink() { + verifyHtmlNode("brokenLink") + } + + @Test fun codeSpan() { + verifyHtmlNode("codeSpan") + } + + @Test fun parenthesis() { + verifyHtmlNode("parenthesis") + } + + @Test fun bracket() { + verifyHtmlNode("bracket") + } + + @Test fun see() { + verifyHtmlNode("see") + } + + @Test fun tripleBackticks() { + verifyHtmlNode("tripleBackticks") + } + + @Test fun typeLink() { + verifyHtmlNodes("typeLink") { 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" } + } + } + + @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" } + } + } + + @Test fun crossLanguageKotlinExtendsJava() { + verifyOutput(arrayOf( + KotlinSourceRoot("testdata/format/crossLanguage/kotlinExtendsJava/Bar.kt", false), + JavaSourceRoot(File("testdata/format/crossLanguage/kotlinExtendsJava"), null)), + ".html") { model, output -> + buildPagesAndReadInto( + model.members.single().members.filter { it.name == "Bar" }, + output + ) + } + } + + @Test fun orderedList() { + verifyHtmlNodes("orderedList") { model -> model.members.single().members.filter { it.name == "Bar" } } + } + + @Test fun linkWithLabel() { + verifyHtmlNodes("linkWithLabel") { model -> model.members.single().members.filter { it.name == "Bar" } } + } + + @Test fun entity() { + verifyHtmlNodes("entity") { model -> model.members.single().members.filter { it.name == "Bar" } } + } + + @Test fun uninterpretedEmphasisCharacters() { + verifyHtmlNode("uninterpretedEmphasisCharacters") + } + + @Test fun markdownInLinks() { + verifyHtmlNode("markdownInLinks") + } + + @Test fun returnWithLink() { + verifyHtmlNode("returnWithLink") + } + + @Test fun linkWithStarProjection() { + verifyHtmlNode("linkWithStarProjection", withKotlinRuntime = true) + } + + @Test fun functionalTypeWithNamedParameters() { + verifyHtmlNode("functionalTypeWithNamedParameters") + } + + @Test fun sinceKotlin() { + verifyHtmlNode("sinceKotlin") + } + + @Test fun blankLineInsideCodeBlock() { + verifyHtmlNode("blankLineInsideCodeBlock") + } + + @Test fun indentedCodeBlock() { + verifyHtmlNode("indentedCodeBlock") + } + + private fun verifyHtmlNode(fileName: String, withKotlinRuntime: Boolean = false) { + verifyHtmlNodes(fileName, withKotlinRuntime) { model -> model.members.single().members } + } + + private fun verifyHtmlNodes(fileName: String, + withKotlinRuntime: Boolean = false, + nodeFilter: (DocumentationModule) -> List<DocumentationNode>) { + verifyOutput("testdata/format/$fileName.kt", ".html", withKotlinRuntime = withKotlinRuntime) { model, output -> + buildPagesAndReadInto(nodeFilter(model), output) + } + } + + private fun verifyJavaHtmlNode(fileName: String, withKotlinRuntime: Boolean = false) { + verifyJavaHtmlNodes(fileName, withKotlinRuntime) { model -> model.members.single().members } + } + + private fun verifyJavaHtmlNodes(fileName: String, + withKotlinRuntime: Boolean = false, + nodeFilter: (DocumentationModule) -> List<DocumentationNode>) { + verifyJavaOutput("testdata/format/$fileName.java", ".html", withKotlinRuntime = withKotlinRuntime) { model, output -> + buildPagesAndReadInto(nodeFilter(model), output) + } + } +} + diff --git a/core/src/test/kotlin/format/JavaLayoutHtmlFormatTest.kt b/core/src/test/kotlin/format/JavaLayoutHtmlFormatTest.kt new file mode 100644 index 000000000..59746b10f --- /dev/null +++ b/core/src/test/kotlin/format/JavaLayoutHtmlFormatTest.kt @@ -0,0 +1,114 @@ +package org.jetbrains.dokka.tests + +import org.jetbrains.dokka.* +import org.jetbrains.dokka.Formats.JavaLayoutHtmlFormatDescriptor +import org.junit.Test +import java.io.File +import java.net.URL + +class JavaLayoutHtmlFormatTest : JavaLayoutHtmlFormatTestCase() { + override val formatDescriptor = JavaLayoutHtmlFormatDescriptor() + +// @Test +// fun simple() { +// verifyNode("simple.kt") +// } +// +//// @Test +//// fun topLevel() { +//// verifyPackageNode("topLevel.kt") +//// } +// +// @Test +// fun codeBlocks() { +// verifyNode("codeBlocks.kt") { model -> +// listOf(model.members.single().members.single { it.name == "foo" }) +// } +// } +// +// @Test +// fun const() { +// verifyPackageNode("const.kt", noStdlibLink = true) +// verifyNode("const.kt", noStdlibLink = true) { model -> +// model.members.single().members.filter { it.kind in NodeKind.classLike } +// } +// } +// +// @Test +// fun externalClassExtension() { +// verifyPackageNode("externalClassExtension.kt") +// } +// +// @Test +// fun unresolvedExternalClass() { +// verifyNode("unresolvedExternalClass.kt", noStdlibLink = true) { model -> +// listOf(model.members.single().members.single { it.name == "MyException" }) +// } +// } +// +// @Test +// fun genericExtension() { +// verifyNode("genericExtension.kt", noStdlibLink = true) { model -> +// model.members.single().members(NodeKind.Class) +// } +// } +// +// +// @Test +// fun sections() { +// verifyNode("sections.kt", noStdlibLink = true) { model -> +// model.members.single().members.filter { it.name == "sectionsTest" } +// } +// } +// +// @Test +// fun constJava() { +// verifyNode("ConstJava.java", noStdlibLink = true) +// } +// +// @Test +// fun inboundLinksInKotlinMode() { +// val root = "./testdata/format/java-layout-html" +// +// val options = DocumentationOptions( +// "", +// "java-layout-html", +// sourceLinks = listOf(), +// generateClassIndexPage = false, +// generatePackageIndexPage = false, +// noStdlibLink = true, +// apiVersion = null, +// languageVersion = null, +// perPackageOptions = listOf(PackageOptionsImpl("foo", suppress = true)), +// externalDocumentationLinks = +// listOf( +// DokkaConfiguration.ExternalDocumentationLink.Builder( +// URL("file:///"), +// File(root, "inboundLinksTestPackageList").toURI().toURL() +// ).build() +// ) +// ) +// +// +// val sourcePath = "$root/inboundLinksInKotlinMode.kt" +// val documentation = DocumentationModule("test") +// +// appendDocumentation( +// documentation, +// contentRootFromPath(sourcePath), +// contentRootFromPath("$root/inboundLinksInKotlinMode.Dep.kt"), +// withJdk = false, +// withKotlinRuntime = false, +// options = options +// ) +// documentation.prepareForGeneration(options) +// +// verifyModelOutput(documentation, ".html", sourcePath) { model, output -> +// buildPagesAndReadInto( +// model, +// model.members.single { it.name == "bar" }.members, +// output +// ) +// } +// } +}
\ No newline at end of file diff --git a/core/src/test/kotlin/format/JavaLayoutHtmlFormatTestCase.kt b/core/src/test/kotlin/format/JavaLayoutHtmlFormatTestCase.kt new file mode 100644 index 000000000..620f10dda --- /dev/null +++ b/core/src/test/kotlin/format/JavaLayoutHtmlFormatTestCase.kt @@ -0,0 +1,117 @@ +package org.jetbrains.dokka.tests + +import com.google.inject.Guice +import com.google.inject.Injector +import com.google.inject.Module +import com.google.inject.name.Names +import org.jetbrains.dokka.DocumentationNode +import org.jetbrains.dokka.DocumentationOptions +import org.jetbrains.dokka.DokkaLogger +import org.jetbrains.dokka.Formats.JavaLayoutHtmlFormatDescriptorBase +import org.jetbrains.dokka.Formats.JavaLayoutHtmlFormatGenerator +import org.jetbrains.dokka.Generator +import org.jetbrains.dokka.Utilities.bind +import org.junit.Rule +import org.junit.rules.TemporaryFolder +import java.io.File +import java.net.URI + +abstract class JavaLayoutHtmlFormatTestCase { + + abstract val formatDescriptor: JavaLayoutHtmlFormatDescriptorBase + + @get:Rule + var folder = TemporaryFolder() + + var options = + DocumentationOptions( + "", + "java-layout-html", + apiVersion = null, + languageVersion = null, + generateClassIndexPage = false, + generatePackageIndexPage = false, + noStdlibLink = false, + noJdkLink = false, + collectInheritedExtensionsFromLibraries = true + ) + + val injector: Injector by lazy { + Guice.createInjector(Module { binder -> + binder.bind<File>().annotatedWith(Names.named("outputDir")).toInstance(folder.apply { create() }.root) + + binder.bind<DocumentationOptions>().toProvider { options } + binder.bind<DokkaLogger>().toInstance(object : DokkaLogger { + override fun info(message: String) { + println(message) + } + + override fun warn(message: String) { + println("WARN: $message") + } + + override fun error(message: String) { + println("ERROR: $message") + } + + }) + + formatDescriptor.configureOutput(binder) + }) + } + + + protected fun buildPagesAndReadInto(model: DocumentationNode, nodes: List<DocumentationNode>, sb: StringBuilder) = + with(injector.getInstance(Generator::class.java)) { + this as JavaLayoutHtmlFormatGenerator + buildPages(listOf(model)) + val byLocations = nodes.groupBy { mainUri(it) } + byLocations.forEach { (loc, _) -> + sb.appendln("<!-- File: $loc -->") + sb.append(folder.root.toURI().resolve(URI("/").relativize(loc)).toURL().readText()) + } + } + + + protected fun verifyNode( + fileName: String, + noStdlibLink: Boolean = false, + fileExtension: String = ".html", + select: (model: DocumentationNode) -> List<DocumentationNode> + ) { + verifyOutput( + "testdata/format/java-layout-html/$fileName", + fileExtension, + format = "java-layout-html", + withKotlinRuntime = true, + noStdlibLink = noStdlibLink, + collectInheritedExtensionsFromLibraries = true + ) { model, output -> + buildPagesAndReadInto( + model, + select(model), + output + ) + } + } + + protected fun verifyNode(fileName: String, noStdlibLink: Boolean = false) { + verifyNode(fileName, noStdlibLink) { model -> listOf(model.members.single().members.single()) } + } + + protected fun verifyPackageNode(fileName: String, noStdlibLink: Boolean = false) { + verifyOutput( + "testdata/format/java-layout-html/$fileName", + ".package-summary.html", + format = "java-layout-html", + withKotlinRuntime = true, + noStdlibLink = noStdlibLink + ) { model, output -> + buildPagesAndReadInto( + model, + listOf(model.members.single()), + output + ) + } + } +}
\ No newline at end of file diff --git a/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt new file mode 100644 index 000000000..01ac58da4 --- /dev/null +++ b/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt @@ -0,0 +1,74 @@ +package org.jetbrains.dokka.tests + +import org.jetbrains.dokka.* +import org.junit.Before +import org.junit.Ignore +import org.junit.Test + +@Ignore +class KotlinWebSiteFormatTest: FileGeneratorTestCase() { + override val formatService = KotlinWebsiteFormatService(fileGenerator, KotlinLanguageService(), listOf(), DokkaConsoleLogger) + + @Test fun sample() { + verifyKWSNodeByName("sample", "foo") + } + + @Test fun returnTag() { + verifyKWSNodeByName("returnTag", "indexOf") + } + + @Test fun overloadGroup() { + verifyKWSNodeByName("overloadGroup", "magic") + } + + @Test fun dataTags() { + val module = buildMultiplePlatforms("dataTags") + verifyMultiplatformPackage(module, "dataTags") + } + + @Test fun dataTagsInGroupNode() { + val path = "dataTagsInGroupNode" + val module = buildMultiplePlatforms(path) + verifyModelOutput(module, ".md", "testdata/format/website/$path/multiplatform.kt") { model, output -> + 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 -> + 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", + generateClassIndexPage = false, + generatePackageIndexPage = false, + 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) + return module + } + + private fun verifyMultiplatformPackage(module: DocumentationModule, path: String) { + verifyModelOutput(module, ".package.md", "testdata/format/website/$path/multiplatform.kt") { model, output -> + buildPagesAndReadInto(model.members, output) + } + } + +} diff --git a/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt new file mode 100644 index 000000000..63d7d5766 --- /dev/null +++ b/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt @@ -0,0 +1,85 @@ +package org.jetbrains.dokka.tests + +import org.jetbrains.dokka.* +import org.junit.Before +import org.junit.Test + +class KotlinWebSiteHtmlFormatTest: FileGeneratorTestCase() { + override val formatService = KotlinWebsiteHtmlFormatService(fileGenerator, KotlinLanguageService(), listOf(), EmptyHtmlTemplateService) + + @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") + } + + @Test fun returnTag() { + verifyKWSNodeByName("returnTag", "indexOf") + } + + @Test fun overloadGroup() { + verifyKWSNodeByName("overloadGroup", "magic") + } + + @Test fun dataTags() { + val module = buildMultiplePlatforms("dataTags") + verifyMultiplatformPackage(module, "dataTags") + } + + @Test fun dataTagsInGroupNode() { + val path = "dataTagsInGroupNode" + val module = buildMultiplePlatforms(path) + verifyModelOutput(module, ".html", "testdata/format/website-html/$path/multiplatform.kt") { model, output -> + 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 -> + 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", + generateClassIndexPage = false, + generatePackageIndexPage = false, + 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) + return module + } + + private fun verifyMultiplatformPackage(module: DocumentationModule, path: String) { + verifyModelOutput(module, ".package.html", "testdata/format/website-html/$path/multiplatform.kt") { model, output -> + buildPagesAndReadInto(model.members, output) + } + } + +} diff --git a/core/src/test/kotlin/format/KotlinWebSiteRunnableSamplesFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteRunnableSamplesFormatTest.kt new file mode 100644 index 000000000..453b1de85 --- /dev/null +++ b/core/src/test/kotlin/format/KotlinWebSiteRunnableSamplesFormatTest.kt @@ -0,0 +1,39 @@ +package org.jetbrains.dokka.tests + +import org.jetbrains.dokka.DokkaConsoleLogger +import org.jetbrains.dokka.KotlinLanguageService +import org.jetbrains.dokka.KotlinWebsiteRunnableSamplesFormatService +import org.junit.Ignore +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 }) +// } +// } +} diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt new file mode 100644 index 000000000..08d467995 --- /dev/null +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -0,0 +1,547 @@ +package org.jetbrains.dokka.tests + +import org.jetbrains.dokka.* +import org.junit.Before +import org.junit.Ignore +import org.junit.Test + +class MarkdownFormatTest: FileGeneratorTestCase() { + override val formatService = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf()) + + @Test fun emptyDescription() { + verifyMarkdownNode("emptyDescription") + } + + @Test fun classWithCompanionObject() { + verifyMarkdownNode("classWithCompanionObject") + } + + @Test fun annotations() { + verifyMarkdownNode("annotations") + } + + @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 -> + buildPagesAndReadInto(model.members, output) + } + verifyOutput("testdata/format/extensions.kt", ".class.md") { model, output -> + buildPagesAndReadInto(model.members.single().members, output) + } + } + + @Test fun enumClass() { + verifyOutput("testdata/format/enumClass.kt", ".md") { model, output -> + buildPagesAndReadInto(model.members.single().members, output) + } + verifyOutput("testdata/format/enumClass.kt", ".value.md") { model, output -> + val enumClassNode = model.members.single().members[0] + buildPagesAndReadInto( + enumClassNode.members.filter { it.name == "LOCAL_CONTINUE_AND_BREAK" }, + output + ) + } + } + + @Test fun varargsFunction() { + verifyMarkdownNode("varargsFunction") + } + + @Test fun overridingFunction() { + verifyMarkdownNodes("overridingFunction") { model-> + val classMembers = model.members.single().members.first { it.name == "D" }.members + classMembers.filter { it.name == "f" } + } + } + + @Test fun propertyVar() { + verifyMarkdownNode("propertyVar") + } + + @Test fun functionWithDefaultParameter() { + verifyMarkdownNode("functionWithDefaultParameter") + } + + @Test fun accessor() { + verifyMarkdownNodes("accessor") { model -> + model.members.single().members.first { it.name == "C" }.members.filter { it.name == "x" } + } + } + + @Test fun paramTag() { + verifyMarkdownNode("paramTag") + } + + @Test fun throwsTag() { + verifyMarkdownNode("throwsTag") + } + + @Test fun typeParameterBounds() { + verifyMarkdownNode("typeParameterBounds") + } + + @Test fun typeParameterVariance() { + verifyMarkdownNode("typeParameterVariance") + } + + @Test fun typeProjectionVariance() { + verifyMarkdownNode("typeProjectionVariance") + } + + @Test + fun javadocCodeMultiline() { + verifyJavaMarkdownNode("javadocCodeMultiline") + } + + // TODO: FIXME + @Ignore + @Test + fun javadocHtml() { + verifyJavaMarkdownNode("javadocHtml") + } + + // TODO: FIXME + @Ignore + @Test + fun javaCodeLiteralTags() { + verifyJavaMarkdownNode("javaCodeLiteralTags") + } + + @Test + fun javaSample() { + verifyJavaMarkdownNode("javaSample") + } + + // TODO: FIXME + @Ignore + @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" } + } + } + + @Test fun codeBlockNoHtmlEscape() { + verifyMarkdownNodeByName("codeBlockNoHtmlEscape", "hackTheArithmetic") + } + + @Test fun companionObjectExtension() { + verifyMarkdownNodeByName("companionObjectExtension", "Foo") + } + + @Test fun starProjection() { + verifyMarkdownNode("starProjection") + } + + @Test fun extensionFunctionParameter() { + verifyMarkdownNode("extensionFunctionParameter") + } + + @Test fun summarizeSignatures() { + verifyMarkdownNodes("summarizeSignatures") { model -> model.members } + } + + @Test fun summarizeSignaturesProperty() { + verifyMarkdownNodes("summarizeSignaturesProperty") { model -> model.members } + } + + @Test fun reifiedTypeParameter() { + verifyMarkdownNode("reifiedTypeParameter", withKotlinRuntime = true) + } + + @Test fun annotatedTypeParameter() { + verifyMarkdownNode("annotatedTypeParameter", withKotlinRuntime = true) + } + + @Test fun inheritedMembers() { + verifyMarkdownNodeByName("inheritedMembers", "Bar") + } + + @Test fun inheritedExtensions() { + verifyMarkdownNodeByName("inheritedExtensions", "Bar") + } + + @Test fun genericInheritedExtensions() { + verifyMarkdownNodeByName("genericInheritedExtensions", "Bar") + } + + @Test fun arrayAverage() { + verifyMarkdownNodeByName("arrayAverage", "XArray") + } + + @Test fun multipleTypeParameterConstraints() { + verifyMarkdownNode("multipleTypeParameterConstraints", withKotlinRuntime = true) + } + + @Test fun inheritedCompanionObjectProperties() { + verifyMarkdownNodeByName("inheritedCompanionObjectProperties", "C") + } + + @Test fun shadowedExtensionFunctions() { + verifyMarkdownNodeByName("shadowedExtensionFunctions", "Bar") + } + + @Test fun inapplicableExtensionFunctions() { + verifyMarkdownNodeByName("inapplicableExtensionFunctions", "Bar") + } + + @Test fun receiverParameterTypeBound() { + verifyMarkdownNodeByName("receiverParameterTypeBound", "Foo") + } + + @Test fun extensionWithDocumentedReceiver() { + verifyMarkdownNodes("extensionWithDocumentedReceiver") { model -> + model.members.single().members.single().members.filter { it.name == "fn" } + } + } + + @Test fun codeBlock() { + verifyMarkdownNode("codeBlock") + } + + @Test fun exclInCodeBlock() { + verifyMarkdownNodeByName("exclInCodeBlock", "foo") + } + + @Test fun backtickInCodeBlock() { + verifyMarkdownNodeByName("backtickInCodeBlock", "foo") + } + + @Test fun qualifiedNameLink() { + verifyMarkdownNodeByName("qualifiedNameLink", "foo", withKotlinRuntime = true) + } + + @Test fun functionalTypeWithNamedParameters() { + verifyMarkdownNode("functionalTypeWithNamedParameters") + } + + @Test fun typeAliases() { + verifyMarkdownNode("typeAliases") + verifyMarkdownPackage("typeAliases") + } + + @Test fun sampleByFQName() { + verifyMarkdownNode("sampleByFQName") + } + + @Test fun sampleByShortName() { + verifyMarkdownNode("sampleByShortName") + } + + + @Test fun suspendParam() { + verifyMarkdownNode("suspendParam") + verifyMarkdownPackage("suspendParam") + } + + @Test fun sinceKotlin() { + verifyMarkdownNode("sinceKotlin") + verifyMarkdownPackage("sinceKotlin") + } + + @Test fun sinceKotlinWide() { + verifyMarkdownPackage("sinceKotlinWide") + } + + @Test fun dynamicType() { + verifyMarkdownNode("dynamicType") + } + + @Test fun dynamicExtension() { + verifyMarkdownNodes("dynamicExtension") { model -> model.members.single().members.filter { it.name == "Foo" } } + } + + @Test fun memberExtension() { + verifyMarkdownNodes("memberExtension") { model -> model.members.single().members.filter { it.name == "Foo" } } + } + + @Test fun renderFunctionalTypeInParenthesisWhenItIsReceiver() { + verifyMarkdownNode("renderFunctionalTypeInParenthesisWhenItIsReceiver") + } + + @Test fun multiplePlatforms() { + verifyMultiplatformPackage(buildMultiplePlatforms("multiplatform/simple"), "multiplatform/simple") + } + + @Test fun multiplePlatformsMerge() { + verifyMultiplatformPackage(buildMultiplePlatforms("multiplatform/merge"), "multiplatform/merge") + } + + @Test fun multiplePlatformsMergeMembers() { + val module = buildMultiplePlatforms("multiplatform/mergeMembers") + verifyModelOutput(module, ".md", "testdata/format/multiplatform/mergeMembers/foo.kt") { model, output -> + buildPagesAndReadInto(model.members.single().members, output) + } + } + + @Test fun multiplePlatformsOmitRedundant() { + val module = buildMultiplePlatforms("multiplatform/omitRedundant") + verifyModelOutput(module, ".md", "testdata/format/multiplatform/omitRedundant/foo.kt") { model, output -> + buildPagesAndReadInto(model.members.single().members, output) + } + } + + @Test fun multiplePlatformsImplied() { + val module = buildMultiplePlatforms("multiplatform/implied") + verifyModelOutput(module, ".md", "testdata/format/multiplatform/implied/foo.kt") { model, output -> + val service = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf("JVM", "JS")) + fileGenerator.formatService = service + buildPagesAndReadInto(model.members.single().members, output) + } + } + + @Test fun packagePlatformsWithExtExtensions() { + val path = "multiplatform/packagePlatformsWithExtExtensions" + val module = DocumentationModule("test") + val options = DocumentationOptions( + outputDir = "", + outputFormat = "html", + generateClassIndexPage = false, + generatePackageIndexPage = false, + noStdlibLink = true, + noJdkLink = true, + languageVersion = null, + apiVersion = null + ) + appendDocumentation(module, contentRootFromPath("testdata/format/$path/jvm.kt"), defaultPlatforms = listOf("JVM"), withKotlinRuntime = true, options = options) + verifyMultiplatformIndex(module, path) + verifyMultiplatformPackage(module, path) + } + + @Test fun multiplePlatformsPackagePlatformFromMembers() { + val path = "multiplatform/packagePlatformsFromMembers" + val module = buildMultiplePlatforms(path) + verifyMultiplatformIndex(module, path) + verifyMultiplatformPackage(module, path) + } + + @Test fun multiplePlatformsGroupNode() { + val path = "multiplatform/groupNode" + val module = buildMultiplePlatforms(path) + verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.kt") { model, output -> + buildPagesAndReadInto( + listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }), + output + ) + } + verifyMultiplatformPackage(module, path) + } + + @Test fun multiplePlatformsBreadcrumbsInMemberOfMemberOfGroupNode() { + val path = "multiplatform/breadcrumbsInMemberOfMemberOfGroupNode" + val module = buildMultiplePlatforms(path) + verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.kt") { model, output -> + buildPagesAndReadInto( + listOfNotNull(model.members.single().members.find { it.kind == NodeKind.GroupNode }?.member(NodeKind.Class)?.member(NodeKind.Function)), + output + ) + } + } + + @Test fun linksInEmphasis() { + verifyMarkdownNode("linksInEmphasis") + } + + @Test fun linksInStrong() { + verifyMarkdownNode("linksInStrong") + } + + @Test fun linksInHeaders() { + verifyMarkdownNode("linksInHeaders") + } + + @Test fun tokensInEmphasis() { + verifyMarkdownNode("tokensInEmphasis") + } + + @Test fun tokensInStrong() { + verifyMarkdownNode("tokensInStrong") + } + + @Test fun tokensInHeaders() { + verifyMarkdownNode("tokensInHeaders") + } + + @Test fun unorderedLists() { + verifyMarkdownNode("unorderedLists") + } + + @Test fun nestedLists() { + verifyMarkdownNode("nestedLists") + } + + @Test fun referenceLink() { + verifyMarkdownNode("referenceLink") + } + + @Test fun externalReferenceLink() { + verifyMarkdownNode("externalReferenceLink") + } + + @Test fun newlineInTableCell() { + verifyMarkdownPackage("newlineInTableCell") + } + + @Test fun indentedCodeBlock() { + verifyMarkdownNode("indentedCodeBlock") + } + + @Test fun receiverReference() { + verifyMarkdownNode("receiverReference") + } + + @Test fun extensionScope() { + verifyMarkdownNodeByName("extensionScope", "test") + } + + @Test fun typeParameterReference() { + verifyMarkdownNode("typeParameterReference") + } + + @Test fun notPublishedTypeAliasAutoExpansion() { + verifyMarkdownNodeByName("notPublishedTypeAliasAutoExpansion", "foo", includeNonPublic = false) + } + + @Test fun companionImplements() { + verifyMarkdownNodeByName("companionImplements", "Foo") + } + + @Test fun enumRef() { + verifyMarkdownNode("enumRef") + } + + @Test fun inheritedLink() { + val filePath = "testdata/format/inheritedLink" + verifyOutput( + arrayOf( + contentRootFromPath("$filePath.kt"), + contentRootFromPath("$filePath.1.kt") + ), + ".md", + withJdk = true, + withKotlinRuntime = true, + includeNonPublic = false + ) { model, output -> + buildPagesAndReadInto(model.members.single { it.name == "p2" }.members.single().members, output) + } + } + + + private fun buildMultiplePlatforms(path: String): DocumentationModule { + val module = DocumentationModule("test") + val options = DocumentationOptions( + outputDir = "", + outputFormat = "html", + generateClassIndexPage = false, + generatePackageIndexPage = false, + 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) + return module + } + + private fun verifyMultiplatformPackage(module: DocumentationModule, path: String) { + verifyModelOutput(module, ".package.md", "testdata/format/$path/multiplatform.kt") { model, output -> + buildPagesAndReadInto(model.members, output) + } + } + + private fun verifyMultiplatformIndex(module: DocumentationModule, path: String) { + verifyModelOutput(module, ".md", "testdata/format/$path/multiplatform.index.kt") { + model, output -> + val service = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf()) + fileGenerator.formatService = service + buildPagesAndReadInto(listOf(model), output) + } + } + + @Test fun blankLineInsideCodeBlock() { + verifyMarkdownNode("blankLineInsideCodeBlock") + } + + private fun verifyMarkdownPackage(fileName: String, withKotlinRuntime: Boolean = false) { + verifyOutput("testdata/format/$fileName.kt", ".package.md", withKotlinRuntime = withKotlinRuntime) { model, output -> + buildPagesAndReadInto(model.members, output) + } + } + + private fun verifyMarkdownNode(fileName: String, withKotlinRuntime: Boolean = false) { + verifyMarkdownNodes(fileName, withKotlinRuntime) { model -> model.members.single().members } + } + + private fun verifyMarkdownNodes( + fileName: String, + withKotlinRuntime: Boolean = false, + includeNonPublic: Boolean = true, + nodeFilter: (DocumentationModule) -> List<DocumentationNode> + ) { + verifyOutput( + "testdata/format/$fileName.kt", + ".md", + withKotlinRuntime = withKotlinRuntime, + includeNonPublic = includeNonPublic + ) { model, output -> + buildPagesAndReadInto(nodeFilter(model), output) + } + } + + private fun verifyJavaMarkdownNode(fileName: String, withKotlinRuntime: Boolean = false) { + verifyJavaMarkdownNodes(fileName, withKotlinRuntime) { 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 -> + buildPagesAndReadInto(nodeFilter(model), output) + } + } + + private fun verifyMarkdownNodeByName( + fileName: String, + name: String, + withKotlinRuntime: Boolean = false, + includeNonPublic: Boolean = true + ) { + verifyMarkdownNodes(fileName, withKotlinRuntime, includeNonPublic) { model-> + val nodesWithName = model.members.single().members.filter { it.name == name } + if (nodesWithName.isEmpty()) { + throw IllegalArgumentException("Found no nodes named $name") + } + nodesWithName + } + } +} diff --git a/core/src/test/kotlin/format/PackageDocsTest.kt b/core/src/test/kotlin/format/PackageDocsTest.kt new file mode 100644 index 000000000..b7fff1e2e --- /dev/null +++ b/core/src/test/kotlin/format/PackageDocsTest.kt @@ -0,0 +1,92 @@ +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.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 + +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 = 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 + assertEquals("Core functions and types", block.text) + } + + @Test fun testReferenceLinksInPackageDocs() { + val mockLinkResolver = mock<DeclarationLinkResolver> { + val exampleCom = "http://example.com" + on { tryResolveContentLink(any(), eq(exampleCom)) } doAnswer { ContentExternalLink(exampleCom) } + } + + val mockPackageDescriptor = mock<PackageFragmentDescriptor> {} + + val docs = createPackageDocs(mockLinkResolver) + docs.parse("testdata/packagedocs/referenceLinks.md", listOf(mockPackageDescriptor)) + + checkMarkdownOutput(docs, "testdata/packagedocs/referenceLinks") + } + + fun checkMarkdownOutput(docs: PackageDocs, expectedFilePrefix: String) { + + val generator = FileGenerator(File("")) + + val out = StringBuilder() + 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) + assertEqualsIgnoringSeparators(expectedFile, out.toString()) + out.setLength(0) + } + + checkOutput(docs.moduleContent, ".module.md") + + docs.packageContent.forEach { + (name, content) -> + checkOutput(content, ".$name.md") + } + + } +} |