diff options
author | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2017-06-05 18:28:49 +0300 |
---|---|---|
committer | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2017-06-07 17:19:45 +0300 |
commit | fff865cb03d406a07190ad15a9cbf81cb4cfa36a (patch) | |
tree | 9f345ea4e34ef4e1872f424c846f129681404cea /core/src/test/kotlin | |
parent | 6ca62b8b7b0bbe5df26e7e66b827926f9b1417d3 (diff) | |
download | dokka-fff865cb03d406a07190ad15a9cbf81cb4cfa36a.tar.gz dokka-fff865cb03d406a07190ad15a9cbf81cb4cfa36a.tar.bz2 dokka-fff865cb03d406a07190ad15a9cbf81cb4cfa36a.zip |
Fix StringOutOfBoundsException in link mapping
#167
#KT-18213 fixed
Diffstat (limited to 'core/src/test/kotlin')
-rw-r--r-- | core/src/test/kotlin/TestAPI.kt | 1 | ||||
-rw-r--r-- | core/src/test/kotlin/format/PackageDocsTest.kt | 47 |
2 files changed, 44 insertions, 4 deletions
diff --git a/core/src/test/kotlin/TestAPI.kt b/core/src/test/kotlin/TestAPI.kt index e11274ea..4799cd93 100644 --- a/core/src/test/kotlin/TestAPI.kt +++ b/core/src/test/kotlin/TestAPI.kt @@ -189,6 +189,7 @@ fun verifyJavaOutput(path: String, } fun assertEqualsIgnoringSeparators(expectedFile: File, output: String) { + if (!expectedFile.exists()) expectedFile.createNewFile() val expectedText = expectedFile.readText().replace("\r\n", "\n") val actualText = output.replace("\r\n", "\n") diff --git a/core/src/test/kotlin/format/PackageDocsTest.kt b/core/src/test/kotlin/format/PackageDocsTest.kt index 2ff6e85f..a5547025 100644 --- a/core/src/test/kotlin/format/PackageDocsTest.kt +++ b/core/src/test/kotlin/format/PackageDocsTest.kt @@ -1,11 +1,16 @@ package org.jetbrains.dokka.tests.format -import org.jetbrains.dokka.ContentBlock -import org.jetbrains.dokka.ContentText -import org.jetbrains.dokka.DokkaConsoleLogger -import org.jetbrains.dokka.PackageDocs +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.descriptors.PackageFragmentDescriptor import org.junit.Assert.assertEquals import org.junit.Test +import java.io.File public class PackageDocsTest { @Test fun verifyParse() { @@ -15,4 +20,38 @@ public class PackageDocsTest { 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 = PackageDocs(mockLinkResolver, DokkaConsoleLogger) + docs.parse("testdata/packagedocs/referenceLinks.md", listOf(mockPackageDescriptor)) + + checkMarkdownOutput(docs, "testdata/packagedocs/referenceLinks") + } + + fun checkMarkdownOutput(docs: PackageDocs, expectedFilePrefix: String) { + + val out = StringBuilder() + val outputBuilder = MarkdownOutputBuilder(out, InMemoryLocationService.root, InMemoryLocationService, 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") + } + + } } |