From c59d6ef872186d185318c2bdcedabf9eaaa7b8ca Mon Sep 17 00:00:00 2001 From: Vadim Mishenev Date: Mon, 11 Apr 2022 18:22:44 +0300 Subject: Fix using `@` symbol inside code block (#2418) --- .../base/src/test/kotlin/markdown/ParserTest.kt | 2 + ...seModuleAndPackageDocumentationFragmentsTest.kt | 67 ++++++++++++++++++++-- 2 files changed, 64 insertions(+), 5 deletions(-) (limited to 'plugins/base/src/test/kotlin') diff --git a/plugins/base/src/test/kotlin/markdown/ParserTest.kt b/plugins/base/src/test/kotlin/markdown/ParserTest.kt index a9e1eee4..3498f73f 100644 --- a/plugins/base/src/test/kotlin/markdown/ParserTest.kt +++ b/plugins/base/src/test/kotlin/markdown/ParserTest.kt @@ -951,6 +951,7 @@ class ParserTest : KDocTest() { fun `Multilined Code Block`() { val kdoc = """ | ```kotlin + | @Suppress("UNUSED_VARIABLE") | val x: Int = 0 | val y: String = "Text" | @@ -968,6 +969,7 @@ class ParserTest : KDocTest() { listOf( CodeBlock( listOf( + Text("@Suppress(\"UNUSED_VARIABLE\")"), Br, Text("val x: Int = 0"), Br, Text("val y: String = \"Text\""), Br, Br, Text(" val z: Boolean = true"), Br, diff --git a/plugins/base/src/test/kotlin/parsers/ParseModuleAndPackageDocumentationFragmentsTest.kt b/plugins/base/src/test/kotlin/parsers/ParseModuleAndPackageDocumentationFragmentsTest.kt index 4560c532..b6f9307f 100644 --- a/plugins/base/src/test/kotlin/parsers/ParseModuleAndPackageDocumentationFragmentsTest.kt +++ b/plugins/base/src/test/kotlin/parsers/ParseModuleAndPackageDocumentationFragmentsTest.kt @@ -1,12 +1,11 @@ package parsers -import org.jetbrains.dokka.base.parsers.moduleAndPackage.IllegalModuleAndPackageDocumentation +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.base.parsers.moduleAndPackage.ModuleAndPackageDocumentationFile -import org.jetbrains.dokka.base.parsers.moduleAndPackage.ModuleAndPackageDocumentationFragment -import org.jetbrains.dokka.base.parsers.moduleAndPackage.ModuleAndPackageDocumentationSource -import org.jetbrains.dokka.base.parsers.moduleAndPackage.parseModuleAndPackageDocumentationFragments +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 @@ -216,6 +215,64 @@ class ParseModuleAndPackageDocumentationFragmentsTest { ) } + @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() { -- cgit