aboutsummaryrefslogtreecommitdiff
path: root/core/src/test/kotlin
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/test/kotlin')
-rw-r--r--core/src/test/kotlin/TestAPI.kt1
-rw-r--r--core/src/test/kotlin/format/PackageDocsTest.kt47
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")
+ }
+
+ }
}