From 086651dcc3ce496c5ba256dcfddb6afd5c83f7ff Mon Sep 17 00:00:00 2001 From: Błażej Kardyś Date: Wed, 1 Jul 2020 23:57:29 +0200 Subject: Javadoc anchors --- .../javadoc/JavadocClasslikeTemplateMapTest.kt | 19 ++--- .../kotlin/javadoc/location/JavadocLocationTest.kt | 98 ++++++++++++++++++---- 2 files changed, 90 insertions(+), 27 deletions(-) (limited to 'plugins/javadoc/src/test/kotlin') 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>(method["parameters"]).size, "Expected no parameters" ) - assertEquals("final java.lang.String", method.modifiers()) - assertEquals("testFunction()", method.signatureWithoutModifiers()) + assertEquals("final String", method.modifiers()) + assertEquals("testFunction()", 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("FIRST", first.signatureWithoutModifiers()) - assertEquals("SECOND", second.signatureWithoutModifiers()) + assertEquals("FIRST", first.signatureWithoutModifiers()) + assertEquals("SECOND", second.signatureWithoutModifiers()) } } @@ -258,19 +257,19 @@ internal class JavadocClasslikeTemplateMapTest : AbstractJavadocTemplateMapTest( assertParameterNode( node = first, expectedName = "simple", - expectedType = "java.lang.String", + expectedType = "String", expectedDescription = "simple String parameter" ) assertParameterNode( node = second, expectedName = "parameters", - expectedType = "java.lang.Integer", + expectedType = "Integer", expectedDescription = "simple Integer parameter" ) assertParameterNode( node = third, expectedName = "list", - expectedType = "java.lang.Boolean", + expectedType = "Boolean", expectedDescription = "simple Boolean parameter" ) } @@ -306,14 +305,14 @@ internal class JavadocClasslikeTemplateMapTest : AbstractJavadocTemplateMapTest( assertEquals("Generic", map["name"]) assertEquals( - "public final class Generic<T extends java.io.Serializable>", + "public final class Generic<T extends Serializable>", map.signatureWithModifiers() ) val methods = assertIsInstance>(map["methods"]) val ownMethods = assertIsInstance>(methods["own"]).first() val sampleFunction = assertIsInstance>(ownMethods) - assertEquals("final <D extends T> D sampleFunction()", sampleFunction.signatureWithModifiers()) + assertEquals("final <D extends T> D sampleFunction()", 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() : Serializable, Cloneable { + | fun test() {} + | fun test2(s: String) {} + | fun test3(a: A, t: T) {} + |} """.trimIndent(), config, cleanupOutput = false, pluginOverrides = listOf(JavadocPlugin()) - ) { - renderingStage = { rootPageNode, dokkaContext -> - val transformer = JavadocContentToHtmlTranslator( - dokkaContext.plugin().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() + .firstChildOfType() + assertEquals( + " implements Serializable, Cloneable", + 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() + .firstChildOfType { it.name == "Test" } + val testFunctionNode = testClassNode.methods.first { it.name == "test" } + assertEquals( + """test()""", + transformer.htmlForContentNode( + testFunctionNode.signature.signatureWithoutModifiers, + testClassNode ) - val testClass = rootPageNode.firstChildOfType() - .firstChildOfType() - assert( - " implements Serializable, Cloneable" - == 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() + .firstChildOfType { it.name == "Test" } + val testFunctionNode = testClassNode.methods.first { it.name == "test2" } + assertEquals( + """test2(String 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() + .firstChildOfType { it.name == "Test" } + val testFunctionNode = testClassNode.methods.first { it.name == "test3" } + assertEquals( + """test3(A a, T t)""", + transformer.htmlForContentNode( + testFunctionNode.signature.signatureWithoutModifiers, + testClassNode + ) + ) + } + } + + private fun htmlTranslator(rootPageNode: RootPageNode, dokkaContext: DokkaContext) = JavadocContentToHtmlTranslator( + dokkaContext.plugin().querySingle { locationProviderFactory } + .getLocationProvider(rootPageNode), + dokkaContext + ) } -- cgit