diff options
author | Marcin Aman <maman@virtuslab.com> | 2020-08-19 20:09:12 +0200 |
---|---|---|
committer | Sebastian Sellmair <34319766+sellmair@users.noreply.github.com> | 2020-08-28 15:37:55 +0200 |
commit | de809e8076b3cde06dc29328298112ed4a7026b3 (patch) | |
tree | 8773b5f9d0d148d366cd7f250c268716b156b55d /plugins/base/src/test/kotlin | |
parent | e64cb9bfbef093bcc4046a5081393f3c9778b42a (diff) | |
download | dokka-de809e8076b3cde06dc29328298112ed4a7026b3.tar.gz dokka-de809e8076b3cde06dc29328298112ed4a7026b3.tar.bz2 dokka-de809e8076b3cde06dc29328298112ed4a7026b3.zip |
Draft for improving code formatting #1346
Diffstat (limited to 'plugins/base/src/test/kotlin')
-rw-r--r-- | plugins/base/src/test/kotlin/translators/DefaultDescriptorToDocumentableTranslatorTest.kt | 101 | ||||
-rw-r--r-- | plugins/base/src/test/kotlin/translators/JavadocParserTest.kt | 26 |
2 files changed, 107 insertions, 20 deletions
diff --git a/plugins/base/src/test/kotlin/translators/DefaultDescriptorToDocumentableTranslatorTest.kt b/plugins/base/src/test/kotlin/translators/DefaultDescriptorToDocumentableTranslatorTest.kt index b0754429..8a8af626 100644 --- a/plugins/base/src/test/kotlin/translators/DefaultDescriptorToDocumentableTranslatorTest.kt +++ b/plugins/base/src/test/kotlin/translators/DefaultDescriptorToDocumentableTranslatorTest.kt @@ -1,21 +1,23 @@ package translators +import org.junit.jupiter.api.Assertions.* +import org.jetbrains.dokka.model.doc.CodeBlock +import org.jetbrains.dokka.model.doc.P +import org.jetbrains.dokka.model.doc.Text import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test class DefaultDescriptorToDocumentableTranslatorTest : AbstractCoreTest() { - - @Test - fun `data class kdocs over generated methods`() { - val configuration = dokkaConfiguration { - sourceSets { - sourceSet { - sourceRoots = listOf("src/main/kotlin") - } + val configuration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/main/kotlin") } } + } + @Test + fun `data class kdocs over generated methods`() { testInline( """ |/src/main/kotlin/sample/XD.kt @@ -39,7 +41,12 @@ class DefaultDescriptorToDocumentableTranslatorTest : AbstractCoreTest() { ) { documentablesMergingStage = { module -> assert(module.documentationOf("XD", "copy") == "") - assert(module.documentationOf("XD", "equals") == "Memory is not what the heart desires. That is only a mirror.") + assert( + module.documentationOf( + "XD", + "equals" + ) == "Memory is not what the heart desires. That is only a mirror." + ) assert(module.documentationOf("XD", "hashCode") == "") assert(module.documentationOf("XD", "toString") == "") assert(module.documentationOf("XD", "custom") == "But the fat Hobbit, he knows. Eyes always watching.") @@ -49,14 +56,6 @@ class DefaultDescriptorToDocumentableTranslatorTest : AbstractCoreTest() { @Test fun `simple class kdocs`() { - val configuration = dokkaConfiguration { - sourceSets { - sourceSet { - sourceRoots = listOf("src/main/kotlin") - } - } - } - testInline( """ |/src/main/kotlin/sample/XD.kt @@ -80,7 +79,71 @@ class DefaultDescriptorToDocumentableTranslatorTest : AbstractCoreTest() { ) { documentablesMergingStage = { module -> assert(module.documentationOf("XD", "custom") == "But the fat Hobbit, he knows. Eyes always watching.") - assert(module.documentationOf("XD", "equals") == "Memory is not what the heart desires. That is only a mirror.") + assert( + module.documentationOf( + "XD", + "equals" + ) == "Memory is not what the heart desires. That is only a mirror." + ) + } + } + } + + @Test + fun `kdocs with code block`() { + testInline( + """ + |/src/main/kotlin/sample/TestForCodeInDocs.kt + |package sample + |/** + | * Utility for building a String that represents an XML document. + | * The XmlBlob object is immutable and the passed values are copied where it makes sense. + | * + | * Note the XML Declaration is not output as part of the XmlBlob + | * + | * + | * val soapAttrs = attrs("soap-env" to "http://www.w3.org/2001/12/soap-envelope", + | * "soap-env:encodingStyle" to "http://www.w3.org/2001/12/soap-encoding") + | * val soapXml = node("soap-env:Envelope", soapAttrs, + | * node("soap-env:Body", attrs("xmlns:m" to "http://example"), + | * node("m:GetExample", + | * node("m:GetExampleName", "BasePair") + | * ) + | * ) + | * ) + | * + | * + | */ + |class TestForCodeInDocs { + |} + """.trimIndent(), configuration + ) { + documentablesMergingStage = { module -> + val description = module.descriptionOf("TestForCodeInDocs") + val expected = listOf( + P( + children = listOf(Text("Utility for building a String that represents an XML document. The XmlBlob object is immutable and the passed values are copied where it makes sense.")) + ), + P( + children = listOf(Text("Note the XML Declaration is not output as part of the XmlBlob")) + ), + CodeBlock( + children = listOf( + Text( + """ val soapAttrs = attrs("soap-env" to "http://www.w3.org/2001/12/soap-envelope", + "soap-env:encodingStyle" to "http://www.w3.org/2001/12/soap-encoding") + val soapXml = node("soap-env:Envelope", soapAttrs, + node("soap-env:Body", attrs("xmlns:m" to "http://example"), + node("m:GetExample", + node("m:GetExampleName", "BasePair") + ) + ) + )""" + ) + ) + ) + ) + assertEquals(expected, description?.root?.children) } } } diff --git a/plugins/base/src/test/kotlin/translators/JavadocParserTest.kt b/plugins/base/src/test/kotlin/translators/JavadocParserTest.kt index a1fbb2a0..8ffcfb3c 100644 --- a/plugins/base/src/test/kotlin/translators/JavadocParserTest.kt +++ b/plugins/base/src/test/kotlin/translators/JavadocParserTest.kt @@ -6,7 +6,6 @@ import org.jetbrains.dokka.model.childrenOfType import org.jetbrains.dokka.model.doc.* import org.jetbrains.dokka.model.firstChildOfType import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test import org.junit.jupiter.api.Assertions.* import utils.text @@ -100,6 +99,15 @@ class JavadocParserTest : AbstractCoreTest() { | * minute, but this specification follows the date and time conventions | * for ISO C. | * </ul> + | * <pre class="prettyprint"> + | * <androidx.fragment.app.FragmentContainerView + | * xmlns:android="http://schemas.android.com/apk/res/android" + | * xmlns:app="http://schemas.android.com/apk/res-auto" + | * android:id="@+id/fragment_container_view" + | * android:layout_width="match_parent" + | * android:layout_height="match_parent"> + | * </androidx.fragment.app.FragmentContainerView> + | * </pre> | * <p> | * In all cases, arguments given to methods for these purposes need | * not fall within the indicated ranges; for example, a date may be @@ -153,4 +161,20 @@ class JavadocParserTest : AbstractCoreTest() { assertEquals("java.util.Calendar", sees[1].name) } } + + @Test + fun `correctly parsed code block`(){ + performJavadocTest { module -> + val dateDescription = module.descriptionOf("Date2")!! + val preTagContent = dateDescription.firstChildOfType<Pre>().firstChildOfType<Text>() + val expectedText = """<androidx.fragment.app.FragmentContainerView + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:id="@+id/fragment_container_view" + android:layout_width="match_parent" + android:layout_height="match_parent"> + </androidx.fragment.app.FragmentContainerView>""".trimIndent() + assertEquals(expectedText.trim(), preTagContent.body.trim()) + } + } } |