aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/test/kotlin/parsers
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/base/src/test/kotlin/parsers')
-rw-r--r--plugins/base/src/test/kotlin/parsers/JavadocParserTest.kt72
-rw-r--r--plugins/base/src/test/kotlin/parsers/ParseModuleAndPackageDocumentationFragmentsTest.kt282
2 files changed, 35 insertions, 319 deletions
diff --git a/plugins/base/src/test/kotlin/parsers/JavadocParserTest.kt b/plugins/base/src/test/kotlin/parsers/JavadocParserTest.kt
index cf1332db..f4615216 100644
--- a/plugins/base/src/test/kotlin/parsers/JavadocParserTest.kt
+++ b/plugins/base/src/test/kotlin/parsers/JavadocParserTest.kt
@@ -1,21 +1,18 @@
package parsers
-import com.jetbrains.rd.util.first
import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
-import org.jetbrains.dokka.base.translators.psi.parsers.*
import org.jetbrains.dokka.links.Callable
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.links.JavaClassReference
import org.jetbrains.dokka.model.DEnum
import org.jetbrains.dokka.model.DModule
import org.jetbrains.dokka.model.doc.*
-import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
+import org.jetbrains.dokka.utilities.firstIsInstanceOrNull
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import utils.docs
import utils.text
-import kotlin.random.*
-import kotlin.test.*
+import kotlin.test.assertNotNull
class JavadocParserTest : BaseAbstractTest() {
@@ -98,7 +95,7 @@ class JavadocParserTest : BaseAbstractTest() {
configuration,
) {
documentablesCreationStage = { modules ->
- val docs = modules.first().packages.first().classlikes.single().documentation.first().value
+ val docs = modules.first().packages.first().classlikes.single().documentation.values.first()
val root = docs.children.first().root
kotlin.test.assertEquals(
@@ -136,7 +133,7 @@ class JavadocParserTest : BaseAbstractTest() {
configuration,
) {
documentablesCreationStage = { modules ->
- val docs = modules.first().packages.first().classlikes.single().documentation.first().value
+ val docs = modules.first().packages.first().classlikes.single().documentation.values.first()
val root = docs.children.first().root
kotlin.test.assertEquals(
@@ -171,7 +168,7 @@ class JavadocParserTest : BaseAbstractTest() {
configuration,
) {
documentablesCreationStage = { modules ->
- val docs = modules.first().packages.first().classlikes.single().documentation.first().value
+ val docs = modules.first().packages.first().classlikes.single().documentation.values.first()
val root = docs.children.first().root
kotlin.test.assertEquals(
@@ -208,7 +205,7 @@ class JavadocParserTest : BaseAbstractTest() {
configuration,
) {
documentablesCreationStage = { modules ->
- val docs = modules.first().packages.first().classlikes.single().documentation.first().value
+ val docs = modules.first().packages.first().classlikes.single().documentation.values.first()
val root = docs.children.first().root
kotlin.test.assertEquals(
@@ -242,7 +239,7 @@ class JavadocParserTest : BaseAbstractTest() {
configuration,
) {
documentablesCreationStage = { modules ->
- val docs = modules.first().packages.first().classlikes.single().documentation.first().value
+ val docs = modules.first().packages.first().classlikes.single().documentation.values.first()
val root = docs.children.first().root
kotlin.test.assertEquals(
@@ -359,7 +356,7 @@ class JavadocParserTest : BaseAbstractTest() {
testInline(source, configuration) {
documentablesCreationStage = { modules ->
- val docs = modules.first().packages.first().classlikes.single().documentation.first().value
+ val docs = modules.first().packages.first().classlikes.single().documentation.values.first()
assertEquals(expected, docs.children.first().root.children)
}
}
@@ -384,7 +381,7 @@ class JavadocParserTest : BaseAbstractTest() {
configuration,
) {
documentablesCreationStage = { modules ->
- val docs = modules.first().packages.first().classlikes.single().documentation.first().value
+ val docs = modules.first().packages.first().classlikes.single().documentation.values.first()
val root = docs.children.first().root
kotlin.test.assertEquals(
@@ -428,7 +425,7 @@ class JavadocParserTest : BaseAbstractTest() {
configuration,
) {
documentablesCreationStage = { modules ->
- val docs = modules.first().packages.first().classlikes.single().documentation.first().value
+ val docs = modules.first().packages.first().classlikes.single().documentation.values.first()
val root = docs.children.first().root
kotlin.test.assertEquals(
@@ -462,7 +459,7 @@ class JavadocParserTest : BaseAbstractTest() {
configuration,
) {
documentablesCreationStage = { modules ->
- val docs = modules.first().packages.first().classlikes.single().documentation.first().value
+ val docs = modules.first().packages.first().classlikes.single().documentation.values.first()
val root = docs.children.first().root
assertEquals(
@@ -578,7 +575,7 @@ class JavadocParserTest : BaseAbstractTest() {
configuration,
) {
documentablesCreationStage = { modules ->
- val docs = modules.first().packages.first().classlikes.single().documentation.first().value
+ val docs = modules.first().packages.first().classlikes.single().documentation.values.first()
val root = docs.children.first().root
kotlin.test.assertEquals(
@@ -591,26 +588,27 @@ class JavadocParserTest : BaseAbstractTest() {
}
}
- @Test
- fun `test isolated parsing is case sensitive`() {
- // Ensure that it won't accidentally break
- val values = JavadocTag.values().map { it.toString().toLowerCase() }
- val withRandomizedCapitalization = values.map {
- val result = buildString {
- for (char in it) {
- if (Random.nextBoolean()) {
- append(char)
- } else {
- append(char.toLowerCase())
- }
- }
- }
- if (result == it) result.toUpperCase() else result
- }
-
- for ((index, value) in JavadocTag.values().withIndex()) {
- assertEquals(value, JavadocTag.lowercaseValueOfOrNull(values[index]))
- assertNull(JavadocTag.lowercaseValueOfOrNull(withRandomizedCapitalization[index]))
- }
- }
+ // TODO [beresnev] move to java-analysis
+// @Test
+// fun `test isolated parsing is case sensitive`() {
+// // Ensure that it won't accidentally break
+// val values = JavadocTag.values().map { it.toString().toLowerCase() }
+// val withRandomizedCapitalization = values.map {
+// val result = buildString {
+// for (char in it) {
+// if (Random.nextBoolean()) {
+// append(char)
+// } else {
+// append(char.toLowerCase())
+// }
+// }
+// }
+// if (result == it) result.toUpperCase() else result
+// }
+//
+// for ((index, value) in JavadocTag.values().withIndex()) {
+// assertEquals(value, JavadocTag.lowercaseValueOfOrNull(values[index]))
+// assertNull(JavadocTag.lowercaseValueOfOrNull(withRandomizedCapitalization[index]))
+// }
+// }
}
diff --git a/plugins/base/src/test/kotlin/parsers/ParseModuleAndPackageDocumentationFragmentsTest.kt b/plugins/base/src/test/kotlin/parsers/ParseModuleAndPackageDocumentationFragmentsTest.kt
deleted file mode 100644
index b6f9307f..00000000
--- a/plugins/base/src/test/kotlin/parsers/ParseModuleAndPackageDocumentationFragmentsTest.kt
+++ /dev/null
@@ -1,282 +0,0 @@
-package parsers
-
-import org.intellij.markdown.MarkdownElementTypes
-import org.jetbrains.dokka.base.parsers.moduleAndPackage.*
-import org.jetbrains.dokka.base.parsers.moduleAndPackage.ModuleAndPackageDocumentation.Classifier.Module
-import org.jetbrains.dokka.base.parsers.moduleAndPackage.ModuleAndPackageDocumentation.Classifier.Package
-import org.jetbrains.dokka.model.doc.*
-import org.jetbrains.dokka.utilities.DokkaLogger
-import org.junit.jupiter.api.Assertions.assertEquals
-import org.junit.jupiter.api.Assertions.assertTrue
-import org.junit.jupiter.api.Test
-import org.junit.jupiter.api.assertThrows
-import org.junit.jupiter.api.io.TempDir
-import java.nio.file.Path
-
-class ParseModuleAndPackageDocumentationFragmentsTest {
-
- private fun testBasicExample(lineSeperator: String = "\n") {
- val source = source(
- """
- # Module kotlin-demo
- Module description
-
- # Package org.jetbrains.kotlin.demo
- Package demo description
- ## Level 2 heading
- Heading 2\r\n
-
- # Package org.jetbrains.kotlin.demo2
- Package demo2 description
- """.trimIndent().replace("\n", lineSeperator)
- )
- val fragments = parseModuleAndPackageDocumentationFragments(source)
-
- assertEquals(
- listOf(
- ModuleAndPackageDocumentationFragment(
- classifier = Module,
- name = "kotlin-demo",
- documentation = "Module description",
- source = source
- ),
- ModuleAndPackageDocumentationFragment(
- classifier = Package,
- name = "org.jetbrains.kotlin.demo",
- documentation = "Package demo description${lineSeperator}## Level 2 heading${lineSeperator}Heading 2\\r\\n",
- source = source
- ),
- ModuleAndPackageDocumentationFragment(
- classifier = Package,
- name = "org.jetbrains.kotlin.demo2",
- documentation = "Package demo2 description",
- source = source
- )
- ),
- fragments
- )
- }
-
- @Test
- fun `basic example`() {
- testBasicExample()
- }
-
- @Test
- fun `CRLF line seperators`() {
- testBasicExample("\r\n")
- }
-
- @Test
- fun `no module name specified fails`() {
- val exception = assertThrows<IllegalModuleAndPackageDocumentation> {
- parseModuleAndPackageDocumentationFragments(
- source(
- """
- # Module
- No module name given
- """.trimIndent()
- )
- )
- }
-
- assertTrue(
- "Missing Module name" in exception.message.orEmpty(),
- "Expected 'Missing Module name' in error message"
- )
- }
-
- @Test
- fun `no package name specified does not fail`() {
- val source = source(
- """
- # Package
- This is a root package
- """.trimIndent()
- )
- val fragments = parseModuleAndPackageDocumentationFragments(source)
- assertEquals(1, fragments.size, "Expected a single package fragment")
-
- assertEquals(
- ModuleAndPackageDocumentationFragment(
- name = "",
- classifier = Package,
- documentation = "This is a root package",
- source = source
- ),
- fragments.single()
- )
- }
-
- @Test
- fun `white space in module name is supported`() {
- val fragment = parseModuleAndPackageDocumentationFragments(
- source(
- """
- # Module My Module
- Documentation for my module
- """.trimIndent()
- )
- )
-
- assertEquals(
- Module, fragment.single().classifier,
- "Expected module being parsec"
- )
-
- assertEquals(
- "My Module", fragment.single().name,
- "Expected module name with white spaces being parsed"
- )
-
- assertEquals(
- "Documentation for my module", fragment.single().documentation,
- "Expected documentation being available"
- )
- }
-
- @Test
- fun `white space in package name fails`() {
- val exception = assertThrows<IllegalModuleAndPackageDocumentation> {
- parseModuleAndPackageDocumentationFragments(
- source(
- """
- # Package my package
- """.trimIndent()
- )
- )
- }
-
- assertTrue(
- "Package my package" in exception.message.orEmpty(),
- "Expected problematic statement in error message"
- )
- }
-
- @Test
- fun `multiple whitespaces are supported in first line`() {
- val source = source(
- """
- # Module my-module
- My Module
- # Package com.my.package
- My Package
- """.trimIndent()
- )
- val fragments = parseModuleAndPackageDocumentationFragments(source)
-
- assertEquals(
- listOf(
- ModuleAndPackageDocumentationFragment(
- classifier = Module,
- name = "my-module",
- documentation = "My Module",
- source = source
- ),
- ModuleAndPackageDocumentationFragment(
- classifier = Package,
- name = "com.my.package",
- documentation = "My Package",
- source = source
- )
- ),
- fragments
- )
- }
-
- @Test
- fun `parse from file`(@TempDir temporaryFolder: Path) {
- val file = temporaryFolder.resolve("other.md").toFile()
- file.writeText(
- """
- # Module MyModule
- D1
- # Package com.sample
- D2
- """.trimIndent()
- )
-
- assertEquals(
- listOf(
- ModuleAndPackageDocumentationFragment(
- classifier = Module,
- name = "MyModule",
- documentation = "D1",
- source = ModuleAndPackageDocumentationFile(file)
- ),
- ModuleAndPackageDocumentationFragment(
- classifier = Package,
- name = "com.sample",
- documentation = "D2",
- source = ModuleAndPackageDocumentationFile(file)
- )
- ),
- parseModuleAndPackageDocumentationFragments(file)
- )
- }
-
- @Test
- fun `at in code block is supported`() {
- val fragment = parseModuleAndPackageDocumentationFragments(
- source(
- """
- # Module My Module
- ```
- @Smth
- ```
- @author Smb
- """.trimIndent()
- )
- )
-
- assertEquals(
- "```\n" +
- "@Smth\n" +
- "```\n" +
- "@author Smb", fragment.single().documentation,
- "Expected documentation being available"
- )
-
- val parsingContext = ModuleAndPackageDocumentationParsingContext(object : DokkaLogger {
- override var warningsCount: Int = 0
- override var errorsCount: Int = 0
- override fun debug(message: String) {}
- override fun info(message: String) {}
- override fun progress(message: String) {}
- override fun warn(message: String) {}
- override fun error(message: String) {}
- })
- val parsedFragment = parseModuleAndPackageDocumentation(parsingContext, fragment.single())
- val expectedDocumentationNode = DocumentationNode(
- listOf(
- Description(
- CustomDocTag(
- listOf(
- CodeBlock(
- listOf(
- Text("@Smth")
- )
- )
- ), name = MarkdownElementTypes.MARKDOWN_FILE.name
- )
- ),
- Author(
- CustomDocTag(
- listOf(
- P(listOf(Text("Smb")))
- ), name = MarkdownElementTypes.MARKDOWN_FILE.name
- )
- )
- )
- )
- assertEquals(
- expectedDocumentationNode, parsedFragment.documentation
- )
- }
-
- private fun source(documentation: String): ModuleAndPackageDocumentationSource =
- object : ModuleAndPackageDocumentationSource() {
- override val sourceDescription: String = "inline test"
- override val documentation: String = documentation
- }
-}