aboutsummaryrefslogtreecommitdiff
path: root/plugins/javadoc/src/test
diff options
context:
space:
mode:
authorBłażej Kardyś <bkardys@virtuslab.com>2020-07-01 23:57:29 +0200
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-07-13 18:26:43 +0200
commit086651dcc3ce496c5ba256dcfddb6afd5c83f7ff (patch)
treee69e2e2b334fb86a8dd7945eccb23749894fdf0d /plugins/javadoc/src/test
parenta23b652f7f1f43d4cdda4509ff7ff461a0d0bf3a (diff)
downloaddokka-086651dcc3ce496c5ba256dcfddb6afd5c83f7ff.tar.gz
dokka-086651dcc3ce496c5ba256dcfddb6afd5c83f7ff.tar.bz2
dokka-086651dcc3ce496c5ba256dcfddb6afd5c83f7ff.zip
Javadoc anchors
Diffstat (limited to 'plugins/javadoc/src/test')
-rw-r--r--plugins/javadoc/src/test/kotlin/javadoc/JavadocClasslikeTemplateMapTest.kt19
-rw-r--r--plugins/javadoc/src/test/kotlin/javadoc/location/JavadocLocationTest.kt98
2 files changed, 90 insertions, 27 deletions
diff --git a/plugins/javadoc/src/test/kotlin/javadoc/JavadocClasslikeTemplateMapTest.kt b/plugins/javadoc/src/test/kotlin/javadoc/JavadocClasslikeTemplateMapTest.kt
index dc1573e1..340e4697 100644
--- a/plugins/javadoc/src/test/kotlin/javadoc/JavadocClasslikeTemplateMapTest.kt
+++ b/plugins/javadoc/src/test/kotlin/javadoc/JavadocClasslikeTemplateMapTest.kt
@@ -2,7 +2,6 @@ package javadoc
import javadoc.pages.JavadocClasslikePageNode
import org.junit.jupiter.api.Assertions.assertEquals
-import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import testApi.utils.assertIsInstance
@@ -94,8 +93,8 @@ internal class JavadocClasslikeTemplateMapTest : AbstractJavadocTemplateMapTest(
0, assertIsInstance<List<*>>(method["parameters"]).size,
"Expected no parameters"
)
- assertEquals("final <a href=.html>java.lang.String</a>", method.modifiers())
- assertEquals("<a href=.html>testFunction</a>()", method.signatureWithoutModifiers())
+ assertEquals("final <a href=.html>String</a>", method.modifiers())
+ assertEquals("<a href=TestClass.html#testFunction-->testFunction</a>()", method.signatureWithoutModifiers())
}
}
@@ -204,8 +203,8 @@ internal class JavadocClasslikeTemplateMapTest : AbstractJavadocTemplateMapTest(
assertEquals("Sample docs for first", first["brief"])
assertEquals("Sample docs for second", second["brief"])
- assertEquals("<a href=.html>FIRST</a>", first.signatureWithoutModifiers())
- assertEquals("<a href=.html>SECOND</a>", second.signatureWithoutModifiers())
+ assertEquals("<a href=ClockDays.html#FIRST>FIRST</a>", first.signatureWithoutModifiers())
+ assertEquals("<a href=ClockDays.html#SECOND>SECOND</a>", second.signatureWithoutModifiers())
}
}
@@ -258,19 +257,19 @@ internal class JavadocClasslikeTemplateMapTest : AbstractJavadocTemplateMapTest(
assertParameterNode(
node = first,
expectedName = "simple",
- expectedType = "<a href=.html>java.lang.String</a>",
+ expectedType = "<a href=.html>String</a>",
expectedDescription = "simple String parameter"
)
assertParameterNode(
node = second,
expectedName = "parameters",
- expectedType = "<a href=.html>java.lang.Integer</a>",
+ expectedType = "<a href=.html>Integer</a>",
expectedDescription = "simple Integer parameter"
)
assertParameterNode(
node = third,
expectedName = "list",
- expectedType = "<a href=.html>java.lang.Boolean</a>",
+ expectedType = "<a href=.html>Boolean</a>",
expectedDescription = "simple Boolean parameter"
)
}
@@ -306,14 +305,14 @@ internal class JavadocClasslikeTemplateMapTest : AbstractJavadocTemplateMapTest(
assertEquals("Generic", map["name"])
assertEquals(
- "public final class <a href=Generic.html>Generic</a>&lt;T extends <a href=.html>java.io.Serializable</a>&gt;",
+ "public final class <a href=Generic.html>Generic</a>&lt;T extends <a href=.html>Serializable</a>&gt;",
map.signatureWithModifiers()
)
val methods = assertIsInstance<Map<Any, Any?>>(map["methods"])
val ownMethods = assertIsInstance<List<*>>(methods["own"]).first()
val sampleFunction = assertIsInstance<Map<String, Any?>>(ownMethods)
- assertEquals("final &lt;D extends <a href=Generic.html>T</a>&gt; <a href=.html>D</a> <a href=.html>sampleFunction</a>()", sampleFunction.signatureWithModifiers())
+ assertEquals("final &lt;D extends <a href=Generic.html>T</a>&gt; <a href=Generic.html#sampleFunction-->D</a> <a href=Generic.html#sampleFunction-->sampleFunction</a>()", sampleFunction.signatureWithModifiers())
}
}
diff --git a/plugins/javadoc/src/test/kotlin/javadoc/location/JavadocLocationTest.kt b/plugins/javadoc/src/test/kotlin/javadoc/location/JavadocLocationTest.kt
index d60e1070..65d5481d 100644
--- a/plugins/javadoc/src/test/kotlin/javadoc/location/JavadocLocationTest.kt
+++ b/plugins/javadoc/src/test/kotlin/javadoc/location/JavadocLocationTest.kt
@@ -7,16 +7,17 @@ import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.ExternalDocumentationLinkImpl
import org.jetbrains.dokka.javadoc.JavadocPlugin
import org.jetbrains.dokka.model.firstChildOfType
+import org.jetbrains.dokka.pages.RootPageNode
+import org.jetbrains.dokka.plugability.DokkaContext
import org.jetbrains.dokka.plugability.plugin
import org.jetbrains.dokka.plugability.querySingle
import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest
import org.junit.jupiter.api.Test
+import org.junit.jupiter.api.Assertions.assertEquals
class JavadocTest : AbstractCoreTest() {
- @Test
- fun `resolved signature with external links`() {
-
+ private fun locationTestInline(testHandler: (RootPageNode, DokkaContext) -> Unit) {
fun externalLink(link: String) = DokkaConfiguration.ExternalDocumentationLink
.Builder(link)
.build() as ExternalDocumentationLinkImpl
@@ -34,31 +35,94 @@ class JavadocTest : AbstractCoreTest() {
}
}
}
-
testInline(
"""
|/jvmSrc/javadoc/Test.kt
|package javadoc
|import java.io.Serializable
- |class Test() : Serializable, Cloneable
+ |class Test<A>() : Serializable, Cloneable {
+ | fun test() {}
+ | fun test2(s: String) {}
+ | fun <T> test3(a: A, t: T) {}
+ |}
""".trimIndent(),
config,
cleanupOutput = false,
pluginOverrides = listOf(JavadocPlugin())
- ) {
- renderingStage = { rootPageNode, dokkaContext ->
- val transformer = JavadocContentToHtmlTranslator(
- dokkaContext.plugin<JavadocPlugin>().querySingle { locationProviderFactory }
- .getLocationProvider(rootPageNode),
- dokkaContext
+ ) { renderingStage = testHandler }
+ }
+
+ @Test
+ fun `resolved signature with external links`() {
+
+ locationTestInline { rootPageNode, dokkaContext ->
+ val transformer = htmlTranslator(rootPageNode, dokkaContext)
+ val testClass = rootPageNode.firstChildOfType<JavadocPackagePageNode>()
+ .firstChildOfType<JavadocClasslikePageNode>()
+ assertEquals(
+ " implements <a href=https://docs.oracle.com/javase/8/docs/api/java/io/Serializable.html>Serializable</a>, <a href=https://docs.oracle.com/javase/8/docs/api/java/lang/Cloneable.html>Cloneable</a>",
+ transformer.htmlForContentNode(testClass.signature.supertypes!!, null)
+ )
+ }
+ }
+
+ @Test
+ fun `resolved signature to no argument function`() {
+
+ locationTestInline { rootPageNode, dokkaContext ->
+ val transformer = htmlTranslator(rootPageNode, dokkaContext)
+ val testClassNode = rootPageNode.firstChildOfType<JavadocPackagePageNode>()
+ .firstChildOfType<JavadocClasslikePageNode> { it.name == "Test" }
+ val testFunctionNode = testClassNode.methods.first { it.name == "test" }
+ assertEquals(
+ """<a href=Test.html#test-->test</a>()""",
+ transformer.htmlForContentNode(
+ testFunctionNode.signature.signatureWithoutModifiers,
+ testClassNode
)
- val testClass = rootPageNode.firstChildOfType<JavadocPackagePageNode>()
- .firstChildOfType<JavadocClasslikePageNode>()
- assert(
- " implements <a href=https://docs.oracle.com/javase/8/docs/api/java/io/Serializable.html>Serializable</a>, <a href=https://docs.oracle.com/javase/8/docs/api/java/lang/Cloneable.html>Cloneable</a>"
- == transformer.htmlForContentNode(testClass.signature.supertypes!!, null)
+ )
+ }
+ }
+
+ @Test
+ fun `resolved signature to one argument function`() {
+
+ locationTestInline { rootPageNode, dokkaContext ->
+ val transformer = htmlTranslator(rootPageNode, dokkaContext)
+ val testClassNode = rootPageNode.firstChildOfType<JavadocPackagePageNode>()
+ .firstChildOfType<JavadocClasslikePageNode> { it.name == "Test" }
+ val testFunctionNode = testClassNode.methods.first { it.name == "test2" }
+ assertEquals(
+ """<a href=Test.html#test2-String->test2</a>(<a href=https://docs.oracle.com/javase/8/docs/api/java/lang/String.html>String</a> s)""",
+ transformer.htmlForContentNode(
+ testFunctionNode.signature.signatureWithoutModifiers,
+ testClassNode
)
- }
+ )
}
}
+
+ @Test
+ fun `resolved signature to generic function`() {
+
+ locationTestInline { rootPageNode, dokkaContext ->
+ val transformer = htmlTranslator(rootPageNode, dokkaContext)
+ val testClassNode = rootPageNode.firstChildOfType<JavadocPackagePageNode>()
+ .firstChildOfType<JavadocClasslikePageNode> { it.name == "Test" }
+ val testFunctionNode = testClassNode.methods.first { it.name == "test3" }
+ assertEquals(
+ """<a href=Test.html#test3-A,%20T->test3</a>(<a href=Test.html>A</a> a, <a href=Test.html#test3-A,%20T->T</a> t)""",
+ transformer.htmlForContentNode(
+ testFunctionNode.signature.signatureWithoutModifiers,
+ testClassNode
+ )
+ )
+ }
+ }
+
+ private fun htmlTranslator(rootPageNode: RootPageNode, dokkaContext: DokkaContext) = JavadocContentToHtmlTranslator(
+ dokkaContext.plugin<JavadocPlugin>().querySingle { locationProviderFactory }
+ .getLocationProvider(rootPageNode),
+ dokkaContext
+ )
}