diff options
Diffstat (limited to 'core/src/test/kotlin')
-rw-r--r-- | core/src/test/kotlin/TestAPI.kt | 15 | ||||
-rw-r--r-- | core/src/test/kotlin/format/FileGeneratorTestCase.kt | 35 | ||||
-rw-r--r-- | core/src/test/kotlin/format/GFMFormatTest.kt | 15 | ||||
-rw-r--r-- | core/src/test/kotlin/format/HtmlFormatTest.kt | 18 | ||||
-rw-r--r-- | core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt | 17 | ||||
-rw-r--r-- | core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt | 15 | ||||
-rw-r--r-- | core/src/test/kotlin/format/KotlinWebSiteRunnableSamplesFormatTest.kt | 56 | ||||
-rw-r--r-- | core/src/test/kotlin/format/MarkdownFormatTest.kt | 51 | ||||
-rw-r--r-- | core/src/test/kotlin/format/PackageDocsTest.kt | 14 |
9 files changed, 146 insertions, 90 deletions
diff --git a/core/src/test/kotlin/TestAPI.kt b/core/src/test/kotlin/TestAPI.kt index ff8a5260..aa3eff48 100644 --- a/core/src/test/kotlin/TestAPI.kt +++ b/core/src/test/kotlin/TestAPI.kt @@ -270,21 +270,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..948426ea --- /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: ${relativeToRoot(loc).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..b90ab2bf 100644 --- a/core/src/test/kotlin/format/GFMFormatTest.kt +++ b/core/src/test/kotlin/format/GFMFormatTest.kt @@ -4,20 +4,25 @@ import org.jetbrains.dokka.GFMFormatService import org.jetbrains.dokka.KotlinLanguageService import org.junit.Test -class GFMFormatTest { - private val gfmService = GFMFormatService(InMemoryLocationService, KotlinLanguageService(), listOf()) +class GFMFormatTest : FileGeneratorTestCase() { + override val formatService = GFMFormatService(fileGenerator, KotlinLanguageService(), listOf()) - @Test fun sample() { + @Test + fun sample() { verifyGFMNodeByName("sample", "Foo") } - @Test fun listInTableCell() { + @Test + fun listInTableCell() { verifyGFMNodeByName("listInTableCell", "Foo") } 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 }) + 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 index 01e4559e..54c367fd 100644 --- a/core/src/test/kotlin/format/HtmlFormatTest.kt +++ b/core/src/test/kotlin/format/HtmlFormatTest.kt @@ -3,11 +3,12 @@ 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()) +class HtmlFormatTest: FileGeneratorTestCase() { + override val formatService = HtmlFormatService(fileGenerator, KotlinLanguageService(), HtmlTemplateService.default(), listOf()) @Test fun classWithCompanionObject() { verifyHtmlNode("classWithCompanionObject") @@ -31,10 +32,10 @@ class HtmlFormatTest { @Test fun deprecated() { verifyOutput("testdata/format/deprecated.kt", ".package.html") { model, output -> - htmlService.createOutputBuilder(output, tempLocation).appendNodes(model.members) + buildPagesAndReadInto(model.members, output) } verifyOutput("testdata/format/deprecated.kt", ".class.html") { model, output -> - htmlService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members) + buildPagesAndReadInto(model.members.single().members, output) } } @@ -102,7 +103,10 @@ class HtmlFormatTest { 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" }) + buildPagesAndReadInto( + model.members.single().members.filter { it.name == "Bar" }, + output + ) } } @@ -158,7 +162,7 @@ class HtmlFormatTest { withKotlinRuntime: Boolean = false, nodeFilter: (DocumentationModule) -> List<DocumentationNode>) { verifyOutput("testdata/format/$fileName.kt", ".html", withKotlinRuntime = withKotlinRuntime) { model, output -> - htmlService.createOutputBuilder(output, tempLocation).appendNodes(nodeFilter(model)) + buildPagesAndReadInto(nodeFilter(model), output) } } @@ -170,7 +174,7 @@ class HtmlFormatTest { withKotlinRuntime: Boolean = false, nodeFilter: (DocumentationModule) -> List<DocumentationNode>) { verifyJavaOutput("testdata/format/$fileName.java", ".html", withKotlinRuntime = withKotlinRuntime) { model, output -> - htmlService.createOutputBuilder(output, tempLocation).appendNodes(nodeFilter(model)) + buildPagesAndReadInto(nodeFilter(model), output) } } } diff --git a/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt b/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt index af44b048..b971b54d 100644 --- a/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt +++ b/core/src/test/kotlin/format/KotlinWebSiteFormatTest.kt @@ -1,12 +1,13 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.* +import org.junit.Before 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,14 +30,20 @@ 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 }) + buildPagesAndReadInto( + model.members.single().members.filter { it.name == name }, + output + ) } } @@ -58,7 +65,7 @@ class KotlinWebSiteFormatTest { 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..49fa6d2f 100644 --- a/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt +++ b/core/src/test/kotlin/format/KotlinWebSiteHtmlFormatTest.kt @@ -1,11 +1,11 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.* +import org.junit.Before import org.junit.Test -class KotlinWebSiteHtmlFormatTest { - private val kwsService = KotlinWebsiteHtmlFormatService(InMemoryLocationService, KotlinLanguageService(), listOf()) - +class KotlinWebSiteHtmlFormatTest: FileGeneratorTestCase() { + override val formatService = KotlinWebsiteHtmlFormatService(fileGenerator, KotlinLanguageService(), listOf(), EmptyHtmlTemplateService) @Test fun dropImport() { verifyKWSNodeByName("dropImport", "foo") @@ -44,14 +44,17 @@ 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 }) + buildPagesAndReadInto(model.members.single().members.filter { it.name == name }, output) } } @@ -73,7 +76,7 @@ class KotlinWebSiteHtmlFormatTest { 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) } } 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..f60969fc 100644 --- a/core/src/test/kotlin/format/MarkdownFormatTest.kt +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -1,10 +1,11 @@ package org.jetbrains.dokka.tests import org.jetbrains.dokka.* +import org.junit.Before import org.junit.Test -class MarkdownFormatTest { - private val markdownService = MarkdownFormatService(InMemoryLocationService, KotlinLanguageService(), listOf()) +class MarkdownFormatTest: FileGeneratorTestCase() { + override val formatService = MarkdownFormatService(fileGenerator, KotlinLanguageService(), listOf()) @Test fun emptyDescription() { verifyMarkdownNode("emptyDescription") @@ -34,21 +35,23 @@ class MarkdownFormatTest { @Test fun extensions() { verifyOutput("testdata/format/extensions.kt", ".package.md") { model, output -> - markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members) + buildPagesAndReadInto(model.members, output) } verifyOutput("testdata/format/extensions.kt", ".class.md") { model, output -> - markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members) + buildPagesAndReadInto(model.members.single().members, output) } } @Test fun enumClass() { verifyOutput("testdata/format/enumClass.kt", ".md") { model, output -> - markdownService.createOutputBuilder(output, tempLocation).appendNodes(model.members.single().members) + buildPagesAndReadInto(model.members.single().members, output) } verifyOutput("testdata/format/enumClass.kt", ".value.md") { 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 + ) } } @@ -282,22 +285,23 @@ 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) } } @@ -328,8 +332,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,8 +344,10 @@ 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 + ) } } @@ -428,15 +436,16 @@ class MarkdownFormatTest { 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) } } @@ -446,7 +455,7 @@ class MarkdownFormatTest { 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) + buildPagesAndReadInto(model.members, output) } } @@ -466,7 +475,7 @@ class MarkdownFormatTest { withKotlinRuntime = withKotlinRuntime, includeNonPublic = includeNonPublic ) { model, output -> - markdownService.createOutputBuilder(output, tempLocation).appendNodes(nodeFilter(model)) + buildPagesAndReadInto(nodeFilter(model), output) } } @@ -476,7 +485,7 @@ class MarkdownFormatTest { 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)) + buildPagesAndReadInto(nodeFilter(model), output) } } diff --git a/core/src/test/kotlin/format/PackageDocsTest.kt b/core/src/test/kotlin/format/PackageDocsTest.kt index a5547025..704f7b99 100644 --- a/core/src/test/kotlin/format/PackageDocsTest.kt +++ b/core/src/test/kotlin/format/PackageDocsTest.kt @@ -5,14 +5,13 @@ 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.descriptors.PackageFragmentDescriptor import org.junit.Assert.assertEquals import org.junit.Test import java.io.File -public class PackageDocsTest { +class PackageDocsTest { @Test fun verifyParse() { val docs = PackageDocs(null, DokkaConsoleLogger) docs.parse("testdata/packagedocs/stdlib.md", emptyList()) @@ -37,8 +36,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) |